diff options
Diffstat (limited to 'script/core/diagnostics')
-rw-r--r-- | script/core/diagnostics/count-down-loop.lua | 14 | ||||
-rw-r--r-- | script/core/diagnostics/deprecated.lua | 6 | ||||
-rw-r--r-- | script/core/diagnostics/duplicate-doc-field.lua | 6 | ||||
-rw-r--r-- | script/core/diagnostics/init.lua | 1 | ||||
-rw-r--r-- | script/core/diagnostics/newline-call.lua | 5 | ||||
-rw-r--r-- | script/core/diagnostics/type-check.lua | 56 | ||||
-rw-r--r-- | script/core/diagnostics/undefined-doc-class.lua | 2 | ||||
-rw-r--r-- | script/core/diagnostics/undefined-doc-param.lua | 3 | ||||
-rw-r--r-- | script/core/diagnostics/undefined-env-child.lua | 9 | ||||
-rw-r--r-- | script/core/diagnostics/undefined-field.lua | 6 |
10 files changed, 56 insertions, 52 deletions
diff --git a/script/core/diagnostics/count-down-loop.lua b/script/core/diagnostics/count-down-loop.lua index 49c48880..9bc4b273 100644 --- a/script/core/diagnostics/count-down-loop.lua +++ b/script/core/diagnostics/count-down-loop.lua @@ -20,28 +20,26 @@ return function (uri, callback) end if not source.step then callback { - start = source.init.start, - finish = source.max.finish, + start = source.init.start, + finish = source.max.finish, message = lang.script('DIAG_COUNT_DOWN_LOOP' , ('%s, %s'):format(text:sub( guide.positionToOffset(state, source.init.start), guide.positionToOffset(state, source.max.finish) - ) - , '-1') + ), '-1') ) } else local stepNumber = tonumber(source.step[1]) if stepNumber and stepNumber > 0 then callback { - start = source.init.start, - finish = source.step.finish, + start = source.init.start, + finish = source.step.finish, message = lang.script('DIAG_COUNT_DOWN_LOOP' , ('%s, -%s'):format(text:sub( guide.positionToOffset(state, source.init.start), guide.positionToOffset(state, source.max.finish) - ) - , source.step[1]) + ), source.step[1]) ) } end diff --git a/script/core/diagnostics/deprecated.lua b/script/core/diagnostics/deprecated.lua index 1c248646..649f4dab 100644 --- a/script/core/diagnostics/deprecated.lua +++ b/script/core/diagnostics/deprecated.lua @@ -83,7 +83,11 @@ return function (uri, callback) end table.sort(versions) if #versions > 0 then - message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(versions, '/'), config.get(uri, 'Lua.runtime.version'))) + message = ('%s(%s)'):format(message + , lang.script('DIAG_DEFINED_VERSION' + , table.concat(versions, '/') + , config.get(uri, 'Lua.runtime.version')) + ) end end cache[id] = { diff --git a/script/core/diagnostics/duplicate-doc-field.lua b/script/core/diagnostics/duplicate-doc-field.lua index ab3084c9..71610ef5 100644 --- a/script/core/diagnostics/duplicate-doc-field.lua +++ b/script/core/diagnostics/duplicate-doc-field.lua @@ -15,7 +15,7 @@ return function (uri, callback) local mark for _, group in ipairs(state.ast.docs.groups) do for _, doc in ipairs(group) do - if doc.type == 'doc.class' then + if doc.type == 'doc.class' then mark = {} elseif doc.type == 'doc.field' then if mark then @@ -26,8 +26,8 @@ return function (uri, callback) end if mark[name] then callback { - start = doc.field.start, - finish = doc.field.finish, + start = doc.field.start, + finish = doc.field.finish, message = lang.script('DIAG_DUPLICATE_DOC_FIELD', name), } end diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index 562b526d..4368f51a 100644 --- a/script/core/diagnostics/init.lua +++ b/script/core/diagnostics/init.lua @@ -82,6 +82,7 @@ local function check(uri, name, isScopeDiag, response) return end mark[result.start] = true + result.level = severity or result.level result.code = name response(result) diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua index dbb8c690..3f2d5ca5 100644 --- a/script/core/diagnostics/newline-call.lua +++ b/script/core/diagnostics/newline-call.lua @@ -37,7 +37,10 @@ return function (uri, callback) callback { start = node.start, finish = args.finish, - message = lang.script('DIAG_PREVIOUS_CALL', text:sub(node.start, node.finish), text:sub(args.start, args.finish)), + message = lang.script('DIAG_PREVIOUS_CALL' + , text:sub(node.start, node.finish) + , text:sub(args.start, args.finish) + ), } end end) diff --git a/script/core/diagnostics/type-check.lua b/script/core/diagnostics/type-check.lua index 5f37312e..58574bfa 100644 --- a/script/core/diagnostics/type-check.lua +++ b/script/core/diagnostics/type-check.lua @@ -51,10 +51,10 @@ local function isUserDefineClass(uri, name) end local function isClassOralias(typeName) - if not typeName then + if not typeName then return false elseif typeNameMap[typeName] - or vm.isBuiltinType(typeName) then + or vm.isBuiltinType(typeName) then return true else return false @@ -74,21 +74,21 @@ local function compatibleType(param, args) param[1] = string.sub(param.type, 10) end for _, v in ipairs(args) do - if v[1] == 'any' then + if v[1] == 'any' then return true elseif param[1] == v[1] then return true elseif (param[1] == 'number' or param[1] == 'integer') - and (v[1] == 'integer' or v[1] == 'number') then + and (v[1] == 'integer' or v[1] == 'number') then return true elseif v[1] == 'string' then ---处理alias --@alias searchmode '"ref"'|'"def"' - if param[1] and param[1]:sub(1,1) == '"' then + if param[1] and param[1]:sub(1, 1) == '"' then return true end elseif (isTable(v.type) or isTable(v[1])) - and (isTable(param[1]) or isTable(param.type)) then + and (isTable(param[1]) or isTable(param.type)) then return true end end @@ -140,8 +140,8 @@ local function getParamTypes(arg) return false end local types - ---处理doc.type.function - if arg.type == 'doc.type.arg' then + if arg.type == 'doc.type.arg' then + ---处理doc.type.function if arg.name and arg.name[1] == '...' then types = { [1] = { @@ -153,15 +153,15 @@ local function getParamTypes(arg) end types = arg.extends.types return true, types - ---处理function elseif arg.type == 'local' then + ---处理function local argDefs = vm.getDefs(arg) if #argDefs == 0 then return false end types = {} - ---method, 如果self没有定义为一个class或者type,则认为它为any if arg.tag == 'self' then + ---method, 如果self没有定义为一个class或者type,则认为它为any for _, argDef in ipairs(argDefs) do if argDef.type == 'doc.class.name' or argDef.type == 'doc.type.name' @@ -176,7 +176,7 @@ local function getParamTypes(arg) return true, types else for _, argDef in ipairs(argDefs) do - if argDef.type == 'doc.param' and argDef.extends then + if argDef.type == 'doc.param' and argDef.extends then types = argDef.extends.types if argDef.optional then types[#types+1] = { @@ -185,9 +185,9 @@ local function getParamTypes(arg) } end elseif argDef.type == 'doc.type.enum' - or argDef.type == 'doc.type.ltable' then + or argDef.type == 'doc.type.ltable' then types[#types+1] = argDef - ---变长参数 + ---变长参数 elseif argDef.name and argDef.name[1] == '...' then types = { [1] = { @@ -204,8 +204,8 @@ local function getParamTypes(arg) return true, types end end - ---处理只有一个可变参数 elseif arg.type == '...' then + ---处理只有一个可变参数 types = { [1] = { [1] = '...', @@ -235,7 +235,7 @@ local function getInfoFromDefs(defs) if suc then local plusAlias = {} for i, tp in ipairs(types) do - local aliasDefs = vm.getDefs(tp) + local aliasDefs = vm.getDefs(tp) for _, v in ipairs(aliasDefs) do ---TODO(arthur) -- if not v.type then @@ -376,32 +376,36 @@ local function matchParams(paramsTypes, i, arg) end flag = '' for _, param in ipairs(paramTypes[i]) do - if param[1] == '...' then + if param[1] == '...' then hasVarargs = true return true - ---如果形参的类型在实参里面 elseif compatibleType(param, arg) - or param[1] == 'any' then + or param[1] == 'any' then + ---如果形参的类型在实参里面 flag = '' return true - ---如果是泛型,不检查 elseif isGeneric(param) then + ---如果是泛型,不检查 return true else - ---TODO(arthur) 什么时候param[1]是nil? if param[1] and not errType[param[1]] then + ---TODO(arthur) 什么时候param[1]是nil? errType[param[1]] = true - flag = flag ..' ' .. (param[1] or '') + flag = flag .. ' ' .. (param[1] or '') end end end if flag ~= '' then local argm = '[ ' for _, v in ipairs(arg) do - argm = argm .. v[1]..' ' + argm = argm .. v[1] .. ' ' end argm = argm .. ']' - local message = 'Argument of type in '..argm..' is not assignable to parameter of type in ['..flag..' ]' + local message = 'Argument of type in ' + .. argm + .. ' is not assignable to parameter of type in [' + .. flag + .. ' ]' if not messages[message] then messages[message] = true messages[#messages+1] = message @@ -413,12 +417,12 @@ local function matchParams(paramsTypes, i, arg) end ---@async -return function (uri, callback) +return function(uri, callback) local ast = files.getState(uri) if not ast then return end - guide.eachSourceType(ast.ast, 'call', function (source) ---@async + guide.eachSourceType(ast.ast, 'call', function(source) ---@async if not source.args then return end @@ -444,7 +448,7 @@ return function (uri, callback) ---都不匹配 if not match then if #messages > 0 then - callback{ + callback { start = arg.start, finish = arg.finish, message = table.concat(messages, '\n') diff --git a/script/core/diagnostics/undefined-doc-class.lua b/script/core/diagnostics/undefined-doc-class.lua index 5f3902a2..715583e7 100644 --- a/script/core/diagnostics/undefined-doc-class.lua +++ b/script/core/diagnostics/undefined-doc-class.lua @@ -1,7 +1,5 @@ local files = require 'files' -local searcher = require 'core.searcher' local lang = require 'language' -local define = require 'proto.define' local vm = require 'vm' return function (uri, callback) diff --git a/script/core/diagnostics/undefined-doc-param.lua b/script/core/diagnostics/undefined-doc-param.lua index 86bf3871..98919284 100644 --- a/script/core/diagnostics/undefined-doc-param.lua +++ b/script/core/diagnostics/undefined-doc-param.lua @@ -1,8 +1,5 @@ local files = require 'files' -local searcher = require 'core.searcher' local lang = require 'language' -local define = require 'proto.define' -local vm = require 'vm' local function hasParamName(func, name) if not func.args then diff --git a/script/core/diagnostics/undefined-env-child.lua b/script/core/diagnostics/undefined-env-child.lua index 39c8de27..2f559697 100644 --- a/script/core/diagnostics/undefined-env-child.lua +++ b/script/core/diagnostics/undefined-env-child.lua @@ -1,8 +1,7 @@ -local files = require 'files' -local searcher = require 'core.searcher' -local guide = require 'parser.guide' -local lang = require 'language' -local vm = require "vm.vm" +local files = require 'files' +local guide = require 'parser.guide' +local lang = require 'language' +local vm = require "vm.vm" return function (uri, callback) local ast = files.getState(uri) diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua index 2e64f0cc..7d309096 100644 --- a/script/core/diagnostics/undefined-field.lua +++ b/script/core/diagnostics/undefined-field.lua @@ -5,7 +5,7 @@ local guide = require 'parser.guide' local noder = require 'core.noder' local await = require 'await' -local SkipCheckClass = { +local skipCheckClass = { ['unknown'] = true, ['any'] = true, ['table'] = true, @@ -49,7 +49,7 @@ return function (uri, callback) local ok for _, def in ipairs(defs) do if def.type == 'doc.class.name' - and not SkipCheckClass[def[1]] then + and not skipCheckClass[def[1]] then ok = true break end @@ -60,7 +60,7 @@ return function (uri, callback) end end local message = lang.script('DIAG_UNDEF_FIELD', guide.getKeyName(src)) - if src.type == 'getfield' and src.field then + if src.type == 'getfield' and src.field then callback { start = src.field.start, finish = src.field.finish, |