summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-10 10:04:09 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-10 10:04:09 +0800
commit2a0d80c2dfbb0b00414a58cca4d06c397ec8e691 (patch)
treec5164c8d2b6acec8685d69c0630893e156549a88
parenteb7c7b6dcae752b03332f4f6d9004381eb87d457 (diff)
downloadlua-language-server-2a0d80c2dfbb0b00414a58cca4d06c397ec8e691.zip
给诊断添加code,每一类都可以单独禁用
-rw-r--r--package.json14
-rw-r--r--server/src/config.lua3
-rw-r--r--server/src/core/diagnostics.lua163
-rw-r--r--server/src/method/textDocument/publishDiagnostics.lua1
4 files changed, 96 insertions, 85 deletions
diff --git a/package.json b/package.json
index 3199b600..80f5ad7c 100644
--- a/package.json
+++ b/package.json
@@ -33,17 +33,11 @@
"type": "object",
"title": "Lua",
"properties": {
- "Lua.diagnostics.postSpcae": {
+ "Lua.diagnostics.disable": {
"scope": "resource",
- "type": "boolean",
- "default": true,
- "description": "Check post spaces.\n检查后置空格。"
- },
- "Lua.diagnostics.spaceOnlyLine": {
- "scope": "resource",
- "type": "boolean",
- "default": true,
- "description": "Check space-only lines.\n检查只有空格的行。"
+ "type": "array",
+ "items": "string",
+ "description": "Disabled diagnostic (Use code in hover brackets).\n禁用的诊断(使用浮框括号内的代码)。"
},
"Lua.diagnostics.globals": {
"scope": "resource",
diff --git a/server/src/config.lua b/server/src/config.lua
index aa8452c6..a19f17d8 100644
--- a/server/src/config.lua
+++ b/server/src/config.lua
@@ -29,9 +29,8 @@ end
local Template = {
diagnostics = {
- postSpcae = {true, Boolean},
- spaceOnlyLine = {true, Boolean},
globals = {{}, Str2Hash ';'},
+ disable = {{}, Str2Hash ';'},
},
workspace = {
ignoreDir = {{}, Str2Hash ';'}
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index 662711fb..7ab7e664 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -101,28 +101,24 @@ local function searchSpaces(vm, lines, callback)
for i = 1, #lines do
local line = lines:line(i)
- if config.config.diagnostics.spaceOnlyLine then
- if line:find '^[ \t]+$' then
- local start, finish = lines:range(i)
- if isInString(vm, start, finish) then
- goto NEXT_LINE
- end
- callback(start, finish, lang.script.DIAG_LINE_ONLY_SPACE)
+ if line:find '^[ \t]+$' then
+ local start, finish = lines:range(i)
+ if isInString(vm, start, finish) then
goto NEXT_LINE
end
+ callback(start, finish, lang.script.DIAG_LINE_ONLY_SPACE)
+ goto NEXT_LINE
end
- if config.config.diagnostics.postSpcae then
- local pos = line:find '[ \t]+$'
- if pos then
- local start, finish = lines:range(i)
- start = start + pos - 1
- if isInString(vm, start, finish) then
- goto NEXT_LINE
- end
- callback(start, finish, lang.script.DIAG_LINE_POST_SPACE)
+ local pos = line:find '[ \t]+$'
+ if pos then
+ local start, finish = lines:range(i)
+ start = start + pos - 1
+ if isInString(vm, start, finish) then
goto NEXT_LINE
end
+ callback(start, finish, lang.script.DIAG_LINE_POST_SPACE)
+ goto NEXT_LINE
end
::NEXT_LINE::
@@ -211,68 +207,89 @@ return function (vm, lines, uri)
local datas = {}
local results = vm.results
-- 未使用的局部变量
- searchUnusedLocals(results, function (start, finish, key)
- datas[#datas+1] = {
- start = start,
- finish = finish,
- level = DiagnosticSeverity.Information,
- message = lang.script('DIAG_UNUSED_LOCAL', key),
- }
- end)
+ if not config.config.diagnostics.disable['unused-local'] then
+ searchUnusedLocals(results, function (start, finish, key)
+ datas[#datas+1] = {
+ code = 'unused-local',
+ start = start,
+ finish = finish,
+ level = DiagnosticSeverity.Information,
+ message = lang.script('DIAG_UNUSED_LOCAL', key),
+ }
+ end)
+ end
-- 读取未定义全局变量
- searchUndefinedGlobal(results, function (start, finish, key)
- datas[#datas+1] = {
- start = start,
- finish = finish,
- level = DiagnosticSeverity.Warning,
- message = lang.script('DIAG_UNDEFINED_GLOBAL', key),
- }
- end)
+ if not config.config.diagnostics.disable['undefined-global'] then
+ searchUndefinedGlobal(results, function (start, finish, key)
+ datas[#datas+1] = {
+ code = 'undefined-global',
+ start = start,
+ finish = finish,
+ level = DiagnosticSeverity.Warning,
+ message = lang.script('DIAG_UNDEFINED_GLOBAL', key),
+ }
+ end)
+ end
-- 未使用的Label
- searchUnusedLabel(results, function (start, finish, key)
- datas[#datas+1] = {
- start = start,
- finish = finish,
- level =DiagnosticSeverity.Information,
- message = lang.script('DIAG_UNUSED_LABEL', key)
- }
- end)
+ if not config.config.diagnostics.disable['unused-label'] then
+ searchUnusedLabel(results, function (start, finish, key)
+ datas[#datas+1] = {
+ code = 'unused-label',
+ start = start,
+ finish = finish,
+ level =DiagnosticSeverity.Information,
+ message = lang.script('DIAG_UNUSED_LABEL', key)
+ }
+ end)
+ end
-- 只有空格与制表符的行,以及后置空格
- searchSpaces(vm, lines, function (start, finish, message)
- datas[#datas+1] = {
- start = start,
- finish = finish,
- level = DiagnosticSeverity.Information,
- message = message,
- }
- end)
+ if not config.config.diagnostics.disable['trailing-space'] then
+ searchSpaces(vm, lines, function (start, finish, message)
+ datas[#datas+1] = {
+ code = 'trailing-space',
+ start = start,
+ finish = finish,
+ level = DiagnosticSeverity.Information,
+ message = message,
+ }
+ end)
+ end
-- 重定义局部变量
- searchRedefinition(results, uri, function (start, finish, key, related)
- datas[#datas+1] = {
- start = start,
- finish = finish,
- level = DiagnosticSeverity.Information,
- message = lang.script('DIAG_REDEFINED_LOCAL', key),
- related = related,
- }
- end)
+ if not config.config.diagnostics.disable['redefined-local'] then
+ searchRedefinition(results, uri, function (start, finish, key, related)
+ datas[#datas+1] = {
+ code = 'redefined-local',
+ start = start,
+ finish = finish,
+ level = DiagnosticSeverity.Information,
+ message = lang.script('DIAG_REDEFINED_LOCAL', key),
+ related = related,
+ }
+ end)
+ end
-- 以括号开始的一行(可能被误解析为了上一行的call)
- searchNewLineCall(results, lines, function (start, finish)
- datas[#datas+1] = {
- start = start,
- finish = finish,
- level = DiagnosticSeverity.Information,
- message = lang.script.DIAG_PREVIOUS_CALL,
- }
- end)
+ if not config.config.diagnostics.disable['newline-call'] then
+ searchNewLineCall(results, lines, function (start, finish)
+ datas[#datas+1] = {
+ code = 'newline-call',
+ start = start,
+ finish = finish,
+ level = DiagnosticSeverity.Information,
+ message = lang.script.DIAG_PREVIOUS_CALL,
+ }
+ end)
+ end
-- 调用函数时的参数数量是否超过函数的接收数量
- searchRedundantParameters(results, function (start, finish, max, passed)
- datas[#datas+1] = {
- start = start,
- finish = finish,
- level = DiagnosticSeverity.Warning,
- message = lang.script('DIAG_OVER_MAX_ARGS', max, passed),
- }
- end)
+ if not config.config.diagnostics.disable['remainder-parameters'] then
+ searchRedundantParameters(results, function (start, finish, max, passed)
+ datas[#datas+1] = {
+ code = 'remainder-parameters',
+ start = start,
+ finish = finish,
+ level = DiagnosticSeverity.Warning,
+ message = lang.script('DIAG_OVER_MAX_ARGS', max, passed),
+ }
+ end)
+ end
return datas
end
diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua
index fffd7f9d..9385c657 100644
--- a/server/src/method/textDocument/publishDiagnostics.lua
+++ b/server/src/method/textDocument/publishDiagnostics.lua
@@ -49,6 +49,7 @@ local function createInfo(data, lines)
range = getRange(data.start, data.finish, lines),
severity = data.level,
message = data.message,
+ code = data.code,
}
if data.related then
local related = {}