diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-06 23:21:28 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-06 23:21:28 +0800 |
commit | 27dcfa8d1463936d0b2514cd82eebe1910ab3bb7 (patch) | |
tree | e0420120917c4938e6198e965e0dc146fc9e3835 | |
parent | 5ec199aa6c9119cac7a4e53694eaa7f9273bc58a (diff) | |
download | lua-language-server-27dcfa8d1463936d0b2514cd82eebe1910ab3bb7.zip |
completion and diags for operator
-rw-r--r-- | doc/en-us/config.md | 35 | ||||
-rw-r--r-- | doc/pt-br/config.md | 35 | ||||
-rw-r--r-- | doc/zh-cn/config.md | 35 | ||||
-rw-r--r-- | doc/zh-tw/config.md | 35 | ||||
-rw-r--r-- | locale/en-us/script.lua | 2 | ||||
-rw-r--r-- | locale/pt-br/script.lua | 2 | ||||
-rw-r--r-- | locale/zh-cn/script.lua | 2 | ||||
-rw-r--r-- | locale/zh-tw/script.lua | 2 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 30 | ||||
-rw-r--r-- | script/core/diagnostics/unknown-operator.lua | 34 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 4 | ||||
-rw-r--r-- | script/proto/diagnostic.lua | 1 | ||||
-rw-r--r-- | test/diagnostics/common.lua | 5 |
13 files changed, 158 insertions, 64 deletions
diff --git a/doc/en-us/config.md b/doc/en-us/config.md index 7368d7c0..038cf920 100644 --- a/doc/en-us/config.md +++ b/doc/en-us/config.md @@ -207,10 +207,10 @@ Array<string> * ``"undefined-doc-param"`` * ``"param-type-mismatch"`` * ``"global-in-nil-env"`` -* ``"missing-parameter"`` +* ``"unused-vararg"`` * ``"miss-sep-in-table"`` * ``"unknown-cast-variable"`` -* ``"miss-loop-min"`` +* ``"unknown-operator"`` * ``"malformed-number"`` * ``"err-do-as-then"`` * ``"spell-check"`` @@ -223,6 +223,7 @@ Array<string> * ``"duplicate-doc-alias"`` * ``"doc-field-no-class"`` * ``"no-visible-label"`` +* ``"miss-loop-min"`` * ``"miss-exp"`` * ``"miss-loop-max"`` * ``"miss-name"`` @@ -239,43 +240,43 @@ Array<string> * ``"unused-label"`` * ``"action-after-return"`` * ``"unexpect-dots"`` -* ``"newline-call"`` +* ``"redundant-return-value"`` * ``"jump-local-scope"`` * ``"close-non-object"`` * ``"miss-field"`` * ``"count-down-loop"`` * ``"cast-type-mismatch"`` -* ``"duplicate-index"`` +* ``"newline-call"`` * ``"unexpect-symbol"`` * ``"block-after-else"`` * ``"unicode-name"`` * ``"miss-exponent"`` * ``"err-esc"`` -* ``"redundant-return-value"`` -* ``"unbalanced-assignments"`` +* ``"local-limit"`` +* ``"trailing-space"`` * ``"err-c-long-comment"`` +* ``"undefined-global"`` * ``"undefined-doc-name"`` * ``"ambiguity-1"`` -* ``"trailing-space"`` * ``"deprecated"`` * ``"codestyle-check"`` * ``"missing-return"`` -* ``"undefined-global"`` +* ``"missing-parameter"`` * ``"unused-function"`` -* ``"code-after-break"`` -* ``"assign-type-mismatch"`` -* ``"local-limit"`` * ``"cast-local-type"`` +* ``"assign-type-mismatch"`` +* ``"duplicate-set-field"`` +* ``"no-unknown"`` * ``"need-check-nil"`` * ``"keyword"`` * ``"unknown-diag-code"`` -* ``"unused-vararg"`` +* ``"return-type-mismatch"`` * ``"err-comment-prefix"`` * ``"lowercase-global"`` -* ``"return-type-mismatch"`` -* ``"duplicate-set-field"`` +* ``"unbalanced-assignments"`` * ``"redefined-local"`` -* ``"no-unknown"`` +* ``"code-after-break"`` +* ``"duplicate-index"`` * ``"duplicate-doc-param"`` * ``"index-in-func-name"`` * ``"miss-symbol"`` @@ -407,6 +408,7 @@ object<string, string> * undefined-doc-param * unknown-cast-variable * unknown-diag-code + * unknown-operator */ "luadoc": "Fallback", /* @@ -524,6 +526,7 @@ object<string, string> * undefined-doc-param * unknown-cast-variable * unknown-diag-code + * unknown-operator */ "luadoc": "Fallback", /* @@ -733,6 +736,7 @@ object<string, string> "undefined-global": "Any", "unknown-cast-variable": "Any", "unknown-diag-code": "Any", + "unknown-operator": "Any", /* Enable unused function diagnostics. */ @@ -867,6 +871,7 @@ object<string, string> "undefined-global": "Warning", "unknown-cast-variable": "Warning", "unknown-diag-code": "Warning", + "unknown-operator": "Warning", /* Enable unused function diagnostics. */ diff --git a/doc/pt-br/config.md b/doc/pt-br/config.md index f35df002..479a6add 100644 --- a/doc/pt-br/config.md +++ b/doc/pt-br/config.md @@ -207,10 +207,10 @@ Array<string> * ``"undefined-doc-param"`` * ``"param-type-mismatch"`` * ``"global-in-nil-env"`` -* ``"missing-parameter"`` +* ``"unused-vararg"`` * ``"miss-sep-in-table"`` * ``"unknown-cast-variable"`` -* ``"miss-loop-min"`` +* ``"unknown-operator"`` * ``"malformed-number"`` * ``"err-do-as-then"`` * ``"spell-check"`` @@ -223,6 +223,7 @@ Array<string> * ``"duplicate-doc-alias"`` * ``"doc-field-no-class"`` * ``"no-visible-label"`` +* ``"miss-loop-min"`` * ``"miss-exp"`` * ``"miss-loop-max"`` * ``"miss-name"`` @@ -239,43 +240,43 @@ Array<string> * ``"unused-label"`` * ``"action-after-return"`` * ``"unexpect-dots"`` -* ``"newline-call"`` +* ``"redundant-return-value"`` * ``"jump-local-scope"`` * ``"close-non-object"`` * ``"miss-field"`` * ``"count-down-loop"`` * ``"cast-type-mismatch"`` -* ``"duplicate-index"`` +* ``"newline-call"`` * ``"unexpect-symbol"`` * ``"block-after-else"`` * ``"unicode-name"`` * ``"miss-exponent"`` * ``"err-esc"`` -* ``"redundant-return-value"`` -* ``"unbalanced-assignments"`` +* ``"local-limit"`` +* ``"trailing-space"`` * ``"err-c-long-comment"`` +* ``"undefined-global"`` * ``"undefined-doc-name"`` * ``"ambiguity-1"`` -* ``"trailing-space"`` * ``"deprecated"`` * ``"codestyle-check"`` * ``"missing-return"`` -* ``"undefined-global"`` +* ``"missing-parameter"`` * ``"unused-function"`` -* ``"code-after-break"`` -* ``"assign-type-mismatch"`` -* ``"local-limit"`` * ``"cast-local-type"`` +* ``"assign-type-mismatch"`` +* ``"duplicate-set-field"`` +* ``"no-unknown"`` * ``"need-check-nil"`` * ``"keyword"`` * ``"unknown-diag-code"`` -* ``"unused-vararg"`` +* ``"return-type-mismatch"`` * ``"err-comment-prefix"`` * ``"lowercase-global"`` -* ``"return-type-mismatch"`` -* ``"duplicate-set-field"`` +* ``"unbalanced-assignments"`` * ``"redefined-local"`` -* ``"no-unknown"`` +* ``"code-after-break"`` +* ``"duplicate-index"`` * ``"duplicate-doc-param"`` * ``"index-in-func-name"`` * ``"miss-symbol"`` @@ -407,6 +408,7 @@ object<string, string> * undefined-doc-param * unknown-cast-variable * unknown-diag-code + * unknown-operator */ "luadoc": "Fallback", /* @@ -524,6 +526,7 @@ object<string, string> * undefined-doc-param * unknown-cast-variable * unknown-diag-code + * unknown-operator */ "luadoc": "Fallback", /* @@ -733,6 +736,7 @@ object<string, string> "undefined-global": "Any", "unknown-cast-variable": "Any", "unknown-diag-code": "Any", + "unknown-operator": "Any", /* 未使用的函数 */ @@ -867,6 +871,7 @@ object<string, string> "undefined-global": "Warning", "unknown-cast-variable": "Warning", "unknown-diag-code": "Warning", + "unknown-operator": "Warning", /* 未使用的函数 */ diff --git a/doc/zh-cn/config.md b/doc/zh-cn/config.md index 4f326649..a315b168 100644 --- a/doc/zh-cn/config.md +++ b/doc/zh-cn/config.md @@ -207,10 +207,10 @@ Array<string> * ``"undefined-doc-param"`` * ``"param-type-mismatch"`` * ``"global-in-nil-env"`` -* ``"missing-parameter"`` +* ``"unused-vararg"`` * ``"miss-sep-in-table"`` * ``"unknown-cast-variable"`` -* ``"miss-loop-min"`` +* ``"unknown-operator"`` * ``"malformed-number"`` * ``"err-do-as-then"`` * ``"spell-check"`` @@ -223,6 +223,7 @@ Array<string> * ``"duplicate-doc-alias"`` * ``"doc-field-no-class"`` * ``"no-visible-label"`` +* ``"miss-loop-min"`` * ``"miss-exp"`` * ``"miss-loop-max"`` * ``"miss-name"`` @@ -239,43 +240,43 @@ Array<string> * ``"unused-label"`` * ``"action-after-return"`` * ``"unexpect-dots"`` -* ``"newline-call"`` +* ``"redundant-return-value"`` * ``"jump-local-scope"`` * ``"close-non-object"`` * ``"miss-field"`` * ``"count-down-loop"`` * ``"cast-type-mismatch"`` -* ``"duplicate-index"`` +* ``"newline-call"`` * ``"unexpect-symbol"`` * ``"block-after-else"`` * ``"unicode-name"`` * ``"miss-exponent"`` * ``"err-esc"`` -* ``"redundant-return-value"`` -* ``"unbalanced-assignments"`` +* ``"local-limit"`` +* ``"trailing-space"`` * ``"err-c-long-comment"`` +* ``"undefined-global"`` * ``"undefined-doc-name"`` * ``"ambiguity-1"`` -* ``"trailing-space"`` * ``"deprecated"`` * ``"codestyle-check"`` * ``"missing-return"`` -* ``"undefined-global"`` +* ``"missing-parameter"`` * ``"unused-function"`` -* ``"code-after-break"`` -* ``"assign-type-mismatch"`` -* ``"local-limit"`` * ``"cast-local-type"`` +* ``"assign-type-mismatch"`` +* ``"duplicate-set-field"`` +* ``"no-unknown"`` * ``"need-check-nil"`` * ``"keyword"`` * ``"unknown-diag-code"`` -* ``"unused-vararg"`` +* ``"return-type-mismatch"`` * ``"err-comment-prefix"`` * ``"lowercase-global"`` -* ``"return-type-mismatch"`` -* ``"duplicate-set-field"`` +* ``"unbalanced-assignments"`` * ``"redefined-local"`` -* ``"no-unknown"`` +* ``"code-after-break"`` +* ``"duplicate-index"`` * ``"duplicate-doc-param"`` * ``"index-in-func-name"`` * ``"miss-symbol"`` @@ -407,6 +408,7 @@ object<string, string> * undefined-doc-param * unknown-cast-variable * unknown-diag-code + * unknown-operator */ "luadoc": "Fallback", /* @@ -524,6 +526,7 @@ object<string, string> * undefined-doc-param * unknown-cast-variable * unknown-diag-code + * unknown-operator */ "luadoc": "Fallback", /* @@ -733,6 +736,7 @@ object<string, string> "undefined-global": "Any", "unknown-cast-variable": "Any", "unknown-diag-code": "Any", + "unknown-operator": "Any", /* 未使用的函数 */ @@ -866,6 +870,7 @@ object<string, string> "undefined-global": "Warning", "unknown-cast-variable": "Warning", "unknown-diag-code": "Warning", + "unknown-operator": "Warning", /* 未使用的函数 */ diff --git a/doc/zh-tw/config.md b/doc/zh-tw/config.md index 4cf0dd01..3fff6c6d 100644 --- a/doc/zh-tw/config.md +++ b/doc/zh-tw/config.md @@ -207,10 +207,10 @@ Array<string> * ``"undefined-doc-param"`` * ``"param-type-mismatch"`` * ``"global-in-nil-env"`` -* ``"missing-parameter"`` +* ``"unused-vararg"`` * ``"miss-sep-in-table"`` * ``"unknown-cast-variable"`` -* ``"miss-loop-min"`` +* ``"unknown-operator"`` * ``"malformed-number"`` * ``"err-do-as-then"`` * ``"spell-check"`` @@ -223,6 +223,7 @@ Array<string> * ``"duplicate-doc-alias"`` * ``"doc-field-no-class"`` * ``"no-visible-label"`` +* ``"miss-loop-min"`` * ``"miss-exp"`` * ``"miss-loop-max"`` * ``"miss-name"`` @@ -239,43 +240,43 @@ Array<string> * ``"unused-label"`` * ``"action-after-return"`` * ``"unexpect-dots"`` -* ``"newline-call"`` +* ``"redundant-return-value"`` * ``"jump-local-scope"`` * ``"close-non-object"`` * ``"miss-field"`` * ``"count-down-loop"`` * ``"cast-type-mismatch"`` -* ``"duplicate-index"`` +* ``"newline-call"`` * ``"unexpect-symbol"`` * ``"block-after-else"`` * ``"unicode-name"`` * ``"miss-exponent"`` * ``"err-esc"`` -* ``"redundant-return-value"`` -* ``"unbalanced-assignments"`` +* ``"local-limit"`` +* ``"trailing-space"`` * ``"err-c-long-comment"`` +* ``"undefined-global"`` * ``"undefined-doc-name"`` * ``"ambiguity-1"`` -* ``"trailing-space"`` * ``"deprecated"`` * ``"codestyle-check"`` * ``"missing-return"`` -* ``"undefined-global"`` +* ``"missing-parameter"`` * ``"unused-function"`` -* ``"code-after-break"`` -* ``"assign-type-mismatch"`` -* ``"local-limit"`` * ``"cast-local-type"`` +* ``"assign-type-mismatch"`` +* ``"duplicate-set-field"`` +* ``"no-unknown"`` * ``"need-check-nil"`` * ``"keyword"`` * ``"unknown-diag-code"`` -* ``"unused-vararg"`` +* ``"return-type-mismatch"`` * ``"err-comment-prefix"`` * ``"lowercase-global"`` -* ``"return-type-mismatch"`` -* ``"duplicate-set-field"`` +* ``"unbalanced-assignments"`` * ``"redefined-local"`` -* ``"no-unknown"`` +* ``"code-after-break"`` +* ``"duplicate-index"`` * ``"duplicate-doc-param"`` * ``"index-in-func-name"`` * ``"miss-symbol"`` @@ -407,6 +408,7 @@ object<string, string> * undefined-doc-param * unknown-cast-variable * unknown-diag-code + * unknown-operator */ "luadoc": "Fallback", /* @@ -524,6 +526,7 @@ object<string, string> * undefined-doc-param * unknown-cast-variable * unknown-diag-code + * unknown-operator */ "luadoc": "Fallback", /* @@ -733,6 +736,7 @@ object<string, string> "undefined-global": "Any", "unknown-cast-variable": "Any", "unknown-diag-code": "Any", + "unknown-operator": "Any", /* 未使用的函式 */ @@ -866,6 +870,7 @@ object<string, string> "undefined-global": "Warning", "unknown-cast-variable": "Warning", "unknown-diag-code": "Warning", + "unknown-operator": "Warning", /* 未使用的函式 */ diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index b1ef9545..c46c83c8 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -140,6 +140,8 @@ DIAG_MISSING_RETURN = 'Return value is required here.' DIAG_RETURN_TYPE_MISMATCH = 'The type of the {index} return value is `{def}`, but the actual return is `{ref}`.' +DIAG_UNKNOWN_OPERATOR = +'Unknown operator `{}`.' MWS_NOT_SUPPORT = '{} does not support multi workspace for now, I may need to restart to support the new workspace ...' diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua index 05e208e7..908ba8cc 100644 --- a/locale/pt-br/script.lua +++ b/locale/pt-br/script.lua @@ -140,6 +140,8 @@ DIAG_MISSING_RETURN = -- TODO: need translate! 'Return value is required here.' DIAG_RETURN_TYPE_MISMATCH = -- TODO: need translate! 'The type of the {index} return value is `{def}`, but the actual return is `{ref}`.' +DIAG_UNKNOWN_OPERATOR = -- TODO: need translate! +'Unknown operator `{}`.' MWS_NOT_SUPPORT = '{} não é suportado múltiplos espaços de trabalho por enquanto, posso precisar reiniciar para estabelecer um novo espaço de trabalho ...' diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index b1567f68..02596c04 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -140,6 +140,8 @@ DIAG_MISSING_RETURN = '此处需要返回值。' DIAG_RETURN_TYPE_MISMATCH = '第 {index} 个返回值的类型为 `{def}` ,但实际返回的是 `{ref}`。' +DIAG_UNKNOWN_OPERATOR = +'未知的运算符 `{}`。' MWS_NOT_SUPPORT = '{} 目前还不支持多工作目录,我可能需要重启才能支持新的工作目录...' diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua index da026422..7cf5134d 100644 --- a/locale/zh-tw/script.lua +++ b/locale/zh-tw/script.lua @@ -140,6 +140,8 @@ DIAG_MISSING_RETURN = '此處需要回傳值。' DIAG_RETURN_TYPE_MISMATCH = '第 {index} 個回傳值的類型為 `{def}` ,但實際回傳的是 `{ref}`。' +DIAG_UNKNOWN_OPERATOR = -- TODO: need translate! +'Unknown operator `{}`.' MWS_NOT_SUPPORT = '{} 目前還不支援多工作目錄,我可能需要重新啟動才能支援新的工作目錄...' diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index 69488e36..ae1d7f9e 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1736,6 +1736,23 @@ local function tryluaDocBySource(state, position, source, results) end end return true + elseif source.type == 'doc.operator.name' then + for _, name in ipairs(vm.UNARY_OP) do + if matchKey(source[1], name) then + results[#results+1] = { + label = name, + kind = define.CompletionItemKind.Operator, + } + end + end + for _, name in ipairs(vm.BINARY_OP) do + if matchKey(source[1], name) then + results[#results+1] = { + label = name, + kind = define.CompletionItemKind.Operator, + } + end + end end return false end @@ -1846,6 +1863,19 @@ local function tryluaDocByErr(state, position, err, docState, results) } end end + elseif err.type == 'LUADOC_MISS_OPERATOR_NAME' then + for _, name in ipairs(vm.UNARY_OP) do + results[#results+1] = { + label = name, + kind = define.CompletionItemKind.Operator, + } + end + for _, name in ipairs(vm.BINARY_OP) do + results[#results+1] = { + label = name, + kind = define.CompletionItemKind.Operator, + } + end end end diff --git a/script/core/diagnostics/unknown-operator.lua b/script/core/diagnostics/unknown-operator.lua new file mode 100644 index 00000000..29a86eaa --- /dev/null +++ b/script/core/diagnostics/unknown-operator.lua @@ -0,0 +1,34 @@ +local files = require 'files' +local guide = require 'parser.guide' +local lang = require 'language' +local vm = require 'vm' +local await = require 'await' +local util = require 'utility' + +---@async +return function (uri, callback) + local state = files.getState(uri) + if not state then + return + end + + if not state.ast.docs then + return + end + + for _, doc in ipairs(state.ast.docs) do + if doc.type == 'doc.operator' then + local op = doc.op + if op then + if not util.arrayHas(vm.UNARY_OP, op[1]) + and not util.arrayHas(vm.BINARY_OP, op[1]) then + callback { + start = doc.op.start, + finish = doc.op.finish, + message = lang.script('DIAG_UNKNOWN_OPERATOR', op[1]) + } + end + end + end + end +end diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 2237b232..13c34d16 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -148,10 +148,6 @@ Symbol <- ({} { ---@field versions? table[] ---@field names? parser.object[] -local function trim(str) - return str:match '^%s*(%S+)%s*$' -end - local function parseTokens(text, offset) Ci = 0 Offset = offset diff --git a/script/proto/diagnostic.lua b/script/proto/diagnostic.lua index e5f74ef5..d8312dfe 100644 --- a/script/proto/diagnostic.lua +++ b/script/proto/diagnostic.lua @@ -93,6 +93,7 @@ m.register { 'unknown-diag-code', 'unknown-cast-variable', 'cast-type-mismatch', + 'unknown-operator', } { group = 'luadoc', severity = 'Warning', diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index 9ee572cb..27e92676 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -1902,3 +1902,8 @@ end ]] util.arrayRemove(disables, 'redundant-return') + +TEST [[ +---@class A +---@operator <!xxx!>: A +]] |