diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-07 17:54:27 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-07 17:54:27 +0800 |
commit | dd127fd3161c49a1604e5911c3d2e8dd5d2ac67c (patch) | |
tree | 31017429345ba035a3df64bb934b1f91e888240c | |
parent | 60332a2cceb05a0160d76d6182c756afa0571fae (diff) | |
download | lua-language-server-dd127fd3161c49a1604e5911c3d2e8dd5d2ac67c.zip |
resolve #619 `diagnostics.unusedLocalExclude`
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | doc/en-us/config.md | 16 | ||||
-rw-r--r-- | doc/pt-br/config.md | 16 | ||||
-rw-r--r-- | doc/zh-cn/config.md | 16 | ||||
-rw-r--r-- | doc/zh-tw/config.md | 16 | ||||
-rw-r--r-- | locale/en-us/setting.lua | 2 | ||||
-rw-r--r-- | locale/pt-br/setting.lua | 2 | ||||
-rw-r--r-- | locale/zh-cn/setting.lua | 2 | ||||
-rw-r--r-- | locale/zh-tw/setting.lua | 2 | ||||
-rw-r--r-- | script/config/template.lua | 1 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 2 | ||||
-rw-r--r-- | script/core/diagnostics/unused-local.lua | 7 | ||||
-rw-r--r-- | test/diagnostics/common.lua | 11 |
13 files changed, 93 insertions, 2 deletions
diff --git a/changelog.md b/changelog.md index 6b657aa4..6ba54a96 100644 --- a/changelog.md +++ b/changelog.md @@ -13,6 +13,8 @@ ``` * `NEW` diagnostics: * `unknown-operator` +* `NEW` settings: + * `diagnostics.unusedLocalExclude` * `FIX` [#1284](https://github.com/sumneko/lua-language-server/issues/1284) * `FIX` [#1292](https://github.com/sumneko/lua-language-server/issues/1292) * `FIX` [#1294](https://github.com/sumneko/lua-language-server/issues/1294) diff --git a/doc/en-us/config.md b/doc/en-us/config.md index 038cf920..3f483650 100644 --- a/doc/en-us/config.md +++ b/doc/en-us/config.md @@ -891,6 +891,22 @@ object<string, string> } ``` +# diagnostics.unusedLocalExclude + +Do not diagnose `unused-local` when the variable name matches the following pattern. + +## type + +```ts +Array<string> +``` + +## default + +```jsonc +[] +``` + # diagnostics.workspaceDelay Latency (milliseconds) for workspace diagnostics. When you start the workspace, or edit any file, the entire workspace will be re-diagnosed in the background. Set to negative to disable workspace diagnostics. diff --git a/doc/pt-br/config.md b/doc/pt-br/config.md index 479a6add..f888efea 100644 --- a/doc/pt-br/config.md +++ b/doc/pt-br/config.md @@ -891,6 +891,22 @@ object<string, string> } ``` +# diagnostics.unusedLocalExclude + +Do not diagnose `unused-local` when the variable name matches the following pattern. + +## type + +```ts +Array<string> +``` + +## default + +```jsonc +[] +``` + # diagnostics.workspaceDelay Latency (milliseconds) for workspace diagnostics. When you start the workspace, or edit any file, the entire workspace will be re-diagnosed in the background. Set to negative to disable workspace diagnostics. diff --git a/doc/zh-cn/config.md b/doc/zh-cn/config.md index a315b168..3e2b1246 100644 --- a/doc/zh-cn/config.md +++ b/doc/zh-cn/config.md @@ -890,6 +890,22 @@ object<string, string> } ``` +# diagnostics.unusedLocalExclude + +如果变量名匹配以下规则,则不对其进行 `unused-local` 诊断。 + +## type + +```ts +Array<string> +``` + +## default + +```jsonc +[] +``` + # diagnostics.workspaceDelay 进行工作区诊断的延迟(毫秒)。当你启动工作区,或编辑了任意文件后,将会在后台对整个工作区进行重新诊断。设置为负数可以禁用工作区诊断。 diff --git a/doc/zh-tw/config.md b/doc/zh-tw/config.md index 3fff6c6d..dcd44d63 100644 --- a/doc/zh-tw/config.md +++ b/doc/zh-tw/config.md @@ -890,6 +890,22 @@ object<string, string> } ``` +# diagnostics.unusedLocalExclude + +Do not diagnose `unused-local` when the variable name matches the following pattern. + +## type + +```ts +Array<string> +``` + +## default + +```jsonc +[] +``` + # diagnostics.workspaceDelay 進行工作區診斷的延遲(毫秒)。當你啟動工作區,或編輯了任何檔案後,將會在背景對整個工作區進行重新診斷。設定為負數可以停用工作區診斷。 diff --git a/locale/en-us/setting.lua b/locale/en-us/setting.lua index 5ce69de7..f35edac4 100644 --- a/locale/en-us/setting.lua +++ b/locale/en-us/setting.lua @@ -97,6 +97,8 @@ config.diagnostics.ignoredFiles.Disable = "These files are not diagnosed." config.diagnostics.disableScheme = 'Do not diagnose Lua files that use the following scheme.' +config.diagnostics.unusedLocalExclude = +'Do not diagnose `unused-local` when the variable name matches the following pattern.' config.workspace.ignoreDir = "Ignored files and directories (Use `.gitignore` grammar)."-- .. example.ignoreDir, config.workspace.ignoreSubmodules = diff --git a/locale/pt-br/setting.lua b/locale/pt-br/setting.lua index e8271ce5..b673e90f 100644 --- a/locale/pt-br/setting.lua +++ b/locale/pt-br/setting.lua @@ -97,6 +97,8 @@ config.diagnostics.ignoredFiles.Disable = -- TODO: need translate! "These files are not diagnosed." config.diagnostics.disableScheme = -- TODO: need translate! 'Do not diagnose Lua files that use the following scheme.' +config.diagnostics.unusedLocalExclude = -- TODO: need translate! +'Do not diagnose `unused-local` when the variable name matches the following pattern.' config.workspace.ignoreDir = -- TODO: need translate! "Ignored files and directories (Use `.gitignore` grammar)."-- .. example.ignoreDir, config.workspace.ignoreSubmodules = -- TODO: need translate! diff --git a/locale/zh-cn/setting.lua b/locale/zh-cn/setting.lua index 54de9293..5fa4bf8b 100644 --- a/locale/zh-cn/setting.lua +++ b/locale/zh-cn/setting.lua @@ -96,6 +96,8 @@ config.diagnostics.ignoredFiles.Disable = "不诊断这些文件。" config.diagnostics.disableScheme = '不诊断使用以下 scheme 的lua文件。' +config.diagnostics.unusedLocalExclude = +'如果变量名匹配以下规则,则不对其进行 `unused-local` 诊断。' config.workspace.ignoreDir = "忽略的文件与目录(使用 `.gitignore` 语法)。" config.workspace.ignoreSubmodules = diff --git a/locale/zh-tw/setting.lua b/locale/zh-tw/setting.lua index 17a3435a..9ff8e1a7 100644 --- a/locale/zh-tw/setting.lua +++ b/locale/zh-tw/setting.lua @@ -96,6 +96,8 @@ config.diagnostics.ignoredFiles.Disable = "不診斷這些檔案。" config.diagnostics.disableScheme = '不診斷使用以下 scheme 的lua檔案。' +config.diagnostics.unusedLocalExclude = -- TODO: need translate! +'Do not diagnose `unused-local` when the variable name matches the following pattern.' config.workspace.ignoreDir = "忽略的檔案與目錄(使用 `.gitignore` 語法)。" config.workspace.ignoreSubmodules = diff --git a/script/config/template.lua b/script/config/template.lua index 4e2f45ae..fa0c2772 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -300,6 +300,7 @@ local template = { 'Opened', 'Disable', }, + ['Lua.diagnostics.unusedLocalExclude'] = Type.Array(Type.String), ['Lua.workspace.ignoreDir'] = Type.Array(Type.String) >> { '.vscode', }, diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index c577874f..c882f283 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -2075,8 +2075,6 @@ local function completion(uri, position, triggerCharacter) return nil end clearStack() - vm.lockCache() - local _ <close> = vm.unlockCache local results = {} tracy.ZoneBeginN 'completion #2' tryCompletions(state, position, triggerCharacter, results) diff --git a/script/core/diagnostics/unused-local.lua b/script/core/diagnostics/unused-local.lua index 8bff7dcb..8f2ee217 100644 --- a/script/core/diagnostics/unused-local.lua +++ b/script/core/diagnostics/unused-local.lua @@ -3,6 +3,8 @@ local guide = require 'parser.guide' local define = require 'proto.define' local lang = require 'language' local vm = require 'vm.vm' +local config = require 'config.config' +local glob = require 'glob' local function hasGet(loc) if not loc.ref then @@ -88,12 +90,17 @@ return function (uri, callback) if not ast then return end + local ignorePatterns = config.get(uri, 'Lua.diagnostics.unusedLocalExclude') + local ignore = glob.glob(ignorePatterns) guide.eachSourceType(ast.ast, 'local', function (source) local name = source[1] if name == '_' or name == ast.ENVMode then return end + if ignore(name) then + return + end if isToBeClosed(source) then return end diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index 27e92676..59a56981 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -1907,3 +1907,14 @@ TEST [[ ---@class A ---@operator <!xxx!>: A ]] + +config.add(nil, 'Lua.diagnostics.unusedLocalIgnore', 'll_*') + +TEST [[ +local <!xx!> +local ll_1 +local ll_2 +local <!ll!> +]] + +config.remove(nil, 'Lua.diagnostics.unusedLocalIgnore', 'll_*') |