summaryrefslogtreecommitdiff
path: root/server/src/core/diagnostics.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-08-27 10:00:29 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-08-27 10:00:29 +0800
commit4b38c86f9edcc4898ab62d3acf38c188104642b2 (patch)
tree713803f5b32bd9345ef2339dab89ac4dc0461a2b /server/src/core/diagnostics.lua
parent10b433bd2554678b79086e0486c6701fffca3bd1 (diff)
downloadlua-language-server-4b38c86f9edcc4898ab62d3acf38c188104642b2.zip
优化重复索引的诊断表现
Diffstat (limited to 'server/src/core/diagnostics.lua')
-rw-r--r--server/src/core/diagnostics.lua36
1 files changed, 24 insertions, 12 deletions
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index e3d3ee6a..26327ea2 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -361,9 +361,9 @@ function mt:searchDuplicateIndex(callback)
end
if name then
if mark[name] then
- mark[name][#mark[name]+1] = key
+ mark[name][#mark[name]+1] = obj
else
- mark[name] = { key }
+ mark[name] = { obj }
end
end
end
@@ -373,13 +373,16 @@ function mt:searchDuplicateIndex(callback)
local related = {}
for i = 1, #defs do
related[i] = {
- start = defs[i].start,
- finish = defs[i].finish,
+ start = defs[i][1].start,
+ finish = defs[i][2].finish,
uri = self.uri,
}
end
- for i = 2, #defs do
- callback(defs[i].start, defs[i].finish, name, related)
+ for i = 1, #defs - 1 do
+ callback(defs[i][1].start, defs[i][2].finish, name, related, 'unused')
+ end
+ for i = #defs, #defs do
+ callback(defs[i][1].start, defs[i][1].finish, name, related, 'duplicate')
end
end
end
@@ -768,7 +771,7 @@ function mt:doDiagnostics(func, code, callback)
data.code = code
data.start = start
data.finish = finish
- data.level = DiagnosticSeverity[level]
+ data.level = data.level or DiagnosticSeverity[level]
self.datas[#self.datas+1] = data
end)
if coroutine.isyieldable() then
@@ -875,11 +878,20 @@ return function (vm, lines, uri)
end
end)
-- 构建表时重复定义field
- session:doDiagnostics(session.searchDuplicateIndex, 'duplicate-index', function (key, related)
- return {
- message = lang.script('DIAG_DUPLICATE_INDEX', key),
- related = related,
- }
+ session:doDiagnostics(session.searchDuplicateIndex, 'duplicate-index', function (key, related, type)
+ if type == 'unused' then
+ return {
+ message = lang.script('DIAG_DUPLICATE_INDEX', key),
+ related = related,
+ level = DiagnosticSeverity.Hint,
+ tags = {DiagnosticTag.Unnecessary},
+ }
+ else
+ return {
+ message = lang.script('DIAG_DUPLICATE_INDEX', key),
+ related = related,
+ }
+ end
end)
-- 往表里面塞重复的method
--session:doDiagnostics(session.searchDuplicateMethod, 'duplicate-method', function (key, related)