summaryrefslogtreecommitdiff
path: root/script/vm/global.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-01-11 22:03:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-01-11 22:03:43 +0800
commit390474caca77ea5e745f3a3ae2ca7168e7165573 (patch)
tree97bdcf92bf6ec60d802f795f47e59bb8e33f3c61 /script/vm/global.lua
parentd74c85c8517b9f3b7591cc337fa387f2805ebb40 (diff)
downloadlua-language-server-390474caca77ea5e745f3a3ae2ca7168e7165573.zip
stash
Diffstat (limited to 'script/vm/global.lua')
-rw-r--r--script/vm/global.lua38
1 files changed, 33 insertions, 5 deletions
diff --git a/script/vm/global.lua b/script/vm/global.lua
index 066dfab9..5ffcdb34 100644
--- a/script/vm/global.lua
+++ b/script/vm/global.lua
@@ -4,6 +4,11 @@ local guide = require 'parser.guide'
---@class vm
local vm = require 'vm.vm'
+---@type table<string, vm.global>
+local allGlobals = {}
+---@type table<uri, table<string, boolean>>
+local globalSubs = util.multiTable(2)
+
---@class parser.object
---@field package _globalBase parser.object
---@field package _globalBaseMap table<string, parser.object>
@@ -114,11 +119,39 @@ function mt:getKeyName()
return self.name:match('[^' .. vm.ID_SPLITE .. ']+$')
end
+---@return string?
+function mt:getFieldName()
+ return self.name:match(vm.ID_SPLITE .. '(.-)$')
+end
+
---@return boolean
function mt:isAlive()
return next(self.links) ~= nil
end
+---@param uri uri
+---@return parser.object?
+function mt:getParentBase(uri)
+ local parentID = self.name:match('^(.-)' .. vm.ID_SPLITE)
+ if not parentID then
+ return nil
+ end
+ local parentName = self.cate .. '|' .. parentID
+ local global = allGlobals[parentName]
+ if not global then
+ return nil
+ end
+ local link = global.links[uri]
+ if not link then
+ return nil
+ end
+ local luckyBoy = link.sets[1] or link.gets[1]
+ if not luckyBoy then
+ return nil
+ end
+ return vm.getGlobalBase(luckyBoy)
+end
+
---@param cate vm.global.cate
---@return vm.global
local function createGlobal(name, cate)
@@ -138,11 +171,6 @@ end
---@field package _globalNode vm.global|false
---@field package _enums? parser.object[]
----@type table<string, vm.global>
-local allGlobals = {}
----@type table<uri, table<string, boolean>>
-local globalSubs = util.multiTable(2)
-
local compileObject
local compilerGlobalSwitch = util.switch()
: case 'local'