diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-16 16:27:49 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-16 16:27:49 +0800 |
commit | 025c4c5fb2ced70e448716391be70fc47e82b1fb (patch) | |
tree | d5acdab607e63e80b9eb046d3b588168e187aa32 | |
parent | 05c0b9a8894bb1c24a24e2ed26e61a3b47d12d89 (diff) | |
download | lua-language-server-025c4c5fb2ced70e448716391be70fc47e82b1fb.zip |
completion: supports enums in `fun()`
-rw-r--r-- | changelog.md | 7 | ||||
-rw-r--r-- | script/core/completion.lua | 6 | ||||
-rw-r--r-- | test/completion/init.lua | 27 |
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, + }, + }, +} |