diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-03-02 20:31:35 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-03-02 20:31:35 +0800 |
commit | be0d11df2d89b8cb8cf24190ccfbd273256f4c74 (patch) | |
tree | 328597311c655f39bc43c9bcb963a4fd7491a65c /script/vm | |
parent | 4508b4018dced01fe5420e008e813199d0ce856f (diff) | |
download | lua-language-server-be0d11df2d89b8cb8cf24190ccfbd273256f4c74.zip |
update
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/getDef.lua | 18 | ||||
-rw-r--r-- | script/vm/global-manager.lua | 11 | ||||
-rw-r--r-- | script/vm/local-id.lua | 6 | ||||
-rw-r--r-- | script/vm/node/compiler.lua | 30 |
4 files changed, 52 insertions, 13 deletions
diff --git a/script/vm/getDef.lua b/script/vm/getDef.lua index c423ba1a..e661b861 100644 --- a/script/vm/getDef.lua +++ b/script/vm/getDef.lua @@ -178,13 +178,30 @@ function searchByParentNode(source, pushResult) end end +local function searchByNode(source, pushResult) + local node = compiler.compileNode(source) + if not node then + return + end + for n in compiler.eachNode(node) do + pushResult(n) + end +end + ---@param source parser.object ---@return parser.object[] function vm.getDefs(source) local results = {} local mark = {} + local hasLocal local function pushResult(src) + if src.type == 'local' and not src.dummy then + if hasLocal then + return + end + hasLocal = true + end if not mark[src] then mark[src] = true results[#results+1] = src @@ -195,6 +212,7 @@ function vm.getDefs(source) searchByGlobal(source, pushResult) searchByID(source, pushResult) searchByParentNode(source, pushResult) + searchByNode(source, pushResult) return results end diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua index 5267aea1..4c2a535e 100644 --- a/script/vm/global-manager.lua +++ b/script/vm/global-manager.lua @@ -60,15 +60,19 @@ local compilerGlobalMap = util.switch() ---@param source parser.object : call(function (source) local name + local keyName = guide.getKeyName(source) + if not keyName then + return + end if source.node._globalNode then local parentName = source.node._globalNode:getName() if parentName == '_G' then - name = guide.getKeyName(source) + name = keyName else - name = parentName .. m.ID_SPLITE .. guide.getKeyName(source) + name = parentName .. m.ID_SPLITE .. keyName end elseif source.node.special == '_G' then - name = guide.getKeyName(source) + name = keyName end if not name then return @@ -117,6 +121,7 @@ local compilerGlobalMap = util.switch() local global = m.declareGlobal(name, uri) if source.node.special == 'rawset' then global:addSet(uri, source) + source.value = source.args[3] else global:addGet(uri, source) end diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua index ddcb9e97..230f48eb 100644 --- a/script/vm/local-id.lua +++ b/script/vm/local-id.lua @@ -59,7 +59,11 @@ local compileMap = util.switch() if not parentID then return end - source._localID = parentID .. m.ID_SPLITE .. guide.getKeyName(source) + local key = guide.getKeyName(source) + if not key then + return + end + source._localID = parentID .. m.ID_SPLITE .. key source.index._localID = source._localID if source.type == 'setindex' then m.compileLocalID(source.next) diff --git a/script/vm/node/compiler.lua b/script/vm/node/compiler.lua index dbfc54d1..dd151e4f 100644 --- a/script/vm/node/compiler.lua +++ b/script/vm/node/compiler.lua @@ -109,16 +109,14 @@ local function getReturnOfSetMetaTable(source, args) end local function getReturn(func, index, source, args) - local node = m.compileNode(func) - if not node then - return + if func.special == 'setmetatable' then + return getReturnOfSetMetaTable(source, args) end - for cnode in m.eachNode(node) do - if cnode.type == 'function' then - return getReturnOfFunction(cnode, index) - elseif cnode.type == 'global' then - if cnode.name == 'setmetatable' and index == 1 then - return getReturnOfSetMetaTable(source, args) + local node = m.compileNode(func) + if node then + for cnode in m.eachNode(node) do + if cnode.type == 'function' then + return getReturnOfFunction(cnode, index) end end end @@ -215,6 +213,11 @@ local compilerMap = util.switch() m.setNode(source, m.compileNode(source.value)) end end) + : case 'field' + : case 'method' + : call(function (source) + m.setNode(source, m.compileNode(source.parent)) + end) : case 'function.return' : call(function (source) local func = source.parent @@ -234,6 +237,10 @@ local compilerMap = util.switch() m.setNode(source, getReturn(vararg.node, source.sindex, source, vararg.args)) end end) + : case 'call' + : call(function (source) + m.setNode(source, getReturn(source.node, 1, source, source.args)) + end) : getMap() ---@param source parser.object @@ -248,6 +255,11 @@ end local function compileByGlobal(source) if source._globalNode then m.setNode(source, source._globalNode) + for _, set in ipairs(source._globalNode:getSets()) do + if set.value then + m.setNode(source, m.compileNode(set.value)) + end + end end end |