diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-08-14 14:21:37 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-08-14 14:21:37 +0800 |
commit | 63edb992a363a97dfa3f02a988f5f7771d5b0b03 (patch) | |
tree | 3be9e8ee2cfd6bcdae73630293b7fc1d3821dd0e /script/core | |
parent | 525d095c55c696a36f67caae5e4e8f631e10c116 (diff) | |
download | lua-language-server-63edb992a363a97dfa3f02a988f5f7771d5b0b03.zip |
new diag: `inject-field`
#1990
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/diagnostics/inject-field.lua | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/script/core/diagnostics/inject-field.lua b/script/core/diagnostics/inject-field.lua index 62e1d1ca..2e1fc93c 100644 --- a/script/core/diagnostics/inject-field.lua +++ b/script/core/diagnostics/inject-field.lua @@ -3,6 +3,7 @@ local vm = require 'vm' local lang = require 'language' local guide = require 'parser.guide' local await = require 'await' +local hname = require 'core.hover.name' local skipCheckClass = { ['unknown'] = true, @@ -22,19 +23,37 @@ return function (uri, callback) await.delay() local node = src.node - if node then - local ok - for view in vm.getInfer(node):eachView(uri) do - if skipCheckClass[view] then - return - end - ok = true + if not node then + return + end + local ok + for view in vm.getInfer(node):eachView(uri) do + if skipCheckClass[view] then + return end - if not ok then + ok = true + end + if not ok then + return + end + + local class = vm.getDefinedClass(uri, node) + if class then + return + end + + for _, def in ipairs(vm.getDefs(src)) do + local dnode = def.node + if dnode and vm.getDefinedClass(uri, dnode) then return end end - local message = lang.script('DIAG_INJECT_FIELD', guide.getKeyName(src)) + + local message = lang.script('DIAG_INJECT_FIELD', { + class = vm.getInfer(node):view(uri), + field = guide.getKeyName(src), + node = hname(node), + }) if src.type == 'setfield' and src.field then callback { start = src.field.start, |