diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 19 | ||||
-rw-r--r-- | server/test/completion/init.lua | 21 |
2 files changed, 36 insertions, 4 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 37527ac2..ddbe7271 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -663,6 +663,17 @@ local function searchEnumAsLib(vm, source, word, callback, pos, args, lib) end end +local function buildEmmyEnumComment(option, data) + if not option or not option.comment then + return data + end + if not data then + data = {} + end + data.documentation = tostring(option.comment) + return data +end + local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, func) local select = #args + 1 for i, arg in ipairs(args) do @@ -677,18 +688,18 @@ local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, fun return end - param:eachEnum(function (str) + param:eachEnum(function (str, option) if matchKey(word, str) then local strSource = parser:ast(tostring(str), 'String') if strSource then if source.type == 'string' then local data = buildTextEdit(source.start, source.finish, strSource[1], source[2]) - callback(str, nil, CompletionItemKind.EnumMember, data) + callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(option, data)) else - callback(str, nil, CompletionItemKind.EnumMember) + callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(option)) end else - callback(str, nil, CompletionItemKind.EnumMember) + callback(str, nil, CompletionItemKind.EnumMember, buildEmmyEnumComment(option)) end end end) diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index 5f43b8d2..98d6611d 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -1338,3 +1338,24 @@ zz$ } } } + +TEST [[ +---@param x string +---| "'选项1'" {comment = '注释1'} +---| "'选项2'" {comment = '注释2'} +function f(x) end + +f($) +]] +{ + { + label = "'选项1'", + kind = CompletionItemKind.EnumMember, + documentation = '注释1', + }, + { + label = "'选项2'", + kind = CompletionItemKind.EnumMember, + documentation = '注释2', + }, +} |