diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-12-13 16:39:03 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-12-13 16:39:03 +0800 |
commit | 73f8157c96d2551d7cfc3e2b1868a792095eec03 (patch) | |
tree | 503f161ef19fd6258f7f84f55e91a50b7dd5daaa /script/vm/tracer.lua | |
parent | 98589ddbeba3cb7e9341e79bb674bad9e8b957c3 (diff) | |
download | lua-language-server-73f8157c96d2551d7cfc3e2b1868a792095eec03.zip |
special treats for `do`
Diffstat (limited to 'script/vm/tracer.lua')
-rw-r--r-- | script/vm/tracer.lua | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/script/vm/tracer.lua b/script/vm/tracer.lua index ba83fd5b..2e2fd084 100644 --- a/script/vm/tracer.lua +++ b/script/vm/tracer.lua @@ -9,7 +9,7 @@ local guide = require 'parser.guide' ---@class vm.tracer ---@field source parser.object ---@field assigns parser.object[] ----@field nodes table<parser.object, vm.node> +---@field nodes table<parser.object, vm.node|false> ---@field main parser.object ---@field uri uri local mt = {} @@ -34,15 +34,20 @@ end ---@param mark table function mt:collectBlock(obj, mark) while true do + obj = obj.parent if mark[obj] then return end - mark[obj] = true - self.assigns[#self.assigns+1] = obj + if not guide.isBlockType(obj) then + return + end if obj == self.main then return end - obj = obj.parent + mark[obj] = true + if obj.type ~= 'do' then + self.assigns[#self.assigns+1] = obj + end end end @@ -78,11 +83,23 @@ end ---@return parser.object? function mt:getLastAssign(source) local assign = self.source + local block = guide.getParentBlock(source) + if not block then + return nil + end for _, obj in ipairs(self.assigns) do - if obj.start > source.start then + if obj.start >= source.start then break end - assign = obj + local objBlock = guide.getParentBlock(obj) + if not objBlock then + break + end + if objBlock == block + or objBlock.type == 'do' + or objBlock.finish > block.finish then + assign = obj + end end return assign end @@ -90,17 +107,22 @@ end ---@param source parser.object ---@return vm.node? function mt:getNode(source) - if self.nodes[source] then - return self.nodes[source] + if self.nodes[source] ~= nil then + return self.nodes[source] or nil end local lastAssign = self:getLastAssign(source) if not lastAssign then + self.nodes[source] = false return nil end if guide.isSet(lastAssign) then local lastNode = vm.compileNode(lastAssign) + self.nodes[source] = lastNode return lastNode end + local lastNode = self:getNode(lastAssign) + self.nodes[source] = lastNode + return lastNode end ---@param source parser.object |