diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-05 02:00:27 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-05 02:00:27 +0800 |
commit | 8661aaa67e749190c97ed2960bcc7453d6224876 (patch) | |
tree | 907b984ca5b4a758eccd1cbdfa7e69d458f84003 /script | |
parent | b04ad0cbe77602f739cb35d7ba838a1f62d298dd (diff) | |
download | lua-language-server-8661aaa67e749190c97ed2960bcc7453d6224876.zip |
update
Diffstat (limited to 'script')
-rw-r--r-- | script/vm/compiler.lua | 15 | ||||
-rw-r--r-- | script/vm/global-manager.lua | 16 | ||||
-rw-r--r-- | script/vm/infer.lua | 14 |
3 files changed, 43 insertions, 2 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 1473b985..c1ed4e95 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -103,6 +103,7 @@ local searchFieldSwitch = util.switch() function m.getClassFields(node, key, pushResult) local mark = {} + local function searchClass(class) local name = class.name if mark[name] then @@ -151,7 +152,21 @@ function m.getClassFields(node, key, pushResult) end end end + + local function searchGlobal(class) + if class.cate == 'type' and class.name == '_G' then + local globals = globalMgr.getGlobals('variable') + for _, global in ipairs(globals) do + local sets = global:getSets() + for _, set in ipairs(sets) do + pushResult(set) + end + end + end + end + searchClass(node) + searchGlobal(node) end ---@class parser.object diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua index fc9ff633..eed65c64 100644 --- a/script/vm/global-manager.lua +++ b/script/vm/global-manager.lua @@ -244,6 +244,22 @@ function m.getFields(cate, name) return globals end +---@param cate vm.global.cate +---@return vm.node.global[] +function m.getGlobals(cate) + local globals = {} + + -- TODO: optimize + for gid, global in pairs(m.globals) do + if util.stringStartWith(gid, cate) + and not gid:find(m.ID_SPLITE) 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/infer.lua b/script/vm/infer.lua index 5a6ec369..760f340c 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -310,12 +310,17 @@ function mt:viewLiterals() if not self.node then return nil end + local mark = {} local literals = {} for n in nodeMgr.eachNode(self.node) do if n.type == 'string' or n.type == 'number' or n.type == 'integer' then - literals[#literals+1] = util.viewLiteral(n[1]) + local literal = util.viewLiteral(n[1]) + if not mark[literal] then + literals[#literals+1] = literal + mark[literal] = true + end end end if #literals == 0 then @@ -330,10 +335,15 @@ function mt:viewClass() if not self.node then return nil end + local mark = {} local class = {} for n in nodeMgr.eachNode(self.node) do if n.type == 'global' and n.cate == 'type' then - class[#class+1] = n.name + local name = n.name + if not mark[name] then + class[#class+1] = name + mark[name] = true + end end end if #class == 0 then |