summaryrefslogtreecommitdiff
path: root/server-beta/src/searcher/eachGlobal.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-04 15:15:21 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-04 15:15:21 +0800
commit37818cece496dad3fa683065e3e0c32e6ede186b (patch)
tree874f2eb0ccd931d74d7c66d30276b1cbb54bf61b /server-beta/src/searcher/eachGlobal.lua
parente9e66c789b6d2b4fb57d639f1143ea84fe40019b (diff)
downloadlua-language-server-37818cece496dad3fa683065e3e0c32e6ede186b.zip
支持全局变量
Diffstat (limited to 'server-beta/src/searcher/eachGlobal.lua')
-rw-r--r--server-beta/src/searcher/eachGlobal.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/server-beta/src/searcher/eachGlobal.lua b/server-beta/src/searcher/eachGlobal.lua
new file mode 100644
index 00000000..21ee2c51
--- /dev/null
+++ b/server-beta/src/searcher/eachGlobal.lua
@@ -0,0 +1,34 @@
+local guide = require 'parser.guide'
+local searcher = require 'searcher.searcher'
+
+local function eachGlobal(source, callback)
+ local root = guide.getRoot(source)
+ local env = root.locals[1]
+ searcher.eachField(env, callback)
+end
+
+function searcher.eachGlobal(source, callback)
+ local lock <close> = searcher.lock('eachGlobal', source)
+ if not lock then
+ return
+ end
+ local cache = searcher.cache.eachGlobal[source]
+ if cache then
+ for i = 1, #cache do
+ callback(cache[i])
+ end
+ return
+ end
+ cache = {}
+ searcher.cache.eachGlobal[source] = cache
+ local mark = {}
+ eachGlobal(source, function (info)
+ local src = info.source
+ if mark[src] then
+ return
+ end
+ mark[src] = true
+ cache[#cache+1] = info
+ callback(info)
+ end)
+end