Skip to content

Commit c0de8e6

Browse files
committed
FIX Autocompletion for enum values ​​is not available in some cases
1 parent 9498df4 commit c0de8e6

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

changelog.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
5-
* `FIX` Don't do diagnostics when the workspace is not ready
65
* `NEW` Reference workspace symbols in comments using `[some text](lua://symbolName)` syntax
7-
6+
* `FIX` Don't do diagnostics when the workspace is not ready
7+
* `FIX` Autocompletion for enum values ​​is not available in some cases
88
## 3.9.1
99
`2024-5-14`
1010
* revert extension runtime

script/core/completion/completion.lua

+8-5
Original file line numberDiff line numberDiff line change
@@ -1357,18 +1357,21 @@ local function insertEnum(state, pos, src, enums, isInArray, mark)
13571357
kind = define.CompletionItemKind.Function,
13581358
insertText = insertText,
13591359
}
1360+
elseif src.type == 'doc.enum' then
1361+
---@cast src parser.object
1362+
if vm.docHasAttr(src, 'key') then
1363+
insertDocEnumKey(state, pos, src, enums)
1364+
else
1365+
insertDocEnum(state, pos, src, enums)
1366+
end
13601367
elseif isInArray and src.type == 'doc.type.array' then
13611368
for i, d in ipairs(vm.getDefs(src.node)) do
13621369
insertEnum(state, pos, d, enums, isInArray, mark)
13631370
end
13641371
elseif src.type == 'global' and src.cate == 'type' then
13651372
for _, set in ipairs(src:getSets(state.uri)) do
13661373
if set.type == 'doc.enum' then
1367-
if vm.docHasAttr(set, 'key') then
1368-
insertDocEnumKey(state, pos, set, enums)
1369-
else
1370-
insertDocEnum(state, pos, set, enums)
1371-
end
1374+
insertEnum(state, pos, set, enums, isInArray, mark)
13721375
end
13731376
end
13741377
end

test/completion/common.lua

+29-1
Original file line numberDiff line numberDiff line change
@@ -3841,6 +3841,35 @@ f(<??>)
38413841
},
38423842
}
38433843

3844+
TEST [[
3845+
---@class optional
3846+
---@field enum enum
3847+
3848+
---@enum(key) enum
3849+
local t = {
3850+
a = 1,
3851+
b = 2,
3852+
}
3853+
3854+
---@param a optional
3855+
local function f(a)
3856+
end
3857+
3858+
f {
3859+
enum = <??>
3860+
}
3861+
]]
3862+
{
3863+
{
3864+
label = '"a"',
3865+
kind = define.CompletionItemKind.EnumMember,
3866+
},
3867+
{
3868+
label = '"b"',
3869+
kind = define.CompletionItemKind.EnumMember,
3870+
},
3871+
}
3872+
38443873
TEST [[
38453874
--
38463875
<??>
@@ -4433,4 +4462,3 @@ new 'A' {
44334462
kind = define.CompletionItemKind.Property,
44344463
}
44354464
}
4436-

0 commit comments

Comments
 (0)