diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-05 19:47:15 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-05 19:47:15 +0800 |
commit | 2ab618716a33378449aa4938864db632a141719e (patch) | |
tree | 56b141d4b3439b5136d988908fc08b2b5838146e /script | |
parent | 671c7089a1697ee8f6fc108a9568b0509e1aa933 (diff) | |
download | lua-language-server-2ab618716a33378449aa4938864db632a141719e.zip |
resolve #1254 can suppress syntax errors
Diffstat (limited to 'script')
-rw-r--r-- | script/config/template.lua | 3 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 3 | ||||
-rw-r--r-- | script/core/diagnostics/unknown-diag-code.lua | 4 | ||||
-rw-r--r-- | script/proto/diagnostic.lua | 27 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 5 | ||||
-rw-r--r-- | script/vm/doc.lua | 6 |
6 files changed, 41 insertions, 7 deletions
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 |