diff options
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/constant/DiagnosticDefaultSeverity.lua | 1 | ||||
-rw-r--r-- | server/src/core/diagnostics.lua | 52 |
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 { |