diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-06-23 16:12:29 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-06-23 16:12:29 +0800 |
commit | a782eb79202e29326b96fab7cd7591ba881a7778 (patch) | |
tree | 01e2e9d8369b154067b0671b533bf84b5302619f /script/core | |
parent | 3c4203ac592c00fa8f3072faf77e1966149a7860 (diff) | |
download | lua-language-server-a782eb79202e29326b96fab7cd7591ba881a7778.zip |
自动完成显示代码块参考
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/completion.lua | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua index a62a5f1c..d0301d3a 100644 --- a/script/core/completion.lua +++ b/script/core/completion.lua @@ -264,7 +264,7 @@ local function sortPairs(t) end end -local function searchFieldsByInfo(parent, word, source, map) +local function searchFieldsByInfo(parent, word, source, map, srcMap) parent:eachInfo(function (info, src) local k = info[1] if src == source then @@ -291,12 +291,13 @@ local function searchFieldsByInfo(parent, word, source, map) end if matchKey(word, k) then map[k] = v + srcMap[k] = src end end) end -local function searchFieldsByChild(parent, word, source, map) - parent:eachChild(function (k, v) +local function searchFieldsByChild(parent, word, source, map, srcMap) + parent:eachChild(function (k, v, src) if map[k] then return end @@ -314,6 +315,7 @@ local function searchFieldsByChild(parent, word, source, map) end if matchKey(word, k) then map[k] = v + srcMap[k] = src end end) end @@ -325,17 +327,18 @@ local function searchFields(vm, source, word, callback, pos) return end local map = {} + local srcMap = {} local current = parent for _ = 1, 3 do - searchFieldsByInfo(current, word, source, map) + searchFieldsByInfo(current, word, source, map, srcMap) current = current:getMetaMethod('__index') if not current then break end end - searchFieldsByChild(parent, word, source, map) + searchFieldsByChild(parent, word, source, map, srcMap) for k, v in sortPairs(map) do - callback(k, nil, CompletionItemKind.Field, getValueData('field', k, v, pos, source)) + callback(k, srcMap[k], CompletionItemKind.Field, getValueData('field', k, v, pos, source)) end end @@ -421,17 +424,18 @@ end local function searchGlobals(vm, source, word, callback, pos) local global = vm.env:getValue() local map = {} + local srcMap = {} local current = global for _ = 1, 3 do - searchFieldsByInfo(current, word, source, map) + searchFieldsByInfo(current, word, source, map, srcMap) current = current:getMetaMethod('__index') if not current then break end end - searchFieldsByChild(global, word, source, map) + searchFieldsByChild(global, word, source, map, srcMap) for k, v in sortPairs(map) do - callback(k, nil, CompletionItemKind.Field, getValueData('field', k, v, pos, source)) + callback(k, srcMap[k], CompletionItemKind.Field, getValueData('field', k, v, pos, source)) end end @@ -683,7 +687,10 @@ local function searchInRequire(vm, source, callback) end for _, str in ipairs(list) do local data = buildTextEdit(source.start, source.finish, str, source[2]) - data.documentation = map[str] + data.documentation = { + value = map[str], + kind = 'markdown', + } callback(str, nil, CompletionItemKind.Reference, data) end end @@ -708,17 +715,26 @@ local function searchEnumAsLib(vm, source, word, callback, pos, args, lib) if strSource then if source.type == 'string' then local data = buildTextEdit(source.start, source.finish, strSource[1], source[2]) - data.documentation = enum.description + data.documentation = { + kind = 'markdown', + value = enum.description, + } callback(enum.enum, nil, CompletionItemKind.EnumMember, data) else callback(enum.enum, nil, CompletionItemKind.EnumMember, { - documentation = enum.description + documentation = { + value = enum.description, + kind = 'markdown', + } }) end end else callback(enum.enum, nil, CompletionItemKind.EnumMember, { - documentation = enum.description + documentation = { + value = enum.description, + kind = 'markdown', + } }) end end @@ -740,7 +756,10 @@ local function buildEmmyEnumComment(enum, data) if not data then data = {} end - data.documentation = tostring(enum.comment) + data.documentation = { + value = tostring(enum.comment), + kind = 'markdown', + } return data end @@ -956,6 +975,12 @@ local function makeList(source, pos, word) if not data.kind then data.kind = kind end + if src then + data.data = { + uri = src.uri, + offset = src.start, + } + end list[#list+1] = data if data.snip then local snipType = config.config.completion.callSnippet |