diff options
author | sumneko <sumneko@hotmail.com> | 2019-05-30 11:13:40 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-05-30 11:13:40 +0800 |
commit | 9edc2fec3d060a8ef0b2fe230ffe5f91f37c7f2f (patch) | |
tree | 4c1e7f6f724aad98842b36196fdb20d293bb6410 /server | |
parent | 9ed437e427f3ecd0aed13e22458e5f6a20c962e2 (diff) | |
download | lua-language-server-9edc2fec3d060a8ef0b2fe230ffe5f91f37c7f2f.zip |
诊断设置常量
Diffstat (limited to 'server')
-rw-r--r-- | server/src/constant/DiagnosticDefaultSeverity.lua | 1 | ||||
-rw-r--r-- | server/src/core/diagnostics.lua | 38 | ||||
-rw-r--r-- | server/test/diagnostics/init.lua | 6 |
3 files changed, 45 insertions, 0 deletions
diff --git a/server/src/constant/DiagnosticDefaultSeverity.lua b/server/src/constant/DiagnosticDefaultSeverity.lua index 2088a922..eef44107 100644 --- a/server/src/constant/DiagnosticDefaultSeverity.lua +++ b/server/src/constant/DiagnosticDefaultSeverity.lua @@ -14,4 +14,5 @@ return { ['empty-block'] = 'Information', ['redundant-value'] = 'Information', ['emmy-lua'] = 'Warning', + ['set-const'] = 'Error', } diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index 93cf34d9..458a4686 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -631,6 +631,38 @@ function mt:searchEmmyLua(callback) end) end +function mt:searchSetConstLocal(callback) + local mark = {} + self.vm:eachSource(function (source) + local loc = source:bindLocal() + if not loc then + return + end + if mark[loc] then + return + end + mark[loc] = true + if not loc.tags then + return + end + local const + for _, tag in ipairs(loc.tags) do + if tag[1] == 'const' then + const = true + break + end + end + if not const then + return + end + loc:eachInfo(function (info, src) + if info.type == 'set' then + callback(src.start, src.finish) + end + end) + end) +end + function mt:doDiagnostics(func, code, callback) if config.config.diagnostics.disable[code] then return @@ -772,5 +804,11 @@ return function (vm, lines, uri) related = related, } end) + -- 检查给const变量赋值 + session:doDiagnostics(session.searchSetConstLocal, 'set-const', function () + return { + message = lang.script.DIAG_SET_CONST + } + end) return session.datas end diff --git a/server/test/diagnostics/init.lua b/server/test/diagnostics/init.lua index eec4bf36..7884df06 100644 --- a/server/test/diagnostics/init.lua +++ b/server/test/diagnostics/init.lua @@ -442,3 +442,9 @@ TEST [[ TEST [[ ---@class Class : any ]] + +TEST [[ +local <const> x = 1 +<!x!> = 2 +return x +]] |