diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-01-04 20:42:24 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-01-04 20:42:24 +0800 |
commit | 702b0e7abe33f099e26ce48fdd4d82d6c8d7af0e (patch) | |
tree | c6b5f3892cdd6e5870a0b63703d1976bb3ac787c | |
parent | e74d75c40e5c1b3dff2454b70aafb38332cf8969 (diff) | |
download | lua-language-server-702b0e7abe33f099e26ce48fdd4d82d6c8d7af0e.zip |
fix viewing
-rw-r--r-- | script/vm/compiler.lua | 2 | ||||
-rw-r--r-- | script/vm/infer.lua | 36 |
2 files changed, 17 insertions, 21 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 65e8d008..43c372a0 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -613,7 +613,6 @@ local function bindAs(source) local doc = ases[index] if doc and doc.touch == source.finish then local asNode = vm.compileNode(doc.as) - asNode.resolved = true vm.setNode(source, asNode, true) return true end @@ -1947,6 +1946,5 @@ function vm.compileNode(source) local node = vm.getNode(source) ---@cast node -? - node.resolved = true return node end diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 99cf622e..3a89c4c8 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -134,11 +134,12 @@ local viewNodeSwitch;viewNodeSwitch = util.switch() for i, sign in ipairs(source.signs) do buf[i] = vm.getInfer(sign):view(uri) end - if infer._drop then - local node = vm.compileNode(source) - for c in node:eachObject() do - if guide.isLiteral(c) then - infer._drop[c] = true + local node = vm.compileNode(source) + for c in node:eachObject() do + if guide.isLiteral(c) then + local view = vm.viewObject(c, uri) + if view then + infer._drop[view] = true end end end @@ -150,10 +151,6 @@ local viewNodeSwitch;viewNodeSwitch = util.switch() infer._hasTable = true return end - if infer._drop and infer._drop[source] then - infer._hasTable = true - return - end infer._hasClass = true local buf = {} buf[#buf+1] = '{ ' @@ -291,9 +288,7 @@ function mt:_trim() end ---@param uri uri ----@return table<string, true> function mt:_eraseAlias(uri) - local drop = {} local expandAlias = config.get(uri, 'Lua.hover.expandAlias') for n in self.node:eachObject() do if n.type == 'global' and n.cate == 'type' then @@ -304,8 +299,10 @@ function mt:_eraseAlias(uri) for _, set in ipairs(n:getSets(uri)) do if set.type == 'doc.alias' then if expandAlias then - drop[n.name] = true - local newInfer = {} + self._drop[n.name] = true + local newInfer = setmetatable({ + _drop = {}, + }, mt) for _, ext in ipairs(set.extends.types) do viewNodeSwitch(ext.type, ext, newInfer, uri) end @@ -316,7 +313,7 @@ function mt:_eraseAlias(uri) for _, ext in ipairs(set.extends.types) do local view = viewNodeSwitch(ext.type, ext, {}, uri) if view and view ~= n.name then - drop[view] = true + self._drop[view] = true end end end @@ -326,7 +323,6 @@ function mt:_eraseAlias(uri) ::CONTINUE:: end end - return drop end ---@param uri uri @@ -393,14 +389,13 @@ function mt:view(uri, default) return 'any' end - local drop if self._hasClass then - drop = self:_eraseAlias(uri) + self:_eraseAlias(uri) end local array = {} for view in pairs(self.views) do - if not drop or not drop[view] then + if not self._drop[view] then array[#array+1] = view end end @@ -529,7 +524,10 @@ end ---@param uri uri ---@return string? function vm.viewObject(source, uri) - return viewNodeSwitch(source.type, source, {}, uri) + local infer = setmetatable({ + _drop = {}, + }, mt) + return viewNodeSwitch(source.type, source, infer, uri) end ---@param source parser.object |