summaryrefslogtreecommitdiff
path: root/script-beta/parser/guide.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-09 20:28:18 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-09 20:28:18 +0800
commitd803249a1aedafad9b08349ed16c941bf4c3ba4e (patch)
treee25c274c1c1f16eddefa3ca572202f7536c6b7d8 /script-beta/parser/guide.lua
parent9e193c1d17d64137191c5aa9e4f39c18a795396f (diff)
downloadlua-language-server-d803249a1aedafad9b08349ed16c941bf4c3ba4e.zip
自动完成搜索局部变量
Diffstat (limited to 'script-beta/parser/guide.lua')
-rw-r--r--script-beta/parser/guide.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 2e26a3da..4ccfd23d 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -235,6 +235,39 @@ function m.getLocal(block, name, pos)
error('guide.getLocal overstack')
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)
+ end
+ end
+ if res then
+ return res, res
+ end
+ ::CONTINUE::
+ block = m.getParentBlock(block)
+ end
+ error('guide.getLocal overstack')
+end
+
--- 获取指定区块中可见的标签
---@param block table
---@param name string {comment = '标签名'}