diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-08-06 14:58:41 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-08-06 14:58:41 +0800 |
commit | f87c508bf3a45465c01241a0502041be9b693c08 (patch) | |
tree | f481699759f2c1e0aa8d1815cadf3bfac6ce80ab /server/src/core | |
parent | cffa66267a2c31fb13cdcf41e2c68dd549c9cc07 (diff) | |
download | lua-language-server-f87c508bf3a45465c01241a0502041be9b693c08.zip |
诊断重复的field
Diffstat (limited to 'server/src/core')
-rw-r--r-- | server/src/core/diagnostics.lua | 52 |
1 files changed, 52 insertions, 0 deletions
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 { |