diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-09-29 15:38:28 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-09-29 15:38:28 +0800 |
commit | bfaac3b788628dfbd0faa27cafc8973bccab4d10 (patch) | |
tree | 5e5c9ed83f8b88b2d1891af7d14cf7973e7f74dd /script-beta/vm/getGlobals.lua | |
parent | f737afdef778e4b34d7f9db154068ff5f04de119 (diff) | |
download | lua-language-server-bfaac3b788628dfbd0faa27cafc8973bccab4d10.zip |
更好的全局变量支持
Diffstat (limited to 'script-beta/vm/getGlobals.lua')
-rw-r--r-- | script-beta/vm/getGlobals.lua | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/script-beta/vm/getGlobals.lua b/script-beta/vm/getGlobals.lua index f5b22ff9..32617eb1 100644 --- a/script-beta/vm/getGlobals.lua +++ b/script-beta/vm/getGlobals.lua @@ -4,8 +4,34 @@ local files = require 'files' local library = require 'library' local util = require 'utility' +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) @@ -32,7 +58,12 @@ local function getGlobalsOfFile(uri) searchEnvRef(ref, results) end end + local mark = {} for _, res in ipairs(results) do + if mark[res] then + goto CONTINUE + end + mark[res] = true local name = guide.getSimpleName(res) if name then if not globals[name] then @@ -40,6 +71,7 @@ local function getGlobalsOfFile(uri) end globals[name][#globals[name]+1] = res end + ::CONTINUE:: end return globals end |