summaryrefslogtreecommitdiff
path: root/script-beta/vm/getGlobals.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-06 17:23:27 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-06 17:23:27 +0800
commit33559d7c87c5daf6dbb31b8d005f33ed6b27ace2 (patch)
treef245b14cf878db16795a742f8ed82293a76c57f4 /script-beta/vm/getGlobals.lua
parent35962bc062fb778dd4038c9d8d50ea7d601453e1 (diff)
downloadlua-language-server-33559d7c87c5daf6dbb31b8d005f33ed6b27ace2.zip
整理代码
Diffstat (limited to 'script-beta/vm/getGlobals.lua')
-rw-r--r--script-beta/vm/getGlobals.lua49
1 files changed, 1 insertions, 48 deletions
diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua
index 380a21ac..4c0abe3d 100644
--- a/script-beta/vm/getGlobals.lua
+++ b/script-beta/vm/getGlobals.lua
@@ -5,60 +5,13 @@ local library = require 'library'
local util = require 'utility'
local config = require 'config'
-local function searchRawset(ref, results)
- if guide.getKeyName(ref) ~= 's|rawset' then
- return
- end
- local call = ref.parent
- if call.type ~= 'call' or call.node ~= ref then
- return
- end
- if not call.args then
- return
- end
- local arg1 = call.args[1]
- if arg1.special ~= '_G' then
- -- 不会吧不会吧,不会真的有人写成 `rawset(_G._G._G, 'xxx', value)` 吧
- return
- end
- results[#results+1] = call
-end
-
-local function searchG(ref, results)
- while ref and guide.getKeyName(ref) == 's|_G' do
- results[#results+1] = ref
- ref = ref.next
- end
- if ref then
- results[#results+1] = ref
- searchRawset(ref, results)
- end
-end
-
-local function searchEnvRef(ref, results)
- if ref.type == 'setglobal'
- or ref.type == 'getglobal' then
- results[#results+1] = ref
- searchG(ref, results)
- elseif ref.type == 'getlocal' then
- results[#results+1] = ref.next
- searchG(ref.next, results)
- end
-end
-
local function getGlobalsOfFile(uri)
local globals = {}
local ast = files.getAst(uri)
if not ast then
return globals
end
- local results = {}
- local env = guide.getENV(ast.ast)
- if env.ref then
- for _, ref in ipairs(env.ref) do
- searchEnvRef(ref, results)
- end
- end
+ local results = guide.findGlobals(ast.ast)
local mark = {}
for _, res in ipairs(results) do
if mark[res] then