diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-06-27 21:42:53 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-06-27 21:42:53 +0800 |
commit | 07c2cec7341676e587fe73f7ecbd361c9eb9a5b9 (patch) | |
tree | bc60eabd9893cc8f3c639bc962501aaade36ed21 /server | |
parent | 4db019185cc52a046fbc630078bed743b9819144 (diff) | |
download | lua-language-server-07c2cec7341676e587fe73f7ecbd361c9eb9a5b9.zip |
自动完成支持enum.comment
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', + }, +} |