diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-12-10 14:25:40 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-12-10 14:25:40 +0800 |
commit | ee07ad02720ea8e36f08e1f7981d2b41cb7e9f07 (patch) | |
tree | c8cb775888ec0cc543eb14cb3458aa494d30374e | |
parent | 328db97c169dfa44607acebd09bd63ca22491733 (diff) | |
download | lua-language-server-ee07ad02720ea8e36f08e1f7981d2b41cb7e9f07.zip |
格式化文档
-rw-r--r-- | script-beta/core/completion.lua | 21 | ||||
-rw-r--r-- | script-beta/provider/init.lua | 13 | ||||
-rw-r--r-- | test-beta/completion/init.lua | 26 |
3 files changed, 34 insertions, 26 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 8e7dfdf9..2dae0b90 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -74,11 +74,12 @@ end local function checkLocal(ast, word, offset, results) local locals = guide.getVisibleLocals(ast.ast, offset) - for name in pairs(locals) do + for name, source in pairs(locals) do if matchKey(word, name) then results[#results+1] = { - label = name, - kind = ckind.Variable, + label = name, + kind = ckind.Variable, + detail = getLabel(source), } end end @@ -146,12 +147,14 @@ end local function checkLibrary(ast, text, word, offset, results) for name, lib in pairs(library.global) do if matchKey(word, name) then - buildFunction(results, lib, false, { - label = name, - kind = ckind.Function, - documentation = lib.description, - detail = getLabel(lib), - }) + if lib.type == 'function' then + buildFunction(results, lib, false, { + label = name, + kind = ckind.Function, + documentation = lib.description, + detail = getLabel(lib), + }) + end end end end diff --git a/script-beta/provider/init.lua b/script-beta/provider/init.lua index d6cac333..1965f820 100644 --- a/script-beta/provider/init.lua +++ b/script-beta/provider/init.lua @@ -315,10 +315,15 @@ proto.on('textDocument/completion', function (params) local items = {} for i, res in ipairs(result) do items[i] = { - label = res.label, - kind = res.kind, - sortText = ('%04d'):format(i), - insertText = res.insertText, + label = res.label, + kind = res.kind, + detail = res.detail, + documentation = { + value = res.documentation, + kind = 'markdown', + }, + sortText = ('%04d'):format(i), + insertText = res.insertText, insertTextFormat = res.insertTextFormat, } end diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua index 7ce95b84..bff1abbc 100644 --- a/test-beta/completion/init.lua +++ b/test-beta/completion/init.lua @@ -15,14 +15,22 @@ local function eq(a, b) if tp1 == 'table' then local mark = {} for k in pairs(a) do - if not eq(a[k], b[k]) then - return false + if type(k) == 'number' + or k == 'label' + or k == 'kind' then + if not eq(a[k], b[k]) then + return false + end + mark[k] = true end - mark[k] = true end for k in pairs(b) do - if not mark[k] then - return false + if type(k) == 'number' + or k == 'label' + or k == 'kind' then + if not mark[k] then + return false + end end end return true @@ -126,16 +134,10 @@ ass$ { label = 'assert', kind = CompletionItemKind.Function, - documentation = EXISTS, - detail = EXISTS, }, { label = 'assert()', kind = CompletionItemKind.Snippet, - documentation = EXISTS, - insertText = EXISTS, - insertTextFormat = 2, - detail = EXISTS, }, } @@ -147,7 +149,6 @@ z$ { label = 'zabc', kind = CompletionItemKind.Variable, - detail = '(number) = 1', } } @@ -159,7 +160,6 @@ z$ { label = 'zabc', kind = CompletionItemKind.Variable, - detail = '(number) = 1.0', } } |