summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-02-23 21:14:53 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-02-23 21:14:53 +0800
commit6a41f28c76daec6f9bc1f4505ad9e005c5412306 (patch)
tree7728d83d2139cbab9a8ec3db4453a1e2aeac34d2 /script
parente7e7a337a07999a610d903d14aa6e774baa16a8c (diff)
downloadlua-language-server-6a41f28c76daec6f9bc1f4505ad9e005c5412306.zip
improve completion as tableindex
Diffstat (limited to 'script')
-rw-r--r--script/core/completion.lua46
1 files changed, 12 insertions, 34 deletions
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 8bba81b2..ccbe401e 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -101,6 +101,14 @@ local function findSymbol(text, offset)
return nil
end
+local function findNearestSource(ast, offset)
+ local source
+ guide.eachSourceContain(ast.ast, offset, function (src)
+ source = src
+ end)
+ return source
+end
+
local function findTargetSymbol(text, offset, symbol)
offset = skipSpace(text, offset)
for i = offset, 1, -1 do
@@ -1094,35 +1102,13 @@ local function checkEqualEnum(ast, text, offset, results)
eqOrNeq = true
end
start = skipSpace(text, start - 1)
- local source = guide.eachSourceContain(ast.ast, start, function (source)
- if source.finish ~= start then
- return
- end
- if source.type == 'getlocal'
- or source.type == 'setlocal'
- or source.type == 'local'
- or source.type == 'getglobal'
- or source.type == 'setglobal'
- or source.type == 'getfield'
- or source.type == 'setfield'
- or source.type == 'getindex'
- or source.type == 'setindex'
- or source.type == 'tablefield'
- or source.type == 'tableindex'
- or source.type == 'call' then
- return source
- end
- local parent = source.parent
- if parent then
- if parent.type == 'tablefield'
- or parent.type == 'tableindex' then
- return source
- end
- end
- end)
+ local source = findNearestSource(ast, start)
if not source then
return
end
+ if source.type == 'callargs' then
+ source = source.parent
+ end
if source.type == 'call' and not eqOrNeq then
return
end
@@ -1347,14 +1333,6 @@ local function getCallArgInfo(call, text, offset)
return #call.args + 1, nil
end
-local function findNearestSource(ast, offset)
- local source
- guide.eachSourceContain(ast.ast, offset, function (src)
- source = src
- end)
- return source
-end
-
local function getFuncParamByCallIndex(func, index)
if not func.args or #func.args == 0 then
return nil