summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-10 10:52:33 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-10 10:52:33 +0800
commitcc5e87de72ce1ab76c60149da7aa5d65dc807342 (patch)
tree4a4c4cb85c6d57dca5dde95e872f843478b89f20
parent329fffd8d658d2fdbf8484824cdd32fd4b3e186c (diff)
downloadlua-language-server-cc5e87de72ce1ab76c60149da7aa5d65dc807342.zip
修正一些bug
-rw-r--r--script-beta/core/completion.lua14
-rw-r--r--script-beta/parser/guide.lua38
2 files changed, 23 insertions, 29 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index 35e4e21f..1f78b4d4 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -67,18 +67,24 @@ local function findParent(ast, text, offset)
end
local function checkLocal(ast, word, offset, results)
- guide.getVisibleLocalNames(ast.ast, offset, function (name)
+ local locals = guide.getVisibleLocals(ast.ast, offset)
+ for name in pairs(locals) do
if matchKey(word, name) then
results[#results+1] = {
label = name,
kind = ckind.Variable,
}
end
- end)
+ end
+end
+
+local function isSameSource(source, pos)
+ return source.start <= pos and source.finish >= pos
end
local function checkField(ast, text, word, offset, results)
- local parent, oop = findParent(ast, text, offset - #word)
+ local myStart = offset - #word + 1
+ local parent, oop = findParent(ast, text, myStart - 1)
if not parent then
parent = guide.getLocal(ast.ast, '_ENV', offset)
if not parent then
@@ -90,7 +96,7 @@ local function checkField(ast, text, word, offset, results)
local key = info.key
if key
and key:sub(1, 1) == 's'
- and info.source.finish ~= offset then
+ and not isSameSource(info.source, myStart) then
local name = key:sub(3)
if not used[name] and matchKey(word, name) then
results[#results+1] = {
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index b4b45d0b..443c2293 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -236,33 +236,21 @@ function m.getLocal(block, name, pos)
end
--- 获取指定区块中所有的可见局部变量名称
-function m.getVisibleLocalNames(block, pos, callback)
- block = m.getBlock(block)
- local used = {}
- for _ = 1, 1000 do
- if not block then
- return nil
- end
- local locals = block.locals
- local res
- if not locals then
- goto CONTINUE
- end
- for i = 1, #locals do
- local loc = locals[i]
- if loc.effect > pos then
- break
- end
- local name = loc[1]
- if not used[name] then
- used[name] = true
- callback(name)
+function m.getVisibleLocals(block, pos)
+ local result = {}
+ m.eachSourceContain(m.getRoot(block), pos, function (source)
+ local locals = source.locals
+ if locals then
+ for i = 1, #locals do
+ local loc = locals[i]
+ local name = loc[1]
+ if loc.effect <= pos then
+ result[name] = loc
+ end
end
end
- ::CONTINUE::
- block = m.getParentBlock(block)
- end
- error('guide.getLocal overstack')
+ end)
+ return result
end
--- 获取指定区块中可见的标签