diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-03-15 18:03:34 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-03-15 18:03:34 +0800 |
commit | 2426bbe0758801ecfe4369d72f6755e9ef193cc5 (patch) | |
tree | 28fd3385b767b6eea451b1cbc95bce624ce9a879 | |
parent | 4e68872ea96a53f9c7ad5e11c83794b92f477fb4 (diff) | |
download | lua-language-server-2426bbe0758801ecfe4369d72f6755e9ef193cc5.zip |
diagnostic: improve `newline-call`
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | locale/en-us/script.lua | 4 | ||||
-rw-r--r-- | locale/zh-cn/script.lua | 4 | ||||
-rw-r--r-- | script/core/diagnostics/newline-call.lua | 11 | ||||
-rw-r--r-- | test/diagnostics/init.lua | 18 |
5 files changed, 22 insertions, 18 deletions
diff --git a/changelog.md b/changelog.md index 2feb8102..3cd97010 100644 --- a/changelog.md +++ b/changelog.md @@ -4,8 +4,9 @@ * `NEW` VSCode: new setting `Lua.misc.parameters` * `NEW` quick fix: disable diagnostic in line/file * `CHG` intelli-scense: search from generic param to return -* `CHG` improve performance * `CHG` text-document-synchronization: refactored +* `CHG` diagnostic: improve `newline-call` +* `CHG` improve performance * `FIX` missed syntax error `function m['x']() end` ## 1.18.1 diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index f39720e2..a1ec0e17 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -13,8 +13,8 @@ DIAG_UNUSED_VARARG = 'Unused vararg.' DIAG_REDEFINED_LOCAL = 'Redefined local `{}`.' DIAG_DUPLICATE_INDEX = 'Duplicate index `{}`.' DIAG_DUPLICATE_METHOD = 'Duplicate method `{}`.' -DIAG_PREVIOUS_CALL = 'Parsed as function call for the previous line. It may be necessary to add a `;` before.' -DIAG_PREFIELD_CALL = 'Parsed as `{} {}`. It may be necessary to add a `,` or `;` in the middle.' +DIAG_PREVIOUS_CALL = 'Will be interpreted as `{}{}`. It may be necessary to add a `,`.' +DIAG_PREFIELD_CALL = 'Will be interpreted as `{}{}`. It may be necessary to add a `,` or `;`.' DIAG_OVER_MAX_ARGS = 'The function takes only {:d} parameters, but you passed {:d}.' DIAG_OVER_MAX_ARGS = 'Only has {} variables, but you set {} values.' DIAG_AMBIGUITY_1 = 'Compute `{}` first. You may need to add brackets.' diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index 53149a6f..386d2cc5 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -13,8 +13,8 @@ DIAG_UNUSED_VARARG = '未使用的不定参数。' DIAG_REDEFINED_LOCAL = '重定义局部变量 `{}`。' DIAG_DUPLICATE_INDEX = '重复的索引 `{}`。' DIAG_DUPLICATE_METHOD = '重复的方法 `{}`。' -DIAG_PREVIOUS_CALL = '解析为了上一行的函数调用。你可能需要在前面加一个 `;`。' -DIAG_PREFIELD_CALL = '解析为了 `{} {}`。你可能需要在中间加一个`,`或`;`。' +DIAG_PREVIOUS_CALL = '会被解释为 `{}{}`。你可能需要加一个 `;`。' +DIAG_PREFIELD_CALL = '会被解释为 `{}{}`。你可能需要加一个`,`或`;`。' DIAG_OVER_MAX_ARGS = '函数只接收 {:d} 个参数,但你传了 {:d} 个。' DIAG_OVER_MAX_VALUES = '只有 {} 个变量,但你设置了 {} 个值。' DIAG_AMBIGUITY_1 = '会优先运算 `{}`,你可能需要加个括号。' diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua index c2c8bd66..807f76a2 100644 --- a/script/core/diagnostics/newline-call.lua +++ b/script/core/diagnostics/newline-call.lua @@ -3,8 +3,9 @@ local guide = require 'core.guide' local lang = require 'language' return function (uri, callback) - local ast = files.getAst(uri) + local ast = files.getAst(uri) local lines = files.getLines(uri) + local text = files.getText(uri) if not ast or not lines then return end @@ -20,6 +21,10 @@ return function (uri, callback) if not source.next then return end + if text:sub(args.start, args.start) ~= '(' + or text:sub(args.finish, args.finish) ~= ')' then + return + end local nodeRow = guide.positionOf(lines, node.finish) local argRow = guide.positionOf(lines, args.start) @@ -29,9 +34,9 @@ return function (uri, callback) if #args == 1 then callback { - start = args.start, + start = node.start, finish = args.finish, - message = lang.script.DIAG_PREVIOUS_CALL, + message = lang.script('DIAG_PREVIOUS_CALL', text:sub(node.start, node.finish), text:sub(args.start, args.finish)), } end end) diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index 6f250543..e8cc76e4 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -230,8 +230,8 @@ _ENV = nil config.config.diagnostics.disable['undefined-env-child'] = nil TEST [[ -print() -<!('string')!>:sub(1, 1) +<!print() +('string')!>:sub(1, 1) ]] TEST [[ @@ -240,6 +240,12 @@ print() ]] TEST [[ +pairs +{} +{} +]] + +TEST [[ local x return x : f(1) @@ -357,14 +363,6 @@ TEST [[ <!local function f() end!> ]] ---TEST [[ ---F = <!function () end!> ---]] --- ---TEST [[ ---<!function F() end!> ---]] - config.config.diagnostics.disable['unused-local'] = nil TEST [[ local mt, x |