diff options
Diffstat (limited to 'script/core/hover')
-rw-r--r-- | script/core/hover/arg.lua | 13 | ||||
-rw-r--r-- | script/core/hover/description.lua | 1 | ||||
-rw-r--r-- | script/core/hover/init.lua | 4 | ||||
-rw-r--r-- | script/core/hover/label.lua | 10 | ||||
-rw-r--r-- | script/core/hover/name.lua | 6 | ||||
-rw-r--r-- | script/core/hover/return.lua | 129 | ||||
-rw-r--r-- | script/core/hover/table.lua | 6 |
7 files changed, 76 insertions, 93 deletions
diff --git a/script/core/hover/arg.lua b/script/core/hover/arg.lua index d03f55f2..c2c6a105 100644 --- a/script/core/hover/arg.lua +++ b/script/core/hover/arg.lua @@ -1,6 +1,5 @@ local guide = require 'parser.guide' -local infer = require 'core.infer' -local vm = require 'vm' +local infer = require 'vm.infer' local function optionalArg(arg) if not arg.bindDocs then @@ -22,7 +21,7 @@ local function asFunction(source, oop) methodDef = true end if methodDef then - args[#args+1] = ('self: %s'):format(infer.searchAndViewInfers(parent.node)) + args[#args+1] = ('self: %s'):format(infer.viewType(parent.node)) end if source.args then for i = 1, #source.args do @@ -35,15 +34,15 @@ local function asFunction(source, oop) args[#args+1] = ('%s%s: %s'):format( name, optionalArg(arg) and '?' or '', - infer.searchAndViewInfers(arg) + infer.viewType(arg) ) elseif arg.type == '...' then args[#args+1] = ('%s: %s'):format( '...', - infer.searchAndViewInfers(arg) + infer.viewType(arg) ) else - args[#args+1] = ('%s'):format(infer.searchAndViewInfers(arg)) + args[#args+1] = ('%s'):format(infer.viewType(arg)) end ::CONTINUE:: end @@ -66,7 +65,7 @@ local function asDocFunction(source, oop) args[i] = ('%s%s: %s'):format( name, arg.optional and '?' or '', - arg.extends and infer.searchAndViewInfers(arg.extends) or 'any' + arg.extends and infer.viewType(arg.extends) or 'any' ) end if oop then diff --git a/script/core/hover/description.lua b/script/core/hover/description.lua index a5b30cf3..741d7cbd 100644 --- a/script/core/hover/description.lua +++ b/script/core/hover/description.lua @@ -1,6 +1,5 @@ local vm = require 'vm' local ws = require 'workspace' -local searcher = require 'core.searcher' local markdown = require 'provider.markdown' local config = require 'config' local lang = require 'language' diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua index baa24139..fdfbd73d 100644 --- a/script/core/hover/init.lua +++ b/script/core/hover/init.lua @@ -5,7 +5,7 @@ local getDesc = require 'core.hover.description' local util = require 'utility' local findSource = require 'core.find-source' local markdown = require 'provider.markdown' -local infer = require 'core.infer' +local infer = require 'vm.infer' local guide = require 'parser.guide' ---@async @@ -40,7 +40,7 @@ local function getHover(source) end local oop - if infer.searchAndViewInfers(source) == 'function' then + if infer.viewType(source) == 'function' then local hasFunc for _, def in ipairs(vm.getDefs(source)) do if guide.isOOP(def) then diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index d07212f8..37d4c730 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -2,7 +2,7 @@ local buildName = require 'core.hover.name' local buildArg = require 'core.hover.arg' local buildReturn = require 'core.hover.return' local buildTable = require 'core.hover.table' -local infer = require 'core.infer' +local infer = require 'vm.infer' local vm = require 'vm' local util = require 'utility' local lang = require 'language' @@ -35,7 +35,7 @@ local function asDocTypeName(source) end if doc.type == 'doc.alias.name' then local extends = doc.parent.extends - return lang.script('HOVER_EXTENDS', infer.searchAndViewInfers(extends)) + return lang.script('HOVER_EXTENDS', infer.viewType(extends)) end end end @@ -43,8 +43,8 @@ end ---@async local function asValue(source, title) local name = buildName(source, false) or '' - local type = infer.searchAndViewInfers(source) - local literal = infer.searchAndViewLiterals(source) + local type = infer.viewType(source) + local literal = infer.viewLiterals(source) local cont if not infer.hasType(source, 'string') and not type:find('%[%]$') then @@ -131,7 +131,7 @@ local function asDocFieldName(source) break end end - local view = infer.searchAndViewInfers(docField.extends) + local view = infer.viewType(docField.extends) if not class then return ('field ?.%s: %s'):format(name, view) end diff --git a/script/core/hover/name.lua b/script/core/hover/name.lua index 5d8f0b3d..3b1a45c2 100644 --- a/script/core/hover/name.lua +++ b/script/core/hover/name.lua @@ -1,7 +1,5 @@ -local searcher = require 'core.searcher' -local infer = require 'core.infer' +local infer = require 'vm.infer' local guide = require 'parser.guide' -local vm = require 'vm' local buildName @@ -21,7 +19,7 @@ end local function asField(source, oop) local class if source.node.type ~= 'getglobal' then - class = infer.getClass(source.node) + class = infer.viewClass(source.node) end local node = class or buildName(source.node, false) diff --git a/script/core/hover/return.lua b/script/core/hover/return.lua index 681e9747..f34f364e 100644 --- a/script/core/hover/return.lua +++ b/script/core/hover/return.lua @@ -1,94 +1,81 @@ -local infer = require 'core.infer' +local infer = require 'vm.infer' local guide = require 'parser.guide' +local compiler = require 'vm.compiler' + +---@param source parser.object +---@return integer +local function countReturns(source) + local n = 0 -local function getReturnDualByDoc(source) local docs = source.bindDocs - if not docs then - return - end - local dual - for _, doc in ipairs(docs) do - if doc.type == 'doc.return' then - for _, rtn in ipairs(doc.returns) do - if not dual then - dual = {} + if docs then + for _, doc in ipairs(docs) do + if doc.type == 'doc.return' then + for _, rtn in ipairs(doc.returns) do + if rtn.returnIndex and rtn.returnIndex > n then + n = rtn.returnIndex + end end - dual[#dual+1] = { rtn } end end end - return dual -end -local function getReturnDualByGrammar(source) - if not source.returns then - return nil - end - local dual - for _, rtn in ipairs(source.returns) do - if not dual then - dual = {} + local returns = source.returns + if returns then + for _, rtn in ipairs(returns) do + if #rtn > n then + n = #rtn + end end - for n = 1, #rtn do - if not dual[n] then - dual[n] = {} + end + + return n +end + +---@param source parser.object +---@return parser.object[] +local function getReturnDocs(source) + local returns = {} + + local docs = source.bindDocs + if docs then + for _, doc in ipairs(docs) do + if doc.type == 'doc.return' then + for _, rtn in ipairs(doc.returns) do + returns[rtn.returnIndex] = rtn + end end - dual[n][#dual[n]+1] = rtn[n] end end - return dual + + return returns end local function asFunction(source) - local dual = getReturnDualByDoc(source) - or getReturnDualByGrammar(source) - if not dual then - return + local num = countReturns(source) + if num == 0 then + return nil end + + local docs = getReturnDocs(source) + local returns = {} - for i, rtn in ipairs(dual) do - local line = {} - local infers = {} + + for i = 1, num do + local rtn = compiler.getReturnOfFunction(source, i) + local doc = docs[i] + local text = ('%s%s%s'):format( + doc and doc.name[1] or '', + infer.viewType(rtn), + doc and doc.optional and '?' or '' + ) if i == 1 then - line[#line+1] = ' -> ' - else - line[#line+1] = ('% 3d. '):format(i) - end - for n = 1, #rtn do - if rtn[n].type == 'doc.type' then - for _, typeUnit in ipairs(rtn[n].types) do - if typeUnit[1] == 'nil' then - infers['nil'] = true - end - end - end - local values = infer.searchInfers(rtn[n]) - for tp in pairs(values) do - infers[tp] = true - end - end - if next(infers) or rtn[1] then - local tp = infer.viewInfers(guide.getUri(source), infers) - if rtn[1].name then - line[#line+1] = ('%s%s: %s'):format( - rtn[1].name[1], - rtn[1].optional and '?' or '', - tp - ) - else - line[#line+1] = ('%s%s'):format( - tp, - rtn[1].optional and '?' or '' - ) - end + returns[i] = (' -> %s'):format(text) else - break + returns[i] = ('% 3d. %s'):format(i, text) end - returns[i] = table.concat(line) - end - if #returns == 0 then - return nil end + return table.concat(returns, '\n') end @@ -99,7 +86,7 @@ local function asDocFunction(source) local returns = {} for i, rtn in ipairs(source.returns) do local rtnText = ('%s%s'):format( - infer.searchAndViewInfers(rtn), + infer.viewType(rtn), rtn.optional and '?' or '' ) if i == 1 then diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua index 374f756d..e2c439af 100644 --- a/script/core/hover/table.lua +++ b/script/core/hover/table.lua @@ -1,7 +1,7 @@ local vm = require 'vm' local util = require 'utility' local config = require 'config' -local infer = require 'core.infer' +local infer = require 'vm.infer' local await = require 'await' local guide = require 'parser.guide' @@ -177,8 +177,8 @@ return function (source) await.delay() local key = keys[i] - inferMap[key] = infer.searchAndViewInfers(source, key) - literalMap[key] = infer.searchAndViewLiterals(source, key) + inferMap[key] = infer.viewType(source, key) + literalMap[key] = infer.viewLiterals(source, key) if not tonumber(literalMap[key]) then isConsts = false end |