diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-01 17:54:19 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-01 17:54:19 +0800 |
commit | d699b4cac83b81b023323076b74d3d03b6b13ee6 (patch) | |
tree | f5b22d0425e0e467a1604d43b4ed6b22b697c81e /script/vm | |
parent | 231e4e3b2be6f815c1d6734185537f777ef32d88 (diff) | |
download | lua-language-server-d699b4cac83b81b023323076b74d3d03b6b13ee6.zip |
update
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/compiler.lua | 13 | ||||
-rw-r--r-- | script/vm/field.lua | 14 | ||||
-rw-r--r-- | script/vm/global-manager.lua | 20 | ||||
-rw-r--r-- | script/vm/local-id.lua | 1 |
4 files changed, 44 insertions, 4 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 158fdc36..6f542367 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -32,9 +32,16 @@ local searchFieldSwitch = util.switch() ---@param node vm.node.global : call(function (node, key, pushResult) if node.cate == 'variable' then - local global = globalMgr.getGlobal('variable', node.name, key) - if global then - pushResult(global) + if key then + local global = globalMgr.getGlobal('variable', node.name, key) + if global then + pushResult(global) + end + else + local globals = globalMgr.getFields('variable', node.name) + for _, global in ipairs(globals) do + pushResult(global) + end end end if node.cate == 'type' then diff --git a/script/vm/field.lua b/script/vm/field.lua index 52c56e7f..563c7868 100644 --- a/script/vm/field.lua +++ b/script/vm/field.lua @@ -7,9 +7,21 @@ local localID = require 'vm.local-id' local globalMgr = require 'vm.global-manager' local nodeMgr = require 'vm.node' +local searchByNodeSwitch = util.switch() + : case 'global' + ---@param global vm.node.global + : call(function (global, pushResult) + for _, set in ipairs(global:getSets()) do + pushResult(set) + end + end) + : default(function (source, pushResult) + pushResult(source) + end) + local function searchByNode(source, pushResult) compiler.compileByParentNode(source, nil, function (field) - pushResult(field) + searchByNodeSwitch(field.type, field, pushResult) end) end diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua index 99d1b697..fc9ff633 100644 --- a/script/vm/global-manager.lua +++ b/script/vm/global-manager.lua @@ -224,6 +224,26 @@ function m.getGlobal(cate, name, field) return m.globals[key] end +---@param cate vm.global.cate +---@param name string +---@return vm.node.global[] +function m.getFields(cate, name) + local globals = {} + local key = cate .. '|' .. name + + -- TODO: optimize + for gid, global in pairs(m.globals) do + if gid ~= key + and util.stringStartWith(gid, key) + and gid:sub(#key + 1, #key + 1) == m.ID_SPLITE + and not gid:find(m.ID_SPLITE, #key + 2) then + globals[#globals+1] = global + end + end + + return globals +end + ---@param source parser.object function m.compileObject(source) if source._globalNode ~= nil then diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua index 8d530beb..06e086c7 100644 --- a/script/vm/local-id.lua +++ b/script/vm/local-id.lua @@ -172,6 +172,7 @@ function m.getFields(source) for lid, sources in pairs(root._localIDs) do if lid ~= id and util.stringStartWith(lid, id) + and lid:sub(#id + 1, #id + 1) == m.ID_SPLITE -- only one field and not lid:find(m.ID_SPLITE, #id + 2) then for _, src in ipairs(sources) do |