diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-08 13:12:31 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-08 13:12:31 +0800 |
commit | 3771e70b48e9a088cbdc11a8b952d525eea1e7c9 (patch) | |
tree | 065b1c5501dfaf1aef5c484f6128bc61cc75d054 /script | |
parent | b8c5db4d443e5a0c638d964104d8966f837eeb6a (diff) | |
download | lua-language-server-3771e70b48e9a088cbdc11a8b952d525eea1e7c9.zip |
cleanup
Diffstat (limited to 'script')
-rw-r--r-- | script/core/hover/label.lua | 5 | ||||
-rw-r--r-- | script/core/hover/table.lua | 7 | ||||
-rw-r--r-- | script/gc.lua | 1 | ||||
-rw-r--r-- | script/vm/getLinks.lua | 63 | ||||
-rw-r--r-- | script/vm/infer.lua | 5 | ||||
-rw-r--r-- | script/vm/init.lua | 4 | ||||
-rw-r--r-- | script/vm/library.lua (renamed from script/vm/getLibrary.lua) | 0 | ||||
-rw-r--r-- | script/vm/sign.lua | 11 | ||||
-rw-r--r-- | script/vm/type.lua | 45 |
9 files changed, 50 insertions, 91 deletions
diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index 995c3294..c2239344 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -45,10 +45,7 @@ local function asValue(source, title) local ifr = infer.getInfer(source) local type = ifr:view() local literal = ifr:viewLiterals() - local cont - if not ifr:hasType 'string' then - cont = buildTable(source) - end + local cont = buildTable(source) local pack = {} pack[#pack+1] = title pack[#pack+1] = name .. ':' diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua index 88808daa..8f9beefe 100644 --- a/script/core/hover/table.lua +++ b/script/core/hover/table.lua @@ -163,6 +163,13 @@ return function (source) return nil end + for view in infer.getInfer(source):eachView() do + if view == 'string' + or vm.isSubType(view, 'string') then + return nil + end + end + local fields = vm.getFields(source) local keys, map = getKeyMap(fields) if #keys == 0 then diff --git a/script/gc.lua b/script/gc.lua index 24a72f15..7bb81569 100644 --- a/script/gc.lua +++ b/script/gc.lua @@ -5,6 +5,7 @@ local util = require 'utility' local mt = {} mt.__index = mt mt.type = 'gc' +mt._removed = false mt._max = 10 diff --git a/script/vm/getLinks.lua b/script/vm/getLinks.lua deleted file mode 100644 index 8571fb46..00000000 --- a/script/vm/getLinks.lua +++ /dev/null @@ -1,63 +0,0 @@ -local guide = require 'parser.guide' ----@class vm -local vm = require 'vm.vm' -local files = require 'files' -local rpath = require 'workspace.require-path' - -local function getFileLinks(uri) - local links = {} - local state = files.getState(uri) - if not state then - return links - end - tracy.ZoneBeginN('getFileLinks') - guide.eachSpecialOf(state.ast, 'require', function (source) - local call = source.parent - if not call or call.type ~= 'call' then - return - end - local args = call.args - if not args or not args[1] or args[1].type ~= 'string' then - return - end - local uris = rpath.findUrisByRequirePath(uri, args[1][1]) - for _, u in ipairs(uris) do - if not links[u] then - links[u] = {} - end - links[u][#links[u]+1] = call - end - end) - tracy.ZoneEnd() - return links -end - -local function getFileLinksOrCache(uri) - local cache = files.getCache(uri) - cache.links = cache.links or getFileLinks(uri) - return cache.links -end - -local function getLinksTo(uri) - local links = {} - for u in files.eachFile(uri) do - local ls = getFileLinksOrCache(u) - if ls[uri] then - for _, l in ipairs(ls[uri]) do - links[#links+1] = l - end - end - end - return links -end - --- 获取所有 require(uri) 的文件 -function vm.getLinksTo(uri) - local cache = vm.getCache('getLinksTo')[uri] - if cache ~= nil then - return cache - end - cache = getLinksTo(uri) - vm.getCache('getLinksTo')[uri] = cache - return cache -end diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 853bd7de..1ccc54aa 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -309,6 +309,11 @@ function mt:view(default, uri) end end +function mt:eachView() + self:_computeViews() + return next, self.views +end + ---@param other vm.infer ---@return vm.infer function mt:merge(other) diff --git a/script/vm/init.lua b/script/vm/init.lua index aa1b908f..4f527930 100644 --- a/script/vm/init.lua +++ b/script/vm/init.lua @@ -4,6 +4,6 @@ require 'vm.def' require 'vm.ref' require 'vm.field' require 'vm.doc' -require 'vm.getLibrary' -require 'vm.getLinks' +require 'vm.type' +require 'vm.library' return vm diff --git a/script/vm/getLibrary.lua b/script/vm/library.lua index 1a8d8ffd..1a8d8ffd 100644 --- a/script/vm/getLibrary.lua +++ b/script/vm/library.lua diff --git a/script/vm/sign.lua b/script/vm/sign.lua index 2c440902..eae549e4 100644 --- a/script/vm/sign.lua +++ b/script/vm/sign.lua @@ -1,5 +1,7 @@ local guide = require 'parser.guide' local nodeMgr = require 'vm.node' +---@class vm +local vm = require 'vm.vm' ---@class vm.sign ---@field parent parser.object @@ -19,7 +21,6 @@ function mt:resolve(argNodes) if not argNodes then return nil end - local typeMgr = require 'vm.type' local compiler = require 'vm.compiler' local globalMgr = require 'vm.global-manager' local resolved = {} @@ -56,18 +57,18 @@ function mt:resolve(argNodes) local uvalueNode = compiler.compileNode(ufield.extends) if ufieldNode.type == 'doc.generic.name' and uvalueNode.type == 'doc.generic.name' then -- { [number]: number} -> { [K]: V } - local tfieldNode = typeMgr.getTableKey(node, 'any') - local tvalueNode = typeMgr.getTableValue(node, 'any') + local tfieldNode = vm.getTableKey(node, 'any') + local tvalueNode = vm.getTableValue(node, 'any') resolve(ufieldNode, tfieldNode) resolve(uvalueNode, tvalueNode) else if ufieldNode.type == 'doc.generic.name' then -- { [number]: number}|number[] -> { [K]: number } - local tnode = typeMgr.getTableKey(node, uvalueNode) + local tnode = vm.getTableKey(node, uvalueNode) resolve(ufieldNode, tnode) else -- { [number]: number}|number[] -> { [number]: V } - local tnode = typeMgr.getTableValue(node, ufieldNode) + local tnode = vm.getTableValue(node, ufieldNode) resolve(uvalueNode, tnode) end end diff --git a/script/vm/type.lua b/script/vm/type.lua index 8b80d4f3..4cac9723 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -1,14 +1,14 @@ local nodeMgr = require 'vm.node' local compiler = require 'vm.compiler' local globalMgr = require 'vm.global-manager' +---@class vm +local vm = require 'vm.vm' ----@class vm.type-manager -local m = {} - ----@param child vm.node ----@param parent vm.node +---@param child vm.node|string +---@param parent vm.node|string +---@param mark? table ---@return boolean -function m.isSubType(child, parent, mark) +function vm.isSubType(child, parent, mark) if type(parent) == 'string' then parent = globalMgr.getGlobal('type', parent) end @@ -16,13 +16,17 @@ function m.isSubType(child, parent, mark) child = globalMgr.getGlobal('type', child) end + if not child or not parent then + return false + end + if parent.type == 'global' and parent.cate == 'type' and parent.name == 'any' then return true end if child.type == 'doc.type' then for _, typeUnit in ipairs(child.types) do - if not m.isSubType(typeUnit, parent) then + if not vm.isSubType(typeUnit, parent) then return false end end @@ -36,7 +40,7 @@ function m.isSubType(child, parent, mark) if child.type == 'global' and child.cate == 'type' then if parent.type == 'doc.type' then for _, typeUnit in ipairs(parent.types) do - if m.isSubType(child, typeUnit) then + if vm.isSubType(child, typeUnit) then return true end end @@ -58,7 +62,16 @@ function m.isSubType(child, parent, mark) for _, set in ipairs(child:getSets()) do if set.type == 'doc.class' and set.extends then for _, ext in ipairs(set.extends) do - if m.isSubType(globalMgr.getGlobal('type', ext[1]), parent, mark) then + if ext.type == 'doc.extends.name' + and vm.isSubType(globalMgr.getGlobal('type', ext[1]), parent, mark) then + return true + end + end + end + if set.type == 'doc.alias' and set.extends then + for _, ext in ipairs(set.extends.types) do + if ext.type == 'doc.type.name' + and vm.isSubType(globalMgr.getGlobal('type', ext[1]), parent, mark) then return true end end @@ -72,18 +85,18 @@ end ---@param tnode vm.node ---@param knode vm.node -function m.getTableValue(tnode, knode) +function vm.getTableValue(tnode, knode) local result for tn in nodeMgr.eachNode(tnode) do if tn.type == 'doc.type.table' then for _, field in ipairs(tn.fields) do - if m.isSubType(field.name, knode) then + if vm.isSubType(field.name, knode) then result = nodeMgr.mergeNode(result, compiler.compileNode(field.extends)) end end end if tn.type == 'doc.type.array' then - if m.isSubType(globalMgr.getGlobal('type', 'integer'), knode) then + if vm.isSubType(globalMgr.getGlobal('type', 'integer'), knode) then result = nodeMgr.mergeNode(result, compiler.compileNode(tn.node)) end end @@ -106,18 +119,18 @@ end ---@param tnode vm.node ---@param vnode vm.node -function m.getTableKey(tnode, vnode) +function vm.getTableKey(tnode, vnode) local result for tn in nodeMgr.eachNode(tnode) do if tn.type == 'doc.type.table' then for _, field in ipairs(tn.fields) do - if m.isSubType(field.extends, vnode) then + if vm.isSubType(field.extends, vnode) then result = nodeMgr.mergeNode(result, compiler.compileNode(field.name)) end end end if tn.type == 'doc.type.array' then - if m.isSubType(tn.node, vnode) then + if vm.isSubType(tn.node, vnode) then result = nodeMgr.mergeNode(result, globalMgr.getGlobal('type', 'integer')) end end @@ -137,5 +150,3 @@ function m.getTableKey(tnode, vnode) end return result end - -return m |