Skip to content

Commit

Permalink
FIX Autocompletion for enum values ​​is not available in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jun 5, 2024
1 parent 9498df4 commit c0de8e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions script/core/completion/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1357,18 +1357,21 @@ 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)
end
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
Expand Down
30 changes: 29 additions & 1 deletion test/completion/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3841,6 +3841,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 [[
--
<??>
Expand Down Expand Up @@ -4433,4 +4462,3 @@ new 'A' {
kind = define.CompletionItemKind.Property,
}
}

0 comments on commit c0de8e6

Please sign in to comment.