summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-05 19:47:15 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-05 19:47:15 +0800
commit2ab618716a33378449aa4938864db632a141719e (patch)
tree56b141d4b3439b5136d988908fc08b2b5838146e
parent671c7089a1697ee8f6fc108a9568b0509e1aa933 (diff)
downloadlua-language-server-2ab618716a33378449aa4938864db632a141719e.zip
resolve #1254 can suppress syntax errors
-rw-r--r--changelog.md1
-rw-r--r--doc/en-us/config.md96
-rw-r--r--doc/pt-br/config.md96
-rw-r--r--doc/zh-cn/config.md96
-rw-r--r--doc/zh-tw/config.md96
-rw-r--r--script/config/template.lua3
-rw-r--r--script/core/completion/completion.lua3
-rw-r--r--script/core/diagnostics/unknown-diag-code.lua4
-rw-r--r--script/proto/diagnostic.lua27
-rw-r--r--script/provider/diagnostic.lua5
-rw-r--r--script/vm/doc.lua6
11 files changed, 426 insertions, 7 deletions
diff --git a/changelog.md b/changelog.md
index 27448c47..b27a26fe 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,7 @@
# changelog
## 3.5.0
+* `CHG` `---@diagnostic disable: <ERR_NAME>` can suppress syntax errors
* `FIX` [#1278](https://github.com/sumneko/lua-language-server/issues/1278)
## 3.4.1
diff --git a/doc/en-us/config.md b/doc/en-us/config.md
index 6ab5a012..7368d7c0 100644
--- a/doc/en-us/config.md
+++ b/doc/en-us/config.md
@@ -186,6 +186,102 @@ Disabled diagnostic (Use code in hover brackets).
Array<string>
```
+## enum
+
+* ``"not-yieldable"``
+* ``"redundant-parameter"``
+* ``"break-outside"``
+* ``"undefined-doc-class"``
+* ``"unknown-symbol"``
+* ``"miss-method"``
+* ``"err-nonstandard-symbol"``
+* ``"unknown-attribute"``
+* ``"unexpect-efunc-name"``
+* ``"different-requires"``
+* ``"miss-end"``
+* ``"await-in-sync"``
+* ``"args-after-dots"``
+* ``"err-eq-as-assign"``
+* ``"newfield-call"``
+* ``"err-assign-as-eq"``
+* ``"undefined-doc-param"``
+* ``"param-type-mismatch"``
+* ``"global-in-nil-env"``
+* ``"missing-parameter"``
+* ``"miss-sep-in-table"``
+* ``"unknown-cast-variable"``
+* ``"miss-loop-min"``
+* ``"malformed-number"``
+* ``"err-do-as-then"``
+* ``"spell-check"``
+* ``"undefined-env-child"``
+* ``"missing-return-value"``
+* ``"discard-returns"``
+* ``"redundant-return"``
+* ``"miss-esc-x"``
+* ``"redundant-value"``
+* ``"duplicate-doc-alias"``
+* ``"doc-field-no-class"``
+* ``"no-visible-label"``
+* ``"miss-exp"``
+* ``"miss-loop-max"``
+* ``"miss-name"``
+* ``"empty-block"``
+* ``"unused-local"``
+* ``"err-then-as-do"``
+* ``"duplicate-doc-field"``
+* ``"redefined-label"``
+* ``"exp-in-action"``
+* ``"set-const"``
+* ``"circle-doc-class"``
+* ``"unexpect-lfunc-name"``
+* ``"unsupport-symbol"``
+* ``"unused-label"``
+* ``"action-after-return"``
+* ``"unexpect-dots"``
+* ``"newline-call"``
+* ``"jump-local-scope"``
+* ``"close-non-object"``
+* ``"miss-field"``
+* ``"count-down-loop"``
+* ``"cast-type-mismatch"``
+* ``"duplicate-index"``
+* ``"unexpect-symbol"``
+* ``"block-after-else"``
+* ``"unicode-name"``
+* ``"miss-exponent"``
+* ``"err-esc"``
+* ``"redundant-return-value"``
+* ``"unbalanced-assignments"``
+* ``"err-c-long-comment"``
+* ``"undefined-doc-name"``
+* ``"ambiguity-1"``
+* ``"trailing-space"``
+* ``"deprecated"``
+* ``"codestyle-check"``
+* ``"missing-return"``
+* ``"undefined-global"``
+* ``"unused-function"``
+* ``"code-after-break"``
+* ``"assign-type-mismatch"``
+* ``"local-limit"``
+* ``"cast-local-type"``
+* ``"need-check-nil"``
+* ``"keyword"``
+* ``"unknown-diag-code"``
+* ``"unused-vararg"``
+* ``"err-comment-prefix"``
+* ``"lowercase-global"``
+* ``"return-type-mismatch"``
+* ``"duplicate-set-field"``
+* ``"redefined-local"``
+* ``"no-unknown"``
+* ``"duplicate-doc-param"``
+* ``"index-in-func-name"``
+* ``"miss-symbol"``
+* ``"undefined-field"``
+* ``"miss-space-between"``
+
## default
```jsonc
diff --git a/doc/pt-br/config.md b/doc/pt-br/config.md
index dfe69559..f35df002 100644
--- a/doc/pt-br/config.md
+++ b/doc/pt-br/config.md
@@ -186,6 +186,102 @@ Disabled diagnostic (Use code in hover brackets).
Array<string>
```
+## enum
+
+* ``"not-yieldable"``
+* ``"redundant-parameter"``
+* ``"break-outside"``
+* ``"undefined-doc-class"``
+* ``"unknown-symbol"``
+* ``"miss-method"``
+* ``"err-nonstandard-symbol"``
+* ``"unknown-attribute"``
+* ``"unexpect-efunc-name"``
+* ``"different-requires"``
+* ``"miss-end"``
+* ``"await-in-sync"``
+* ``"args-after-dots"``
+* ``"err-eq-as-assign"``
+* ``"newfield-call"``
+* ``"err-assign-as-eq"``
+* ``"undefined-doc-param"``
+* ``"param-type-mismatch"``
+* ``"global-in-nil-env"``
+* ``"missing-parameter"``
+* ``"miss-sep-in-table"``
+* ``"unknown-cast-variable"``
+* ``"miss-loop-min"``
+* ``"malformed-number"``
+* ``"err-do-as-then"``
+* ``"spell-check"``
+* ``"undefined-env-child"``
+* ``"missing-return-value"``
+* ``"discard-returns"``
+* ``"redundant-return"``
+* ``"miss-esc-x"``
+* ``"redundant-value"``
+* ``"duplicate-doc-alias"``
+* ``"doc-field-no-class"``
+* ``"no-visible-label"``
+* ``"miss-exp"``
+* ``"miss-loop-max"``
+* ``"miss-name"``
+* ``"empty-block"``
+* ``"unused-local"``
+* ``"err-then-as-do"``
+* ``"duplicate-doc-field"``
+* ``"redefined-label"``
+* ``"exp-in-action"``
+* ``"set-const"``
+* ``"circle-doc-class"``
+* ``"unexpect-lfunc-name"``
+* ``"unsupport-symbol"``
+* ``"unused-label"``
+* ``"action-after-return"``
+* ``"unexpect-dots"``
+* ``"newline-call"``
+* ``"jump-local-scope"``
+* ``"close-non-object"``
+* ``"miss-field"``
+* ``"count-down-loop"``
+* ``"cast-type-mismatch"``
+* ``"duplicate-index"``
+* ``"unexpect-symbol"``
+* ``"block-after-else"``
+* ``"unicode-name"``
+* ``"miss-exponent"``
+* ``"err-esc"``
+* ``"redundant-return-value"``
+* ``"unbalanced-assignments"``
+* ``"err-c-long-comment"``
+* ``"undefined-doc-name"``
+* ``"ambiguity-1"``
+* ``"trailing-space"``
+* ``"deprecated"``
+* ``"codestyle-check"``
+* ``"missing-return"``
+* ``"undefined-global"``
+* ``"unused-function"``
+* ``"code-after-break"``
+* ``"assign-type-mismatch"``
+* ``"local-limit"``
+* ``"cast-local-type"``
+* ``"need-check-nil"``
+* ``"keyword"``
+* ``"unknown-diag-code"``
+* ``"unused-vararg"``
+* ``"err-comment-prefix"``
+* ``"lowercase-global"``
+* ``"return-type-mismatch"``
+* ``"duplicate-set-field"``
+* ``"redefined-local"``
+* ``"no-unknown"``
+* ``"duplicate-doc-param"``
+* ``"index-in-func-name"``
+* ``"miss-symbol"``
+* ``"undefined-field"``
+* ``"miss-space-between"``
+
## default
```jsonc
diff --git a/doc/zh-cn/config.md b/doc/zh-cn/config.md
index d66bc17d..4f326649 100644
--- a/doc/zh-cn/config.md
+++ b/doc/zh-cn/config.md
@@ -186,6 +186,102 @@ true
Array<string>
```
+## enum
+
+* ``"not-yieldable"``
+* ``"redundant-parameter"``
+* ``"break-outside"``
+* ``"undefined-doc-class"``
+* ``"unknown-symbol"``
+* ``"miss-method"``
+* ``"err-nonstandard-symbol"``
+* ``"unknown-attribute"``
+* ``"unexpect-efunc-name"``
+* ``"different-requires"``
+* ``"miss-end"``
+* ``"await-in-sync"``
+* ``"args-after-dots"``
+* ``"err-eq-as-assign"``
+* ``"newfield-call"``
+* ``"err-assign-as-eq"``
+* ``"undefined-doc-param"``
+* ``"param-type-mismatch"``
+* ``"global-in-nil-env"``
+* ``"missing-parameter"``
+* ``"miss-sep-in-table"``
+* ``"unknown-cast-variable"``
+* ``"miss-loop-min"``
+* ``"malformed-number"``
+* ``"err-do-as-then"``
+* ``"spell-check"``
+* ``"undefined-env-child"``
+* ``"missing-return-value"``
+* ``"discard-returns"``
+* ``"redundant-return"``
+* ``"miss-esc-x"``
+* ``"redundant-value"``
+* ``"duplicate-doc-alias"``
+* ``"doc-field-no-class"``
+* ``"no-visible-label"``
+* ``"miss-exp"``
+* ``"miss-loop-max"``
+* ``"miss-name"``
+* ``"empty-block"``
+* ``"unused-local"``
+* ``"err-then-as-do"``
+* ``"duplicate-doc-field"``
+* ``"redefined-label"``
+* ``"exp-in-action"``
+* ``"set-const"``
+* ``"circle-doc-class"``
+* ``"unexpect-lfunc-name"``
+* ``"unsupport-symbol"``
+* ``"unused-label"``
+* ``"action-after-return"``
+* ``"unexpect-dots"``
+* ``"newline-call"``
+* ``"jump-local-scope"``
+* ``"close-non-object"``
+* ``"miss-field"``
+* ``"count-down-loop"``
+* ``"cast-type-mismatch"``
+* ``"duplicate-index"``
+* ``"unexpect-symbol"``
+* ``"block-after-else"``
+* ``"unicode-name"``
+* ``"miss-exponent"``
+* ``"err-esc"``
+* ``"redundant-return-value"``
+* ``"unbalanced-assignments"``
+* ``"err-c-long-comment"``
+* ``"undefined-doc-name"``
+* ``"ambiguity-1"``
+* ``"trailing-space"``
+* ``"deprecated"``
+* ``"codestyle-check"``
+* ``"missing-return"``
+* ``"undefined-global"``
+* ``"unused-function"``
+* ``"code-after-break"``
+* ``"assign-type-mismatch"``
+* ``"local-limit"``
+* ``"cast-local-type"``
+* ``"need-check-nil"``
+* ``"keyword"``
+* ``"unknown-diag-code"``
+* ``"unused-vararg"``
+* ``"err-comment-prefix"``
+* ``"lowercase-global"``
+* ``"return-type-mismatch"``
+* ``"duplicate-set-field"``
+* ``"redefined-local"``
+* ``"no-unknown"``
+* ``"duplicate-doc-param"``
+* ``"index-in-func-name"``
+* ``"miss-symbol"``
+* ``"undefined-field"``
+* ``"miss-space-between"``
+
## default
```jsonc
diff --git a/doc/zh-tw/config.md b/doc/zh-tw/config.md
index bd2dc4fb..4cf0dd01 100644
--- a/doc/zh-tw/config.md
+++ b/doc/zh-tw/config.md
@@ -186,6 +186,102 @@ true
Array<string>
```
+## enum
+
+* ``"not-yieldable"``
+* ``"redundant-parameter"``
+* ``"break-outside"``
+* ``"undefined-doc-class"``
+* ``"unknown-symbol"``
+* ``"miss-method"``
+* ``"err-nonstandard-symbol"``
+* ``"unknown-attribute"``
+* ``"unexpect-efunc-name"``
+* ``"different-requires"``
+* ``"miss-end"``
+* ``"await-in-sync"``
+* ``"args-after-dots"``
+* ``"err-eq-as-assign"``
+* ``"newfield-call"``
+* ``"err-assign-as-eq"``
+* ``"undefined-doc-param"``
+* ``"param-type-mismatch"``
+* ``"global-in-nil-env"``
+* ``"missing-parameter"``
+* ``"miss-sep-in-table"``
+* ``"unknown-cast-variable"``
+* ``"miss-loop-min"``
+* ``"malformed-number"``
+* ``"err-do-as-then"``
+* ``"spell-check"``
+* ``"undefined-env-child"``
+* ``"missing-return-value"``
+* ``"discard-returns"``
+* ``"redundant-return"``
+* ``"miss-esc-x"``
+* ``"redundant-value"``
+* ``"duplicate-doc-alias"``
+* ``"doc-field-no-class"``
+* ``"no-visible-label"``
+* ``"miss-exp"``
+* ``"miss-loop-max"``
+* ``"miss-name"``
+* ``"empty-block"``
+* ``"unused-local"``
+* ``"err-then-as-do"``
+* ``"duplicate-doc-field"``
+* ``"redefined-label"``
+* ``"exp-in-action"``
+* ``"set-const"``
+* ``"circle-doc-class"``
+* ``"unexpect-lfunc-name"``
+* ``"unsupport-symbol"``
+* ``"unused-label"``
+* ``"action-after-return"``
+* ``"unexpect-dots"``
+* ``"newline-call"``
+* ``"jump-local-scope"``
+* ``"close-non-object"``
+* ``"miss-field"``
+* ``"count-down-loop"``
+* ``"cast-type-mismatch"``
+* ``"duplicate-index"``
+* ``"unexpect-symbol"``
+* ``"block-after-else"``
+* ``"unicode-name"``
+* ``"miss-exponent"``
+* ``"err-esc"``
+* ``"redundant-return-value"``
+* ``"unbalanced-assignments"``
+* ``"err-c-long-comment"``
+* ``"undefined-doc-name"``
+* ``"ambiguity-1"``
+* ``"trailing-space"``
+* ``"deprecated"``
+* ``"codestyle-check"``
+* ``"missing-return"``
+* ``"undefined-global"``
+* ``"unused-function"``
+* ``"code-after-break"``
+* ``"assign-type-mismatch"``
+* ``"local-limit"``
+* ``"cast-local-type"``
+* ``"need-check-nil"``
+* ``"keyword"``
+* ``"unknown-diag-code"``
+* ``"unused-vararg"``
+* ``"err-comment-prefix"``
+* ``"lowercase-global"``
+* ``"return-type-mismatch"``
+* ``"duplicate-set-field"``
+* ``"redefined-local"``
+* ``"no-unknown"``
+* ``"duplicate-doc-param"``
+* ``"index-in-func-name"``
+* ``"miss-symbol"``
+* ``"undefined-field"``
+* ``"miss-space-between"``
+
## default
```jsonc
diff --git a/script/config/template.lua b/script/config/template.lua
index 2f5ff005..4a58c17b 100644
--- a/script/config/template.lua
+++ b/script/config/template.lua
@@ -1,5 +1,6 @@
local util = require 'utility'
local define = require 'proto.define'
+local diag = require 'proto.diagnostic'
---@class config.unit
---@field caller function
@@ -232,7 +233,7 @@ local template = {
>> util.deepCopy(define.BuiltIn),
['Lua.diagnostics.enable'] = Type.Boolean >> true,
['Lua.diagnostics.globals'] = Type.Array(Type.String),
- ['Lua.diagnostics.disable'] = Type.Array(Type.String),
+ ['Lua.diagnostics.disable'] = Type.Array(Type.String << util.getTableKeys(diag.getDiagAndErrNameMap())),
['Lua.diagnostics.severity'] = Type.Hash(
Type.String << util.getTableKeys(define.DiagnosticDefaultNeededFileStatus, true),
Type.String << {
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index c9359e9a..a8895f72 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -18,6 +18,7 @@ local lookBackward = require 'core.look-backward'
local guide = require 'parser.guide'
local await = require 'await'
local postfix = require 'core.completion.postfix'
+local diag = require 'proto.diagnostic'
local diagnosticModes = {
'disable-next-line',
@@ -1834,7 +1835,7 @@ local function tryluaDocByErr(state, position, err, docState, results)
}
end
elseif err.type == 'LUADOC_MISS_DIAG_NAME' then
- for name in util.sortPairs(define.DiagnosticDefaultSeverity) do
+ for name in util.sortPairs(diag.getDiagAndErrNameMap()) do
results[#results+1] = {
label = name,
kind = define.CompletionItemKind.Value,
diff --git a/script/core/diagnostics/unknown-diag-code.lua b/script/core/diagnostics/unknown-diag-code.lua
index 9e492a29..07128a27 100644
--- a/script/core/diagnostics/unknown-diag-code.lua
+++ b/script/core/diagnostics/unknown-diag-code.lua
@@ -1,6 +1,6 @@
local files = require 'files'
local lang = require 'language'
-local define = require 'proto.define'
+local diag = require 'proto.diagnostic'
return function (uri, callback)
local state = files.getState(uri)
@@ -17,7 +17,7 @@ return function (uri, callback)
if doc.names then
for _, nameUnit in ipairs(doc.names) do
local code = nameUnit[1]
- if not define.DiagnosticDefaultSeverity[code] then
+ if not diag.getDiagAndErrNameMap()[code] then
callback {
start = nameUnit.start,
finish = nameUnit.finish,
diff --git a/script/proto/diagnostic.lua b/script/proto/diagnostic.lua
index 1065950d..e5f74ef5 100644
--- a/script/proto/diagnostic.lua
+++ b/script/proto/diagnostic.lua
@@ -236,4 +236,31 @@ m.getGroups = util.cacheReturn(function (name)
return groups
end)
+---@return table<string, true>
+function m.getDiagAndErrNameMap()
+ if not m._diagAndErrNames then
+ local names = {}
+ for name in pairs(m.getDefaultSeverity()) do
+ names[name] = true
+ end
+ local path = package.searchpath('parser.compile', package.path)
+ if path then
+ local f = io.open(path)
+ if f then
+ for line in f:lines() do
+ local name = line:match([=[type%s*=%s*['"](%u[%u_]+%u)['"]]=])
+ if name then
+ local id = name:lower():gsub('_', '-')
+ names[id] = true
+ end
+ end
+ f:close()
+ end
+ end
+ table.sort(names)
+ m._diagAndErrNames = names
+ end
+ return m._diagAndErrNames
+end
+
return m
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index c3822087..58940d2e 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -17,6 +17,7 @@ local ltable = require 'linked-table'
local furi = require 'file-uri'
local json = require 'json'
local fw = require 'filewatch'
+local vm = require 'vm.vm'
---@class diagnosticProvider
local m = {}
@@ -193,7 +194,9 @@ function m.syntaxErrors(uri, ast)
pcall(function ()
local disables = util.arrayToHash(config.get(uri, 'Lua.diagnostics.disable'))
for _, err in ipairs(ast.errs) do
- if not disables[err.type:lower():gsub('_', '-')] then
+ local id = err.type:lower():gsub('_', '-')
+ if not disables[id]
+ and not vm.isDiagDisabledAt(uri, err.start, id, true) then
results[#results+1] = buildSyntaxError(uri, err)
end
end
diff --git a/script/vm/doc.lua b/script/vm/doc.lua
index 15dfde89..c3b924d2 100644
--- a/script/vm/doc.lua
+++ b/script/vm/doc.lua
@@ -358,8 +358,9 @@ end
---@param uri uri
---@param position integer
---@param name string
+---@param err? boolean
---@return boolean
-function vm.isDiagDisabledAt(uri, position, name)
+function vm.isDiagDisabledAt(uri, position, name, err)
local status = files.getState(uri)
if not status then
return false
@@ -389,7 +390,8 @@ function vm.isDiagDisabledAt(uri, position, name)
local count = 0
for _, range in ipairs(cache.diagnosticRanges) do
if range.row <= myRow then
- if not range.names or range.names[name] then
+ if (range.names and range.names[name])
+ or (not range.names and not err) then
if range.mode == 'disable' then
count = count + 1
elseif range.mode == 'enable' then