summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/core/completion.lua24
-rw-r--r--server/test/completion/init.lua31
2 files changed, 49 insertions, 6 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 9afeec2a..331eb6cc 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -616,11 +616,15 @@ local function searchEnumAsLib(vm, source, word, callback, pos, args, lib)
data.documentation = enum.description
callback(enum.enum, nil, CompletionItemKind.EnumMember, data)
else
- local data = buildTextEdit(source.start, source.finish, strSource[1], nil)
- data.documentation = enum.description
- callback(enum.enum, nil, CompletionItemKind.EnumMember, data)
+ callback(enum.enum, nil, CompletionItemKind.EnumMember, {
+ documentation = enum.description
+ })
end
end
+ else
+ callback(enum.enum, nil, CompletionItemKind.EnumMember, {
+ documentation = enum.description
+ })
end
end
end
@@ -648,9 +652,17 @@ local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, fun
param:eachEnum(function (enum)
if matchKey(word, enum) then
- callback(enum, nil, CompletionItemKind.EnumMember, {
- label = enum,
- })
+ local strSource = parser:ast(tostring(enum), 'String')
+ if strSource then
+ if source.type == 'string' then
+ local data = buildTextEdit(source.start, source.finish, strSource[1], source[2])
+ callback(enum, nil, CompletionItemKind.EnumMember, data)
+ else
+ callback(enum, nil, CompletionItemKind.EnumMember)
+ end
+ else
+ callback(enum, nil, CompletionItemKind.EnumMember)
+ end
end
end)
end
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index fee69e74..b649e1a8 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -1159,6 +1159,37 @@ f($)
}
TEST [[
+---@param x string | "'AAA'" | "'BBB'" | "'CCC'"
+function f(x)
+end
+
+f('$')
+]]
+{
+ {
+ label = "AAA",
+ filterText = 'AAA',
+ kind = CompletionItemKind.EnumMember,
+ textEdit = EXISTS,
+ additionalTextEdits = EXISTS,
+ },
+ {
+ label = "BBB",
+ filterText = 'BBB',
+ kind = CompletionItemKind.EnumMember,
+ textEdit = EXISTS,
+ additionalTextEdits = EXISTS,
+ },
+ {
+ label = "CCC",
+ filterText = 'CCC',
+ kind = CompletionItemKind.EnumMember,
+ textEdit = EXISTS,
+ additionalTextEdits = EXISTS,
+ }
+}
+
+TEST [[
---@param x function | 'function () end'
function f(x)
end