diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-28 11:25:29 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-28 11:25:29 +0800 |
commit | eeb15fae07ac0d2ab4fcb8afd3a15516401034bd (patch) | |
tree | 62b3541bbcf656eb6abaf64372a62afb8ff0c2c2 /server | |
parent | ee2b29b81b19d1d2a3bc28805b177b15d59088a1 (diff) | |
download | lua-language-server-eeb15fae07ac0d2ab4fcb8afd3a15516401034bd.zip |
加个 x or 0 + 1 的诊断
Diffstat (limited to 'server')
-rw-r--r-- | server/locale/en-US/script.lni | 1 | ||||
-rw-r--r-- | server/locale/zh-CN/script.lni | 1 | ||||
-rw-r--r-- | server/src/core/diagnostics.lua | 22 |
3 files changed, 24 insertions, 0 deletions
diff --git a/server/locale/en-US/script.lni b/server/locale/en-US/script.lni index d706a304..c26230ad 100644 --- a/server/locale/en-US/script.lni +++ b/server/locale/en-US/script.lni @@ -7,6 +7,7 @@ DIAG_UNUSED_LABEL = 'Unused label `{}`.' DIAG_REDEFINED_LOCAL = 'Redefined local `{}`.' DIAG_PREVIOUS_CALL = 'Parsed as function call for the previous line. It may be necessary to add a `;` before.' DIAG_OVER_MAX_ARGS = 'The function takes only {:d} parameters, but you passed {:d}.' +DIAG_AMBIGUITY_1 = 'Compute `0 {op} {num}` first. You may need to add a bracket.' DIAG_DIAGNOSTICS = 'Diagnostics' DIAG_SYNTAX_CHECK = 'Syntax Check' diff --git a/server/locale/zh-CN/script.lni b/server/locale/zh-CN/script.lni index d54b4101..487b3cce 100644 --- a/server/locale/zh-CN/script.lni +++ b/server/locale/zh-CN/script.lni @@ -7,6 +7,7 @@ DIAG_UNUSED_LABEL = '未使用的标签 `{}`。' DIAG_REDEFINED_LOCAL = '重定义局部变量 `{}`。' DIAG_PREVIOUS_CALL = '解析为了上一行的函数调用。你可能需要在前面加一个 `;`。' DIAG_OVER_MAX_ARGS = '函数只接收 {:d} 个参数,但你传了 {:d} 个。' +DIAG_AMBIGUITY_1 = '会优先运算 `0 {op} {num}`,你可能需要加个括号。' DIAG_DIAGNOSTICS = '诊断' DIAG_SYNTAX_CHECK = '语法检查' diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index 241d70ba..c0c991bb 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -233,6 +233,21 @@ function mt:searchRedundantParameters(callback) end) end +function mt:searchAmbiguity1(callback) + self.vm:eachSource(function (source) + if source.op ~= 'or' then + return + end + local exp = source[2] + if exp.op ~= '+' and exp.op ~= '-' then + return + end + if exp[1][1] == 0 and exp[2].type == 'number' then + callback(source.start, source.finish, exp.op, exp[2][1]) + end + end) +end + function mt:doDiagnostics(func, code, callback) if config.config.diagnostics.disable[code] then return @@ -311,5 +326,12 @@ return function (vm, lines, uri) message = lang.script('DIAG_OVER_MAX_ARGS', max, passed), } end) + -- x or 0 + 1 + session:doDiagnostics(session.searchAmbiguity1, 'ambiguity-1', function (op, num) + return { + level = DiagnosticSeverity.Information, + message = lang.script('DIAG_AMBIGUITY_1', op, num), + } + end) return session.datas end |