summaryrefslogtreecommitdiff
path: root/script/vm/global.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-01-09 14:59:12 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-01-09 14:59:12 +0800
commit805231111f765978985a4888d9c43e973dce87ee (patch)
tree713d6bea737e52a4a5ee389c21842e5e446cbfc1 /script/vm/global.lua
parent5415cf71cced94bf73f292d11f671fbc1ec5296f (diff)
downloadlua-language-server-805231111f765978985a4888d9c43e973dce87ee.zip
cleanup
Diffstat (limited to 'script/vm/global.lua')
-rw-r--r--script/vm/global.lua45
1 files changed, 31 insertions, 14 deletions
diff --git a/script/vm/global.lua b/script/vm/global.lua
index c36a3f58..cc206b52 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -514,28 +514,19 @@ function vm.compileByGlobal(source)
if not global then
return
end
- ---@cast source parser.object
- local root = guide.getRoot(source)
- local uri = guide.getUri(source)
- if not root._globalBaseMap then
- root._globalBaseMap = {}
- end
- local name = global:asKeyName()
- if not root._globalBaseMap[name] then
- root._globalBaseMap[name] = {
- type = 'globalbase',
- parent = root,
- }
+ local globalBase = vm.getGlobalBase(source)
+ if not globalBase then
+ return
end
- source._globalBase = root._globalBaseMap[name]
local globalNode = vm.getNode(source._globalBase)
if globalNode then
vm.setNode(source, globalNode, true)
return
end
+ local uri = guide.getUri(source)
---@type vm.node
globalNode = vm.createNode(global)
- vm.setNode(source._globalBase, globalNode, true)
+ vm.setNode(globalBase, globalNode, true)
vm.setNode(source, globalNode, true)
-- TODO:don't mix
@@ -599,6 +590,32 @@ function vm.compileByGlobal(source)
end
---@param source parser.object
+---@return parser.object?
+function vm.getGlobalBase(source)
+ if source._globalBase then
+ return source._globalBase
+ end
+ local global = vm.getGlobalNode(source)
+ if not global then
+ return nil
+ end
+ ---@cast source parser.object
+ local root = guide.getRoot(source)
+ if not root._globalBaseMap then
+ root._globalBaseMap = {}
+ end
+ local name = global:asKeyName()
+ if not root._globalBaseMap[name] then
+ root._globalBaseMap[name] = {
+ type = 'globalbase',
+ parent = root,
+ }
+ end
+ source._globalBase = root._globalBaseMap[name]
+ return source._globalBase
+end
+
+---@param source parser.object
local function compileSelf(source)
if source.parent.type ~= 'funcargs' then
return