diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-02-24 21:21:39 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-02-24 21:21:39 +0800 |
commit | 88253d2cc1f9d1c5042c5a93692abbdda0667333 (patch) | |
tree | 0d3b08fcb63f17b6e0535463efcab88f3545a155 /script/vm/global-manager.lua | |
parent | 00c5506c24629382618d1fbc75e87e9aea04e376 (diff) | |
download | lua-language-server-88253d2cc1f9d1c5042c5a93692abbdda0667333.zip |
update
Diffstat (limited to 'script/vm/global-manager.lua')
-rw-r--r-- | script/vm/global-manager.lua | 72 |
1 files changed, 50 insertions, 22 deletions
diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua index b9f22b43..8176a2af 100644 --- a/script/vm/global-manager.lua +++ b/script/vm/global-manager.lua @@ -16,25 +16,34 @@ m.ID_SPLITE = '\x1F' local compilerGlobalMap = util.switch() : case 'local' - : call(function (uri, source) - if source.tag ~= '_ENV' then + : call(function (source) + if source.special ~= '_G' then return end if source.ref then for _, ref in ipairs(source.ref) do - m.compileObject(uri, ref) + m.compileObject(ref) end end end) + : case 'getlocal' + : call(function (source) + if source.special ~= '_G' then + return + end + m.compileObject(source.next) + end) : case 'setglobal' - : call(function (uri, source) + : call(function (source) + local uri = guide.getUri(source) local name = guide.getKeyName(source) local global = m.declareGlobal(name, uri) global:addSet(uri, source) source._globalNode = global end) : case 'getglobal' - : call(function (uri, source) + : call(function (source) + local uri = guide.getUri(source) local name = guide.getKeyName(source) local global = m.declareGlobal(name, uri) global:addGet(uri, source) @@ -42,20 +51,34 @@ local compilerGlobalMap = util.switch() local nxt = source.next if nxt then - m.compileObject(uri, nxt) + m.compileObject(nxt) + end + + if source.special == 'rawset' + or source.special == 'rawget' then + m.compileObject(source.parent) end end) : case 'setfield' : case 'setmethod' : case 'setindex' - ---@param uri uri ---@param source parser.object - : call(function (uri, source) - local parent = source.node._globalNode - if not parent then + : call(function (source) + local name + if source.node._globalNode then + local parentName = source.node._globalNode:getName() + if parentName == '_G' then + name = guide.getKeyName(source) + else + name = parentName .. m.ID_SPLITE .. guide.getKeyName(source) + end + elseif source.node.special == '_G' then + name = guide.getKeyName(source) + end + if not name then return end - local name = parent:getName() .. m.ID_SPLITE .. guide.getKeyName(source) + local uri = guide.getUri(source) local global = m.declareGlobal(name, uri) global:addSet(uri, source) source._globalNode = global @@ -63,21 +86,27 @@ local compilerGlobalMap = util.switch() : case 'getfield' : case 'getmethod' : case 'getindex' - ---@param uri uri ---@param source parser.object - : call(function (uri, source) - local parent = source.node._globalNode - if not parent then - return + : call(function (source) + local name + if source.node._globalNode then + local parentName = source.node._globalNode:getName() + if parentName == '_G' then + name = guide.getKeyName(source) + else + name = parentName .. m.ID_SPLITE .. guide.getKeyName(source) + end + elseif source.node.special == '_G' then + name = guide.getKeyName(source) end - local name = parent:getName() .. m.ID_SPLITE .. guide.getKeyName(source) + local uri = guide.getUri(source) local global = m.declareGlobal(name, uri) global:addGet(uri, source) source._globalNode = global local nxt = source.next if nxt then - m.compileObject(uri, nxt) + m.compileObject(nxt) end end) : getMap() @@ -105,22 +134,21 @@ function m.getGlobal(name, field) end ---@param source parser.object -function m.compileObject(uri, source) +function m.compileObject(source) if source._globalNode ~= nil then return end source._globalNode = false local compiler = compilerGlobalMap[source.type] if compiler then - compiler(uri, source) + compiler(source) end end ---@param source parser.object function m.compileAst(source) - local uri = guide.getUri(source) local env = guide.getENV(source) - m.compileObject(uri, env) + m.compileObject(env) end ---@return vm.node.global |