summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-08-06 14:58:41 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-08-06 14:58:41 +0800
commitf87c508bf3a45465c01241a0502041be9b693c08 (patch)
treef481699759f2c1e0aa8d1815cadf3bfac6ce80ab /server/src
parentcffa66267a2c31fb13cdcf41e2c68dd549c9cc07 (diff)
downloadlua-language-server-f87c508bf3a45465c01241a0502041be9b693c08.zip
诊断重复的field
Diffstat (limited to 'server/src')
-rw-r--r--server/src/constant/DiagnosticDefaultSeverity.lua1
-rw-r--r--server/src/core/diagnostics.lua52
2 files changed, 53 insertions, 0 deletions
diff --git a/server/src/constant/DiagnosticDefaultSeverity.lua b/server/src/constant/DiagnosticDefaultSeverity.lua
index eef44107..6edfb04b 100644
--- a/server/src/constant/DiagnosticDefaultSeverity.lua
+++ b/server/src/constant/DiagnosticDefaultSeverity.lua
@@ -11,6 +11,7 @@ return {
['lowercase-global'] = 'Information',
['undefined-env-child'] = 'Information',
['duplicate-index'] = 'Warning',
+ ['duplicate-field'] = 'Warning',
['empty-block'] = 'Information',
['redundant-value'] = 'Information',
['emmy-lua'] = 'Warning',
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index 8eab5960..c136945a 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -385,6 +385,51 @@ function mt:searchDuplicateIndex(callback)
end)
end
+function mt:searchDuplicateField(callback)
+ local mark = {}
+ self.vm:eachSource(function (source)
+ local parent = source:get 'parent'
+ if not parent then
+ return
+ end
+ if mark[parent] then
+ return
+ end
+ mark[parent] = true
+ local relates = {}
+ parent:eachInfo(function (info, src)
+ local k = info[1]
+ if source == src then
+ return
+ end
+ if info.type ~= 'set child' then
+ return
+ end
+ if type(k) ~= 'string' then
+ return
+ end
+ if src.start == 0 then
+ return
+ end
+ if not relates[k] then
+ relates[k] = {}
+ end
+ relates[k][#relates[k]+1] = {
+ start = src.start,
+ finish = src.finish,
+ uri = src.uri
+ }
+ end)
+ for name, relate in pairs(relates) do
+ if #relate > 1 then
+ for _, data in ipairs(relate) do
+ callback(data.start, data.finish, name, relate)
+ end
+ end
+ end
+ end)
+end
+
function mt:searchEmptyBlock(callback)
self.vm:eachSource(function (source)
-- 认为空repeat与空while是合法的
@@ -825,6 +870,13 @@ return function (vm, lines, uri)
related = related,
}
end)
+ -- 往表里面塞重复的field
+ session:doDiagnostics(session.searchDuplicateField, 'duplicate-field', function (key, related)
+ return {
+ message = lang.script('DIAG_DUPLICATE_FIELD', key),
+ related = related,
+ }
+ end)
-- 空代码块
session:doDiagnostics(session.searchEmptyBlock, 'empty-block', function ()
return {