diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-16 10:33:38 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-16 10:33:38 +0800 |
commit | 6576326add050eb308249c69f9f5ee42d788d72f (patch) | |
tree | 173bdfbb65cb0dd69e25d88442146fb8e8bbcb97 /script-beta/parser | |
parent | 87085809fa155c87b48d42d9304b75d97dd6c22d (diff) | |
download | lua-language-server-6576326add050eb308249c69f9f5ee42d788d72f.zip |
highlight 区分是否是全局变量
Diffstat (limited to 'script-beta/parser')
-rw-r--r-- | script-beta/parser/guide.lua | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 601657c1..f4c226b8 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -243,13 +243,12 @@ end --- 寻找根区块 function m.getRoot(obj) for _ = 1, 1000 do + if obj.type == 'main' then + return obj + end local parent = obj.parent if not parent then - if obj.type == 'main' then - return obj - else - return nil - end + return nil end obj = parent end @@ -1812,8 +1811,9 @@ local function searchEnvRef(ref, results) end function m.findGlobals(ast) + local root = m.getRoot(ast) local results = {} - local env = m.getENV(ast) + local env = m.getENV(root) if env.ref then for _, ref in ipairs(env.ref) do searchEnvRef(ref, results) @@ -1822,6 +1822,18 @@ function m.findGlobals(ast) return results end +function m.findGlobalsOfName(ast, name) + local root = m.getRoot(ast) + local results = {} + local globals = m.findGlobals(root) + for _, global in ipairs(globals) do + if m.getKeyName(global) == name then + results[#results+1] = global + end + end + return results +end + function m.checkSameSimpleInGlobal(status, name, source, start, queue) if not name then return @@ -1830,7 +1842,7 @@ function m.checkSameSimpleInGlobal(status, name, source, start, queue) if status.interface.global then objs = status.interface.global(name) else - objs = m.findGlobals(m.getRoot(source)) + objs = m.findGlobalsOfName(source, name) end if objs then for _, obj in ipairs(objs) do |