diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-01 03:35:40 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-01 03:35:40 +0800 |
commit | b9fdfac7c33478161dc17b8e41a0bd46b6f23621 (patch) | |
tree | c9e748de4a93fa892851f8592545aadb20690009 /script/vm | |
parent | d8e7c0b4b388c5ca125d17554814be68444ce1aa (diff) | |
download | lua-language-server-b9fdfac7c33478161dc17b8e41a0bd46b6f23621.zip |
update
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/compiler.lua | 19 | ||||
-rw-r--r-- | script/vm/field.lua | 22 | ||||
-rw-r--r-- | script/vm/local-id.lua | 29 | ||||
-rw-r--r-- | script/vm/vm.lua | 12 |
4 files changed, 55 insertions, 27 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index d1f8c601..058f80ec 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -21,7 +21,8 @@ local searchFieldSwitch = util.switch() for _, field in ipairs(node) do if field.type == 'tablefield' or field.type == 'tableindex' then - if guide.getKeyName(field) == key then + if not key + or key == guide.getKeyName(field) then pushResult(field) end end @@ -48,9 +49,9 @@ local searchFieldSwitch = util.switch() end) : case 'local' : call(function (node, key, pushResult) - local sources = localID.getSources(node, key) - if sources then - for _, src in ipairs(sources) do + local fields = key and localID.getSources(node, key) or localID.getFields(node) + if fields then + for _, src in ipairs(fields) do pushResult(src) end end @@ -71,7 +72,8 @@ local searchFieldSwitch = util.switch() local fieldNode = m.compileNode(fieldKey) for fn in nodeMgr.eachNode(fieldNode) do if fn.type == 'global' and fn.cate == 'type' then - if fn.name == 'any' + if not key + or fn.name == 'any' or (fn.name == 'boolean' and type(key) == 'boolean') or (fn.name == 'number' and type(key) == 'number') or (fn.name == 'integer' and math.tointeger(key)) @@ -82,7 +84,7 @@ local searchFieldSwitch = util.switch() end end if fieldKey.type == 'doc.field.name' then - if fieldKey[1] == key then + if not key or fieldKey[1] == key then pushResult(field.extends) end end @@ -103,7 +105,8 @@ function m.getClassFields(node, key, pushResult) -- check ---@field local hasFounded for _, field in ipairs(set.fields) do - if guide.getKeyName(field) == key then + if not key + or guide.getKeyName(field) == key then hasFounded = true pushResult(field) end @@ -341,7 +344,7 @@ local function compileByLocalID(source) end ---@param source vm.node ----@param key any +---@param key? any ---@param pushResult fun(source: parser.object) function m.compileByParentNode(source, key, pushResult) local parentNode = m.compileNode(source) diff --git a/script/vm/field.lua b/script/vm/field.lua index c30e112d..52c56e7f 100644 --- a/script/vm/field.lua +++ b/script/vm/field.lua @@ -7,26 +7,10 @@ local localID = require 'vm.local-id' local globalMgr = require 'vm.global-manager' local nodeMgr = require 'vm.node' -local searchNodeSwitch = util.switch() - : case 'table' - : call(function (node, pushResult) - for _, field in ipairs(node) do - if field.type == 'tablefield' - or field.type == 'tableindex' then - pushResult(field) - end - end - end) - local function searchByNode(source, pushResult) - local node = compiler.compileNode(source) - if not node then - return - end - - for n in nodeMgr.eachNode(node) do - searchNodeSwitch(n.type, n, pushResult) - end + compiler.compileByParentNode(source, nil, function (field) + pushResult(field) + end) end ---@param source parser.object diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua index 4c9da197..8d530beb 100644 --- a/script/vm/local-id.lua +++ b/script/vm/local-id.lua @@ -109,6 +109,9 @@ function m.compileLocalID(source) return end compileSwitch(source.type, source) + if not source._localID then + return + end local root = guide.getRoot(source) if not root._localIDs then root._localIDs = util.multiTable(2) @@ -153,4 +156,30 @@ function m.getSources(source, key) return root._localIDs[id] end +---@param source parser.object +---@return parser.object[] +function m.getFields(source) + local id = m.getID(source) + if not id then + return nil + end + local root = guide.getRoot(source) + if not root._localIDs then + return nil + end + -- TODO:optimize + local fields = {} + for lid, sources in pairs(root._localIDs) do + if lid ~= id + and util.stringStartWith(lid, id) + -- only one field + and not lid:find(m.ID_SPLITE, #id + 2) then + for _, src in ipairs(sources) do + fields[#fields+1] = src + end + end + end + return fields +end + return m diff --git a/script/vm/vm.lua b/script/vm/vm.lua index e524589c..d370de0d 100644 --- a/script/vm/vm.lua +++ b/script/vm/vm.lua @@ -49,6 +49,18 @@ function m.getKeyType(source) return guide.getKeyType(source) end +---@param source parser.object +---@return parser.object? +function m.getObjectValue(source) + if source.value then + return source.value + end + if source.special == 'rawset' then + return source.args and source.args[3] + end + return nil +end + m.cacheTracker = setmetatable({}, weakMT) function m.flushCache() |