diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2024-06-05 18:37:24 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2024-06-05 18:37:24 +0800 |
commit | c0de8e657bf8685691078b6a367a03a46997bf9c (patch) | |
tree | 734badf1ca90f22e116e108291752bda74526761 | |
parent | 9498df4eee86545ac29df2ff3d701e57448585ad (diff) | |
download | lua-language-server-c0de8e657bf8685691078b6a367a03a46997bf9c.zip |
`FIX` Autocompletion for enum values is not available in some cases
-rw-r--r-- | changelog.md | 4 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 13 | ||||
-rw-r--r-- | test/completion/common.lua | 30 |
3 files changed, 39 insertions, 8 deletions
diff --git a/changelog.md b/changelog.md index e66b74b0..fd82281e 100644 --- a/changelog.md +++ b/changelog.md @@ -2,9 +2,9 @@ ## Unreleased <!-- Add all new changes here. They will be moved under a version at release --> -* `FIX` Don't do diagnostics when the workspace is not ready * `NEW` Reference workspace symbols in comments using `[some text](lua://symbolName)` syntax - +* `FIX` Don't do diagnostics when the workspace is not ready +* `FIX` Autocompletion for enum values is not available in some cases ## 3.9.1 `2024-5-14` * revert extension runtime diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index 5c55c16b..242bf449 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1357,6 +1357,13 @@ local function insertEnum(state, pos, src, enums, isInArray, mark) kind = define.CompletionItemKind.Function, insertText = insertText, } + elseif src.type == 'doc.enum' then + ---@cast src parser.object + if vm.docHasAttr(src, 'key') then + insertDocEnumKey(state, pos, src, enums) + else + insertDocEnum(state, pos, src, enums) + end elseif isInArray and src.type == 'doc.type.array' then for i, d in ipairs(vm.getDefs(src.node)) do insertEnum(state, pos, d, enums, isInArray, mark) @@ -1364,11 +1371,7 @@ local function insertEnum(state, pos, src, enums, isInArray, mark) elseif src.type == 'global' and src.cate == 'type' then for _, set in ipairs(src:getSets(state.uri)) do if set.type == 'doc.enum' then - if vm.docHasAttr(set, 'key') then - insertDocEnumKey(state, pos, set, enums) - else - insertDocEnum(state, pos, set, enums) - end + insertEnum(state, pos, set, enums, isInArray, mark) end end end diff --git a/test/completion/common.lua b/test/completion/common.lua index 3ea02ed7..b5ffe173 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -3842,6 +3842,35 @@ f(<??>) } TEST [[ +---@class optional +---@field enum enum + +---@enum(key) enum +local t = { + a = 1, + b = 2, +} + +---@param a optional +local function f(a) +end + +f { + enum = <??> +} +]] +{ + { + label = '"a"', + kind = define.CompletionItemKind.EnumMember, + }, + { + label = '"b"', + kind = define.CompletionItemKind.EnumMember, + }, +} + +TEST [[ -- <??> ]] @@ -4433,4 +4462,3 @@ new 'A' { kind = define.CompletionItemKind.Property, } } - |