summaryrefslogtreecommitdiff
path: root/server/src/core/completion.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-08-27 20:28:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-08-27 20:28:01 +0800
commita828a593e119ec222e4ef9e6a737234cabe00245 (patch)
tree8c39fb4a4738bdaa1d6d81173e42ba50903cb368 /server/src/core/completion.lua
parentf188a3001de879387fafbb3e875ceafa48e74ab9 (diff)
downloadlua-language-server-a828a593e119ec222e4ef9e6a737234cabe00245.zip
函数调用的代码片段
Diffstat (limited to 'server/src/core/completion.lua')
-rw-r--r--server/src/core/completion.lua44
1 files changed, 44 insertions, 0 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 5a403a55..a3994833 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -869,6 +869,49 @@ 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 = {}
@@ -894,6 +937,7 @@ local function makeList(source, pos, word)
if not data.kind then
data.kind = kind
end
+ makeFunctionSnippet(src, data)
list[#list+1] = data
end, list
end