diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-03-29 22:29:33 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-03-29 22:29:33 +0800 |
commit | ed484ba5809ef58eccf04cba4861c54f1925f794 (patch) | |
tree | 7ac1e09f4a73ae27749ff588514297fdfacdc446 /script/core | |
parent | 529856733fdfdf87f3aec704647798a5b611f49d (diff) | |
download | lua-language-server-ed484ba5809ef58eccf04cba4861c54f1925f794.zip |
update
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/completion/completion.lua | 12 | ||||
-rw-r--r-- | script/core/diagnostics/circle-doc-class.lua | 1 | ||||
-rw-r--r-- | script/core/diagnostics/duplicate-doc-class.lua | 1 | ||||
-rw-r--r-- | script/core/diagnostics/duplicate-set-field.lua | 1 | ||||
-rw-r--r-- | script/core/diagnostics/no-implicit-any.lua | 4 | ||||
-rw-r--r-- | script/core/diagnostics/not-yieldable.lua | 2 | ||||
-rw-r--r-- | script/core/diagnostics/type-check.lua | 2 | ||||
-rw-r--r-- | script/core/highlight.lua | 1 | ||||
-rw-r--r-- | script/core/hint.lua | 4 | ||||
-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 | ||||
-rw-r--r-- | script/core/semantic-tokens.lua | 3 | ||||
-rw-r--r-- | script/core/signature.lua | 1 | ||||
-rw-r--r-- | script/core/type-definition.lua | 3 |
19 files changed, 89 insertions, 115 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index e2c978c6..e7633e7c 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1,7 +1,5 @@ -local sp = require 'bee.subprocess' local define = require 'proto.define' local files = require 'files' -local searcher = require 'core.searcher' local matchKey = require 'core.matchkey' local vm = require 'vm' local getName = require 'core.hover.name' @@ -18,7 +16,7 @@ local rpath = require 'workspace.require-path' local lang = require 'language' local lookBackward = require 'core.look-backward' local guide = require 'parser.guide' -local infer = require 'core.infer' +local infer = require 'vm.infer' local await = require 'await' local postfix = require 'core.completion.postfix' @@ -169,8 +167,8 @@ local function buildDetail(source) if source.type == 'dummy' then return end - local types = infer.searchAndViewInfers(source) - local literals = infer.searchAndViewLiterals(source) + local types = infer.viewType(source) + local literals = infer.viewLiterals(source) if literals then return types .. ' = ' .. literals else @@ -1821,14 +1819,14 @@ local function buildluaDocOfFunction(func) local returns = {} if func.args then for _, arg in ipairs(func.args) do - args[#args+1] = infer.searchAndViewInfers(arg) + args[#args+1] = infer.viewType(arg) end end if func.returns then for _, rtns in ipairs(func.returns) do for n = 1, #rtns do if not returns[n] then - returns[n] = infer.searchAndViewInfers(rtns[n]) + returns[n] = infer.viewType(rtns[n]) end end end diff --git a/script/core/diagnostics/circle-doc-class.lua b/script/core/diagnostics/circle-doc-class.lua index 61dc46b4..6bdad1be 100644 --- a/script/core/diagnostics/circle-doc-class.lua +++ b/script/core/diagnostics/circle-doc-class.lua @@ -1,5 +1,4 @@ local files = require 'files' -local searcher = require 'core.searcher' local lang = require 'language' local vm = require 'vm' local guide = require 'parser.guide' diff --git a/script/core/diagnostics/duplicate-doc-class.lua b/script/core/diagnostics/duplicate-doc-class.lua index 5114a54f..1a37826b 100644 --- a/script/core/diagnostics/duplicate-doc-class.lua +++ b/script/core/diagnostics/duplicate-doc-class.lua @@ -1,5 +1,4 @@ local files = require 'files' -local searcher = require 'core.searcher' local lang = require 'language' local vm = require 'vm' local guide = require 'parser.guide' diff --git a/script/core/diagnostics/duplicate-set-field.lua b/script/core/diagnostics/duplicate-set-field.lua index 492793b1..f8201309 100644 --- a/script/core/diagnostics/duplicate-set-field.lua +++ b/script/core/diagnostics/duplicate-set-field.lua @@ -1,5 +1,4 @@ local files = require 'files' -local searcher = require 'core.searcher' local lang = require 'language' local define = require 'proto.define' local guide = require "parser.guide" diff --git a/script/core/diagnostics/no-implicit-any.lua b/script/core/diagnostics/no-implicit-any.lua index 6ff17c81..47f1b997 100644 --- a/script/core/diagnostics/no-implicit-any.lua +++ b/script/core/diagnostics/no-implicit-any.lua @@ -1,7 +1,7 @@ local files = require 'files' local guide = require 'parser.guide' local lang = require 'language' -local infer = require 'core.infer' +local infer = require 'vm.infer' return function (uri, callback) local ast = files.getState(uri) @@ -20,7 +20,7 @@ return function (uri, callback) and source.type ~= 'tableindex' then return end - if infer.searchAndViewInfers(source) == 'any' then + if infer.viewType(source) == 'any' then callback { start = source.start, finish = source.finish, diff --git a/script/core/diagnostics/not-yieldable.lua b/script/core/diagnostics/not-yieldable.lua index 5736b1e2..706c83e0 100644 --- a/script/core/diagnostics/not-yieldable.lua +++ b/script/core/diagnostics/not-yieldable.lua @@ -3,7 +3,7 @@ local await = require 'await' local guide = require 'parser.guide' local vm = require 'vm' local lang = require 'language' -local infer = require 'core.infer' +local infer = require 'vm.infer' local function isYieldAble(defs, i) local hasFuncDef diff --git a/script/core/diagnostics/type-check.lua b/script/core/diagnostics/type-check.lua index 58574bfa..cbdb40a1 100644 --- a/script/core/diagnostics/type-check.lua +++ b/script/core/diagnostics/type-check.lua @@ -1,7 +1,7 @@ local files = require 'files' local guide = require 'parser.guide' local vm = require 'vm' -local infer = require 'core.infer' +local infer = require 'vm.infer' local await = require 'await' local hasVarargs, errType diff --git a/script/core/highlight.lua b/script/core/highlight.lua index 9db4b508..903c824c 100644 --- a/script/core/highlight.lua +++ b/script/core/highlight.lua @@ -1,4 +1,3 @@ -local searcher = require 'core.searcher' local files = require 'files' local vm = require 'vm' local define = require 'proto.define' diff --git a/script/core/hint.lua b/script/core/hint.lua index e6eb483c..3b5db3e5 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -1,5 +1,5 @@ local files = require 'files' -local infer = require 'core.infer' +local infer = require 'vm.infer' local vm = require 'vm' local config = require 'config' local guide = require 'parser.guide' @@ -41,7 +41,7 @@ local function typeHint(uri, results, start, finish) end end await.delay() - local view = infer.searchAndViewInfers(source) + local view = infer.viewType(source) if view == 'any' or view == 'nil' then return 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 diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index ef426633..f57246d3 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -1,12 +1,11 @@ local files = require 'files' -local searcher = require 'core.searcher' local await = require 'await' local define = require 'proto.define' local vm = require 'vm' local util = require 'utility' local guide = require 'parser.guide' local converter = require 'proto.converter' -local infer = require 'core.infer' +local infer = require 'vm.infer' local config = require 'config' local linkedTable = require 'linked-table' diff --git a/script/core/signature.lua b/script/core/signature.lua index d55866f5..e136bce9 100644 --- a/script/core/signature.lua +++ b/script/core/signature.lua @@ -1,5 +1,4 @@ local files = require 'files' -local searcher = require 'core.searcher' local vm = require 'vm' local hoverLabel = require 'core.hover.label' local hoverDesc = require 'core.hover.description' diff --git a/script/core/type-definition.lua b/script/core/type-definition.lua index c9053fab..6bee7193 100644 --- a/script/core/type-definition.lua +++ b/script/core/type-definition.lua @@ -1,10 +1,9 @@ -local searcher = require 'core.searcher' local workspace = require 'workspace' local files = require 'files' local vm = require 'vm' local findSource = require 'core.find-source' local guide = require 'parser.guide' -local infer = require 'core.infer' +local infer = require 'vm.infer' local rpath = require 'workspace.require-path' local function sortResults(results) |