diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-04-13 11:38:50 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-04-13 11:38:50 +0800 |
commit | 7ff91cdfa6cd43f0e3d628c94709db9dc5e2922f (patch) | |
tree | cb26ae5c0b19656d32cb38d0b44b2d5a1fb899c2 /script | |
parent | e4c388b1ec0aa9129d1339b09a15260cbf1f7489 (diff) | |
download | lua-language-server-7ff91cdfa6cd43f0e3d628c94709db9dc5e2922f.zip |
resolve #494 new diagnostic: `deprecated`
Diffstat (limited to 'script')
-rw-r--r-- | script/core/diagnostics/deprecated.lua | 76 | ||||
-rw-r--r-- | script/core/diagnostics/undefined-global.lua | 41 | ||||
-rw-r--r-- | script/proto/define.lua | 2 |
3 files changed, 78 insertions, 41 deletions
diff --git a/script/core/diagnostics/deprecated.lua b/script/core/diagnostics/deprecated.lua new file mode 100644 index 00000000..260ffc02 --- /dev/null +++ b/script/core/diagnostics/deprecated.lua @@ -0,0 +1,76 @@ +local files = require 'files' +local vm = require 'vm' +local lang = require 'language' +local guide = require 'core.guide' +local config = require 'config' +local define = require 'proto.define' + +return function (uri, callback) + local ast = files.getAst(uri) + if not ast then + return + end + + guide.eachSource(ast.ast, function (src) + if src.type ~= 'getglobal' + and src.type ~= 'getfield' + and src.type ~= 'getindex' + and src.type ~= 'getmethod' then + return + end + if src.type == 'getglobal' then + local key = guide.getKeyName(src) + if not key then + return + end + if config.config.diagnostics.globals[key] then + return + end + if config.config.runtime.special[key] then + return + end + end + + if not vm.isDeprecated(src, 0) then + return + end + + local defs = vm.getDefs(src, 0) + local validVersions + for _, def in ipairs(defs) do + if def.bindDocs then + for _, doc in ipairs(def.bindDocs) do + if doc.type == 'doc.version' then + validVersions = vm.getValidVersions(doc) + break + end + end + end + end + + local message = lang.script.DIAG_DEPRECATED + local versions + if validVersions then + versions = {} + for version, valid in pairs(validVersions) do + if valid then + versions[#versions+1] = version + end + end + table.sort(versions) + if #versions > 0 then + message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(versions, '/'), config.config.runtime.version)) + end + end + + callback { + start = src.start, + finish = src.finish, + tags = { define.DiagnosticTag.Deprecated }, + message = message, + data = { + versions = versions, + } + } + end) +end diff --git a/script/core/diagnostics/undefined-global.lua b/script/core/diagnostics/undefined-global.lua index cce08319..161d8856 100644 --- a/script/core/diagnostics/undefined-global.lua +++ b/script/core/diagnostics/undefined-global.lua @@ -42,46 +42,5 @@ return function (uri, callback) } return end - if not vm.isDeprecated(src, 0) then - return - end - - local message = lang.script('DIAG_UNDEF_GLOBAL', key) - local defs = vm.getDefs(src, 0) - local validVersions - for _, def in ipairs(defs) do - if def.bindDocs then - for _, doc in ipairs(def.bindDocs) do - if doc.type == 'doc.version' then - validVersions = vm.getValidVersions(doc) - break - end - end - end - end - - local versions - if validVersions then - versions = {} - for version, valid in pairs(validVersions) do - if valid then - versions[#versions+1] = version - end - end - table.sort(versions) - if #versions > 0 then - message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_VERSION', table.concat(versions, '/'), config.config.runtime.version)) - end - end - - callback { - start = src.start, - finish = src.finish, - tags = { define.DiagnosticTag.Deprecated }, - message = message, - data = { - versions = versions, - } - } end) end diff --git a/script/proto/define.lua b/script/proto/define.lua index 6bc3b891..75561e87 100644 --- a/script/proto/define.lua +++ b/script/proto/define.lua @@ -76,6 +76,7 @@ m.DiagnosticDefaultSeverity = { ['close-non-object'] = 'Warning', ['count-down-loop'] = 'Warning', ['no-implicit-any'] = 'Information', + ['deprecated'] = 'Warning', ['duplicate-doc-class'] = 'Warning', ['undefined-doc-class'] = 'Warning', @@ -126,6 +127,7 @@ m.DiagnosticDefaultNeededFileStatus = { ['close-non-object'] = 'Any', ['count-down-loop'] = 'Any', ['no-implicit-any'] = 'None', + ['deprecated'] = 'Any', ['duplicate-doc-class'] = 'Any', ['undefined-doc-class'] = 'Any', |