summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-05-13 20:25:59 +0800
committersumneko <sumneko@hotmail.com>2019-05-13 20:25:59 +0800
commit2f8a2d9cdc4ea0b9f7de870113a400ddb0fa7c66 (patch)
treef01f1d693665fb277114c87e1d669da0fc89944c /server/src
parent6cfd613662f54fead966e4aa3c1d1aa4616c8eb5 (diff)
downloadlua-language-server-2f8a2d9cdc4ea0b9f7de870113a400ddb0fa7c66.zip
自动完成参数检查是否在函数或表内
Diffstat (limited to 'server/src')
-rw-r--r--server/src/core/completion.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 22ee8167..e3606ef5 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -575,6 +575,34 @@ local function searchEnumAsEmmyParams(vm, source, word, callback, pos, args, fun
end)
end
+local function getSelect(args, pos)
+ if not args then
+ return 1
+ end
+ for i, arg in ipairs(args) do
+ if arg.start <= pos and arg.finish >= pos - 1 then
+ return i
+ end
+ end
+ return #args + 1
+end
+
+local function isInFunctionOrTable(call, pos)
+ local args = call:bindCall()
+ if not args then
+ return false
+ end
+ local select = getSelect(args, pos)
+ local arg = args[select]
+ if not arg then
+ return false
+ end
+ if arg.type == 'function' or arg.type == 'table' then
+ return true
+ end
+ return false
+end
+
local function searchCallArg(vm, source, word, callback, pos)
local results = {}
vm:eachSource(function (src)
@@ -593,6 +621,10 @@ local function searchCallArg(vm, source, word, callback, pos)
return a.start > b.start
end)
local call = results[1]
+ if isInFunctionOrTable(call, pos) then
+ return
+ end
+
local args = call:bindCall()
if not args then
return