diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-08-27 20:54:07 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-08-27 20:54:07 +0800 |
commit | 972e6458ed5c256cb3d1de05b585bc3fc55f82ad (patch) | |
tree | 6f8a8eb5adfff5f0410f60348a8ee3940a7ec5c3 /server/src | |
parent | a828a593e119ec222e4ef9e6a737234cabe00245 (diff) | |
download | lua-language-server-972e6458ed5c256cb3d1de05b585bc3fc55f82ad.zip |
分离函数调用与函数对象
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/completion.lua | 87 | ||||
-rw-r--r-- | server/src/method/textDocument/completion.lua | 1 |
2 files changed, 44 insertions, 44 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index a3994833..b9191568 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -153,11 +153,45 @@ local function getKind(cata, value) return nil end +local function buildSnipArgs(args) + local t = {} + for i, name in ipairs(args) do + t[i] = ('${%d:%s}'):format(i, name) + end + return table.concat(t, ', ') +end + +local function getFunctionSnip(name, value) + if value:getType() ~= 'function' then + return + end + local lib = value:getLib() + local hover + if lib then + hover = getFunctionHoverAsLib(name, lib) + else + local emmy = value:getEmmy() + if emmy and emmy.type == 'emmy.functionType' then + hover = getFunctionHoverAsEmmy(name, emmy) + else + hover = getFunctionHover(name, value:getFunction()) + end + end + if not hover then + return ('%s()'):format(name) + end + if not hover.args then + return ('%s()'):format(name) + end + return ('%s(%s)'):format(name, buildSnipArgs(hover.args)) +end + local function getValueData(cata, name, value, pos, source) local data = { documentation = getDucumentation(name, value), detail = getDetail(value), kind = getKind(cata, value), + snip = getFunctionSnip(name, value), } if cata == 'field' then if not parser:grammar(name, 'Name') then @@ -869,49 +903,6 @@ local function searchSpecial(vm, source, word, callback, pos, text) searchSpecialHashSign(vm, pos, text, callback) end -local function buildSnipArgs(args) - local t = {} - for i, name in ipairs(args) do - t[i] = ('${%d:%s}'):format(i, name) - end - return table.concat(t, ', ') -end - -local function makeFunctionSnippet(src, data) - if not src then - return - end - local value = src:findValue() - if not value then - return - end - local func = value:getFunction() - if not func then - return - end - local name = data.label - local lib = value:getLib() - local hover - if lib then - hover = getFunctionHoverAsLib(name, lib) - else - local emmy = value:getEmmy() - if emmy and emmy.type == 'emmy.functionType' then - hover = getFunctionHoverAsEmmy(name, emmy) - else - hover = getFunctionHover(name, value:getFunction()) - end - end - if not hover then - return - end - if not hover.args then - return - end - data.insertTextFormat = 2 - data.insertText = ('%s(%s)'):format(data.label, buildSnipArgs(hover.args)) -end - local function makeList(source, pos, word) local list = {} local mark = {} @@ -937,8 +928,16 @@ local function makeList(source, pos, word) if not data.kind then data.kind = kind end - makeFunctionSnippet(src, data) list[#list+1] = data + if data.snip then + local snipData = table.deepCopy(data) + snipData.insertText = data.snip + snipData.kind = CompletionItemKind.Snippet + snipData.label = snipData.label .. '()' + snipData.snip = nil + data.snip = nil + list[#list+1] = snipData + end end, list end diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua index 1b9aa73f..eb33b3ce 100644 --- a/server/src/method/textDocument/completion.lua +++ b/server/src/method/textDocument/completion.lua @@ -80,6 +80,7 @@ return function (lsp, params) for i, item in ipairs(items) do item.sortText = ('%04d'):format(i) + item.insertTextFormat = 2 if item.textEdit then item.textEdit.range = posToRange(lines, item.textEdit.start, item.textEdit.finish) item.textEdit.start = nil |