summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md7
-rw-r--r--script/core/completion.lua6
-rw-r--r--test/completion/init.lua27
3 files changed, 40 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md
index 99232ab4..1178de72 100644
--- a/changelog.md
+++ b/changelog.md
@@ -18,6 +18,13 @@
[3]: string = "c",
}
```
+* `NEW` completion: supports enums in `fun()`
+ ```lua
+ ---@type fun(x: "'aaa'"|"'bbb'")
+ local f
+
+ f(--[[show `'aaa'` and `'bbb'` here]])
+ ```
* `FIX` loading workspace may hang
* `FIX` `debug.getuservalue` and `debug.setuservalue` should not exist in `Lua 5.1`
* `FIX` infer of `---@type class[][]`
diff --git a/script/core/completion.lua b/script/core/completion.lua
index f7f1e2c7..7e95d663 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -1327,6 +1327,12 @@ local function getCallEnumsAndFuncs(source, index)
end
end
end
+ if source.type == 'doc.type.function' then
+ local arg = source.args[index]
+ if arg then
+ return pushCallEnumsAndFuncs(vm.getDefs(arg.extends))
+ end
+ end
end
local function findCall(ast, text, offset)
diff --git a/test/completion/init.lua b/test/completion/init.lua
index ea1cdfdb..1ed82b2a 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -2696,3 +2696,30 @@ local r = f('$')
},
},
}
+
+TEST [[
+---@type fun(x: "'aaa'"|"'bbb'")
+local f
+
+f('$')
+]]
+{
+ {
+ label = "'aaa'",
+ kind = define.CompletionItemKind.EnumMember,
+ textEdit = {
+ newText = "'aaa'",
+ start = 45,
+ finish = 46,
+ },
+ },
+ {
+ label = "'bbb'",
+ kind = define.CompletionItemKind.EnumMember,
+ textEdit = {
+ newText = "'bbb'",
+ start = 45,
+ finish = 46,
+ },
+ },
+}