diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/config/template.lua | 1 | ||||
-rw-r--r-- | script/proto/define.lua | 127 | ||||
-rw-r--r-- | script/proto/diagnostic.lua | 204 |
4 files changed, 210 insertions, 123 deletions
diff --git a/changelog.md b/changelog.md index a06908d2..a1608bd0 100644 --- a/changelog.md +++ b/changelog.md @@ -23,6 +23,7 @@ local n2 = f(0) -- `n2` is `number` local n3 = f(0, 0) -- `n3` is `string` ``` +* `CHG` improve speed for diagnostics and semantic-tokens * `FIX` diagnostics flash when opening a file * `FIX` sometimes workspace diagnostics are not triggered * `FIX` [#1228](https://github.com/sumneko/lua-language-server/issues/1228) diff --git a/script/config/template.lua b/script/config/template.lua index 93f3344b..6078b5a6 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -260,6 +260,7 @@ local template = { 'Opened', 'Disable', }, + ['Lua.typeCheck.enable'] = Type.Boolean >> true, ['Lua.workspace.ignoreDir'] = Type.Array(Type.String) >> { '.vscode', }, diff --git a/script/proto/define.lua b/script/proto/define.lua index 30ef621e..fa834cbf 100644 --- a/script/proto/define.lua +++ b/script/proto/define.lua @@ -1,3 +1,5 @@ +local diag = require 'proto.diagnostic' + local m = {} --- 诊断等级 @@ -8,132 +10,11 @@ m.DiagnosticSeverity = { Hint = 4, } ----@alias DiagnosticDefaultSeverity ----| 'Hint' ----| 'Information' ----| 'Warning' ----| 'Error' - --- 诊断类型与默认等级 ----@type table<string, DiagnosticDefaultSeverity> -m.DiagnosticDefaultSeverity = { - ['unused-local'] = 'Hint', - ['unused-function'] = 'Hint', - ['undefined-global'] = 'Warning', - ['undefined-field'] = 'Warning', - ['global-in-nil-env'] = 'Warning', - ['unused-label'] = 'Hint', - ['unused-vararg'] = 'Hint', - ['trailing-space'] = 'Hint', - ['redefined-local'] = 'Hint', - ['newline-call'] = 'Information', - ['newfield-call'] = 'Warning', - ['redundant-parameter'] = 'Warning', - ['missing-parameter'] = 'Warning', - ['redundant-return'] = 'Warning', - ['ambiguity-1'] = 'Warning', - ['lowercase-global'] = 'Information', - ['undefined-env-child'] = 'Information', - ['duplicate-index'] = 'Warning', - ['duplicate-set-field'] = 'Warning', - ['empty-block'] = 'Hint', - ['redundant-value'] = 'Warning', - ['code-after-break'] = 'Hint', - ['unbalanced-assignments'] = 'Warning', - ['close-non-object'] = 'Warning', - ['count-down-loop'] = 'Warning', - ['no-unknown'] = 'Information', - ['deprecated'] = 'Warning', - ['different-requires'] = 'Warning', - ['await-in-sync'] = 'Warning', - ['not-yieldable'] = 'Warning', - ['discard-returns'] = 'Warning', - ['need-check-nil'] = 'Warning', - ['cast-local-type'] = 'Warning', - ['assign-type-mismatch'] = 'Warning', - ['param-type-mismatch'] = 'Warning', - - ['duplicate-doc-alias'] = 'Warning', - ['undefined-doc-class'] = 'Warning', - ['undefined-doc-name'] = 'Warning', - ['circle-doc-class'] = 'Warning', - ['undefined-doc-param'] = 'Warning', - ['duplicate-doc-param'] = 'Warning', - ['doc-field-no-class'] = 'Warning', - ['duplicate-doc-field'] = 'Warning', - ['unknown-diag-code'] = 'Warning', - ['unknown-cast-variable'] = 'Warning', - ['cast-type-mismatch'] = 'Warning', - - ['codestyle-check'] = 'Warning', - ['spell-check'] = 'Information', -} - ----@alias DiagnosticDefaultNeededFileStatus ----| 'Any' ----| 'Opened' ----| 'None' - --- 文件状态 -m.FileStatus = { - Any = 1, - Opened = 2, -} +m.DiagnosticDefaultSeverity = diag.getDefaultSeverity() --- 诊断类型与需要的文件状态(可以控制只分析打开的文件、还是所有文件) ----@type table<string, DiagnosticDefaultNeededFileStatus> -m.DiagnosticDefaultNeededFileStatus = { - ['unused-local'] = 'Opened', - ['unused-function'] = 'Opened', - ['undefined-global'] = 'Any', - ['undefined-field'] = 'Opened', - ['global-in-nil-env'] = 'Any', - ['unused-label'] = 'Opened', - ['unused-vararg'] = 'Opened', - ['trailing-space'] = 'Opened', - ['redefined-local'] = 'Opened', - ['newline-call'] = 'Any', - ['newfield-call'] = 'Any', - ['redundant-parameter'] = 'Opened', - ['missing-parameter'] = 'Opened', - ['redundant-return'] = 'Opened', - ['ambiguity-1'] = 'Any', - ['lowercase-global'] = 'Any', - ['undefined-env-child'] = 'Any', - ['duplicate-index'] = 'Any', - ['duplicate-set-field'] = 'Any', - ['empty-block'] = 'Opened', - ['redundant-value'] = 'Opened', - ['code-after-break'] = 'Opened', - ['unbalanced-assignments'] = 'Any', - ['close-non-object'] = 'Any', - ['count-down-loop'] = 'Any', - ['no-unknown'] = 'None', - ['deprecated'] = 'Opened', - ['different-requires'] = 'Any', - ['await-in-sync'] = 'None', - ['not-yieldable'] = 'None', - ['discard-returns'] = 'Opened', - ['need-check-nil'] = 'Opened', - ['cast-local-type'] = 'Any', - ['assign-type-mismatch'] = 'Any', - ['param-type-mismatch'] = 'Any', - - ['duplicate-doc-alias'] = 'Any', - ['undefined-doc-class'] = 'Any', - ['undefined-doc-name'] = 'Any', - ['circle-doc-class'] = 'Any', - ['undefined-doc-param'] = 'Any', - ['duplicate-doc-param'] = 'Any', - ['doc-field-no-class'] = 'Any', - ['duplicate-doc-field'] = 'Any', - ['unknown-diag-code'] = 'Any', - ['unknown-cast-variable'] = 'Any', - ['cast-type-mismatch'] = 'Any', - - ['codestyle-check'] = 'None', - ['spell-check'] = 'None', -} +m.DiagnosticDefaultNeededFileStatus = diag.getDefaultStatus() --- 诊断报告标签 m.DiagnosticTag = { diff --git a/script/proto/diagnostic.lua b/script/proto/diagnostic.lua new file mode 100644 index 00000000..09c0596d --- /dev/null +++ b/script/proto/diagnostic.lua @@ -0,0 +1,204 @@ +---@class proto.diagnostic +local m = {} + +---@alias DiagnosticSeverity +---| 'Hint' +---| 'Information' +---| 'Warning' +---| 'Error' + +---@alias DiagnosticNeededFileStatus +---| 'Any' +---| 'Opened' +---| 'None' + +---@class proto.diagnostic.info +---@field severity DiagnosticSeverity +---@field status DiagnosticNeededFileStatus +---@field group string + +m.diagnosticDatas = {} +m.diagnosticGroups = {} + +function m.register(names) + ---@param info proto.diagnostic.info + return function (info) + for _, name in ipairs(names) do + m.diagnosticDatas[name] = { + severity = info.severity, + status = info.status, + } + if not m.diagnosticGroups[info.group] then + m.diagnosticGroups[info.group] = {} + end + m.diagnosticGroups[info.group][name] = true + end + end +end + +m.register { + 'unused-local', + 'unused-function', + 'unused-label', + 'unused-vararg', + 'trailing-space', + 'redundant-return', + 'empty-block', + 'code-after-break', +} { + group = 'unused', + severity = 'Hint', + status = 'Opened', +} + +m.register { + 'redundant-value', + 'unbalanced-assignments', + 'redundant-parameter', + 'missing-parameter', +} { + group = 'unbalanced', + severity = 'Warning', + status = 'Any', +} + +m.register { + 'need-check-nil', + 'undefined-field', + 'cast-local-type', + 'assign-type-mismatch', + 'param-type-mismatch', + 'cast-type-mismatch', +} { + group = 'type-check', + severity = 'Warning', + status = 'Opened', +} + +m.register { + 'duplicate-doc-alias', + 'undefined-doc-class', + 'undefined-doc-name', + 'circle-doc-class', + 'undefined-doc-param', + 'duplicate-doc-param', + 'doc-field-no-class', + 'duplicate-doc-field', + 'unknown-diag-code', + 'unknown-cast-variable', + 'cast-type-mismatch', +} { + group = 'luadoc', + severity = 'Warning', + status = 'Any', +} + +m.register { + 'codestyle-check' +} { + group = 'codestyle', + severity = 'Warning', + status = 'None', +} + +m.register { + 'spell-check' +} { + group = 'codestyle', + severity = 'Information', + status = 'None', +} + +m.register { + 'newline-call', + 'newfield-call', + 'ambiguity-1', + 'count-down-loop', + 'different-requires', +} { + group = 'ambiguity', + severity = 'Warning', + status = 'Any', +} + +m.register { + 'await-in-sync', + 'not-yieldable', +} { + group = 'await', + severity = 'Warning', + status = 'None', +} + +m.register { + 'no-unknown', +} { + group = 'no-unknown', + severity = 'Warning', + status = 'None', +} + +m.register { + 'redefined-local', +} { + group = 'redefined', + severity = 'Hint', + status = 'Opened', +} + +m.register { + 'undefined-global', + 'global-in-nil-env', +} { + group = 'global', + severity = 'Warning', + status = 'Any', +} + +m.register { + 'lowercase-global', + 'undefined-env-child', +} { + group = 'global', + severity = 'Information', + status = 'Any', +} + +m.register { + 'duplicate-index', + 'duplicate-set-field', +} { + group = 'duplicate', + severity = 'Warning', + status = 'Any', +} + +m.register { + 'close-non-object', + 'deprecated', + 'discard-returns', +} { + group = 'strict', + severity = 'Warning', + status = 'Any', +} + +---@return table<string, DiagnosticSeverity> +function m.getDefaultSeverity() + local severity = {} + for name, info in pairs(m.diagnosticDatas) do + severity[name] = info.severity + end + return severity +end + +---@return table<string, DiagnosticNeededFileStatus> +function m.getDefaultStatus() + local status = {} + for name, info in pairs(m.diagnosticDatas) do + status[name] = info.status + end + return status +end + +return m |