diff options
Diffstat (limited to 'server-beta')
-rw-r--r-- | server-beta/src/core/diagnostics/init.lua | 2 | ||||
-rw-r--r-- | server-beta/src/core/diagnostics/redundant-value.lua | 24 | ||||
-rw-r--r-- | server-beta/src/parser/ast.lua | 25 | ||||
-rw-r--r-- | server-beta/src/parser/guide.lua | 3 | ||||
-rw-r--r-- | server-beta/src/parser/parse.lua | 8 | ||||
-rw-r--r-- | server-beta/test/diagnostics/init.lua | 6 |
6 files changed, 54 insertions, 14 deletions
diff --git a/server-beta/src/core/diagnostics/init.lua b/server-beta/src/core/diagnostics/init.lua index 69815003..8b6167cc 100644 --- a/server-beta/src/core/diagnostics/init.lua +++ b/server-beta/src/core/diagnostics/init.lua @@ -11,7 +11,7 @@ local function check(uri, name, level, results) result.level = level or result.level result.code = name results[#results+1] = result - end) + end, name) end return function (uri) diff --git a/server-beta/src/core/diagnostics/redundant-value.lua b/server-beta/src/core/diagnostics/redundant-value.lua index 71749f56..be483448 100644 --- a/server-beta/src/core/diagnostics/redundant-value.lua +++ b/server-beta/src/core/diagnostics/redundant-value.lua @@ -1,14 +1,24 @@ -local files = require 'files' -local guide = require 'parser.guide' +local files = require 'files' +local define = require 'proto.define' +local lang = require 'language' -local function check(source) - -end - -return function (uri, callback) +return function (uri, callback, code) local ast = files.getAst(uri) if not ast then return end + local diags = ast.diags[code] + if not diags then + return + end + + for _, info in ipairs(diags) do + callback { + start = info.start, + finish = info.finish, + tags = { define.DiagnosticTag.Unnecessary }, + message = lang.script('DIAG_OVER_MAX_VALUES', info.max, info.passed) + } + end end diff --git a/server-beta/src/parser/ast.lua b/server-beta/src/parser/ast.lua index 04148da0..953cac67 100644 --- a/server-beta/src/parser/ast.lua +++ b/server-beta/src/parser/ast.lua @@ -13,6 +13,7 @@ _ENV = nil local State local PushError +local PushDiag -- goto 单独处理 local RESERVED = { @@ -1025,6 +1026,17 @@ local Defs = { key.range = key.value.finish end end + if values then + for i = #keys+1, #values do + local value = values[i] + PushDiag('redundant-value', { + start = value.start, + finish = value.finish, + max = #keys, + passed = #values, + }) + end + end return tableUnpack(keys) end, LocalAttr = function (attrs) @@ -1079,6 +1091,17 @@ local Defs = { local value = getValue(values, i) createLocal(key, finish, value, attrs) end + if values then + for i = #keys+1, #values do + local value = values[i] + PushDiag('redundant-value', { + start = value.start, + finish = value.finish, + max = #keys, + passed = #values, + }) + end + end return tableUnpack(keys) end, Do = function (start, actions, finish) @@ -1619,12 +1642,14 @@ local Defs = { local function init(state) State = state PushError = state.pushError + PushDiag = state.pushDiag emmy.init(State) end local function close() State = nil PushError = nil + PushDiag = nil end return { diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index 952fa3c6..f4fd387c 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -320,6 +320,9 @@ function m.eachSourceType(ast, type, callback) end mark[source] = true local tp = source.type + if not tp then + return + end local myCache = cache[tp] if not myCache then myCache = {} diff --git a/server-beta/src/parser/parse.lua b/server-beta/src/parser/parse.lua index 0fd64e80..bbc01b10 100644 --- a/server-beta/src/parser/parse.lua +++ b/server-beta/src/parser/parse.lua @@ -2,12 +2,14 @@ local ast = require 'parser.ast' return function (self, lua, mode, version) local errs = {} + local diags = {} local state = { version = version, lua = lua, emmy = {}, root = {}, errs = errs, + diags = diags, pushError = function (err) if err.finish < err.start then err.finish = err.start @@ -22,6 +24,12 @@ return function (self, lua, mode, version) errs[#errs+1] = err return err end, + pushDiag = function (code, info) + if not diags[code] then + diags[code] = {} + end + diags[code][#diags[code]+1] = info + end } ast.init(state) local suc, res, err = xpcall(self.grammar, debug.traceback, self, lua, mode) diff --git a/server-beta/test/diagnostics/init.lua b/server-beta/test/diagnostics/init.lua index 430ead8d..6a5dc57f 100644 --- a/server-beta/test/diagnostics/init.lua +++ b/server-beta/test/diagnostics/init.lua @@ -588,12 +588,6 @@ t[1] = 1 --]] TEST [[ -local x <const> = 1 -<!x!> = 2 -return x -]] - -TEST [[ local x x = <!x or 0 + 1!> ]] |