summaryrefslogtreecommitdiff
path: root/script/vm/global-manager.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-11 19:03:11 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-11 19:03:11 +0800
commit3b642df7cb6730f35342803089f2d6d495ddd554 (patch)
treebc767efc6c1c12fcb17024217d3adfd844af9922 /script/vm/global-manager.lua
parent2e4f530b33467b94376321c7f9879f2a879429bb (diff)
downloadlua-language-server-3b642df7cb6730f35342803089f2d6d495ddd554.zip
fix #1037
Diffstat (limited to 'script/vm/global-manager.lua')
-rw-r--r--script/vm/global-manager.lua27
1 files changed, 17 insertions, 10 deletions
diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua
index bb4498ff..bd5b8696 100644
--- a/script/vm/global-manager.lua
+++ b/script/vm/global-manager.lua
@@ -74,7 +74,7 @@ local compilerGlobalSwitch = util.switch()
if parentName == '_G' then
name = keyName
else
- name = parentName .. m.ID_SPLITE .. keyName
+ name = ('%s%s%s'):format(parentName, m.ID_SPLITE, keyName)
end
elseif source.node.special == '_G' then
name = keyName
@@ -82,7 +82,7 @@ local compilerGlobalSwitch = util.switch()
if not name then
return
end
- local uri = guide.getUri(source)
+ local uri = guide.getUri(source)
local global = m.declareGlobal('variable', name, uri)
global:addSet(uri, source)
source._globalNode = global
@@ -92,17 +92,22 @@ local compilerGlobalSwitch = util.switch()
: case 'getindex'
---@param source parser.object
: call(function (source)
- local name = guide.getKeyName(source)
- if not name then
+ local name
+ local keyName = guide.getKeyName(source)
+ if not keyName then
return
end
if source.node._globalNode then
local parentName = source.node._globalNode:getName()
- if parentName ~= '_G' then
- name = parentName .. m.ID_SPLITE .. name
+ if parentName == '_G' then
+ name = keyName
+ else
+ name = ('%s%s%s'):format(parentName, m.ID_SPLITE, keyName)
end
+ elseif source.node.special == '_G' then
+ name = keyName
end
- local uri = guide.getUri(source)
+ local uri = guide.getUri(source)
local global = m.declareGlobal('variable', name, uri)
global:addGet(uri, source)
source._globalNode = global
@@ -337,9 +342,11 @@ function m.dropUri(uri)
m.globalSubs[uri] = nil
for key in pairs(globalSub) do
local global = m.globals[key]
- global:dropUri(uri)
- if not global:isAlive() then
- m.globals[key] = nil
+ if global then
+ global:dropUri(uri)
+ if not global:isAlive() then
+ m.globals[key] = nil
+ end
end
end
end