diff options
author | sumneko <sumneko@hotmail.com> | 2022-03-05 21:24:34 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2022-03-05 21:24:34 +0800 |
commit | e556621ca31bc80c78048b82412cb46bdb3a085a (patch) | |
tree | cc4b49dd818a5762762711b6f46faebb2c936f79 | |
parent | 6b7b3a89c8ef0640571ebe9324ea4e43ffbfff33 (diff) | |
download | lua-language-server-e556621ca31bc80c78048b82412cb46bdb3a085a.zip |
literal generic
-rw-r--r-- | script/parser/luadoc.lua | 3 | ||||
-rw-r--r-- | script/vm/compiler.lua | 22 | ||||
-rw-r--r-- | script/vm/generic-manager.lua | 14 |
3 files changed, 30 insertions, 9 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 5bc566f2..ccc38eac 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -120,6 +120,9 @@ Symbol <- ({} { end, }) +---@class parser.object +---@field literal boolean + local function trim(str) return str:match '^%s*(%S+)%s*$' end diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index da4ea7b4..ff13db1a 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -2,9 +2,7 @@ local guide = require 'parser.guide' local util = require 'utility' local union = require 'vm.union' local localID = require 'vm.local-id' -local localMgr = require 'vm.local-manager' local globalMgr = require 'vm.global-manager' -local genericMgr = require 'vm.generic-manager' ---@class parser.object ---@field _compiledNodes boolean @@ -17,6 +15,19 @@ local nodeCache = {} ---@alias vm.node parser.object | vm.node.union | vm.node.global | vm.node.generic +---@param a vm.node +---@param b vm.node +function m.mergeNode(a, b) + if not b then + return a + end + if a.type == 'union' then + a:merge(b) + return a + end + return union(a, b) +end + function m.setNode(source, node) if not node then return @@ -29,11 +40,7 @@ function m.setNode(source, node) if me == node then return end - if me.type == 'union' then - me:merge(node) - return - end - nodeCache[source] = union(me, node) + nodeCache[source] = m.mergeNode(me, node) end function m.eachNode(node) @@ -291,6 +298,7 @@ local function getFunctionGeneric(func) return func._generic end func._generic = false + local genericMgr = require 'vm.generic-manager' for _, doc in ipairs(func.bindDocs) do if doc.type == 'doc.generic' then if not func._generic then diff --git a/script/vm/generic-manager.lua b/script/vm/generic-manager.lua index dbee5dae..4b8b4a3c 100644 --- a/script/vm/generic-manager.lua +++ b/script/vm/generic-manager.lua @@ -1,4 +1,7 @@ local createGeneric = require 'vm.generic' +local compiler = require 'vm.compiler' +local globalMgr = require 'vm.global-manager' +local guide = require 'parser.guide' ---@class vm.node.generic-manager ---@field parent parser.object @@ -30,8 +33,15 @@ function mt:resolve(argNodes) for _, typeUnit in ipairs(sign.types) do if typeUnit.type == 'doc.generic.name' then local key = typeUnit[1] - if not resolved[key] then - resolved[key] = node + if typeUnit.literal then + for n in compiler.eachNode(node) do + if n.type == 'string' then + local type = globalMgr.declareGlobal('type', n[1], guide.getUri(n)) + resolved[key] = compiler.mergeNode(type, resolved[key]) + end + end + else + resolved[key] = compiler.mergeNode(node, resolved[key]) end end end |