diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | locale/en-us/script.lua | 2 | ||||
-rw-r--r-- | locale/pt-br/script.lua | 2 | ||||
-rw-r--r-- | locale/zh-cn/script.lua | 2 | ||||
-rw-r--r-- | locale/zh-tw/script.lua | 2 | ||||
-rw-r--r-- | script/core/diagnostics/inject-field.lua | 37 |
6 files changed, 37 insertions, 9 deletions
diff --git a/changelog.md b/changelog.md index bbfd1250..61f5eeca 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,7 @@ ## 3.7.0 * `NEW` support `---@type` and `--[[@as]]` for return statement * `NEW` commandline parameter `--force-accept-workspace`: allowing the use of the root directory or home directory as the workspace +* `NEW` diagnostic: `inject-field` * `FIX` wrong hover and signature for method with varargs and overloads * `FIX` [#2155] * `FIX` [#2224] diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index dd8c3fa9..ff89fb75 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -170,6 +170,8 @@ DIAG_GLOBAL_ELEMENT = 'Element is global.' DIAG_MISSING_FIELDS = 'Missing fields: {}' +DIAG_INJECT_FIELD = +'Fields cannot be injected into the reference of `{class}` for `{field}`. To do so, use `---@class` for `{node}`.' MWS_NOT_SUPPORT = '{} does not support multi workspace for now, I may need to restart to support the new workspace ...' diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua index 22f42820..969ad5cf 100644 --- a/locale/pt-br/script.lua +++ b/locale/pt-br/script.lua @@ -170,6 +170,8 @@ DIAG_GLOBAL_ELEMENT = -- TODO: need translate! 'Element is global.' DIAG_MISSING_FIELDS = -- TODO: need translate! 'Missing fields: {}' +DIAG_INJECT_FIELD = -- TODO: need translate! +'Fields cannot be injected into the reference of `{class}` for `{field}`. To do so, use `---@class` for `{node}`.' MWS_NOT_SUPPORT = '{} não é suportado múltiplos espaços de trabalho por enquanto, posso precisar reiniciar para estabelecer um novo espaço de trabalho ...' diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index be0cad3b..ef408533 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -170,6 +170,8 @@ DIAG_GLOBAL_ELEMENT = '全局变量。' DIAG_MISSING_FIELDS = '缺少字段: {}' +DIAG_INJECT_FIELD = +'不能在 `{class}` 的引用中注入字段 `{field}` 。如要这么做,请对 `{node}` 使用 `---@class` 。' MWS_NOT_SUPPORT = '{} 目前还不支持多工作目录,我可能需要重启才能支持新的工作目录...' diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua index 995ada56..bcd7af44 100644 --- a/locale/zh-tw/script.lua +++ b/locale/zh-tw/script.lua @@ -170,6 +170,8 @@ DIAG_GLOBAL_ELEMENT = -- TODO: need translate! 'Element is global.' DIAG_MISSING_FIELDS = -- TODO: need translate! 'Missing fields: {}' +DIAG_INJECT_FIELD = -- TODO: need translate! +'Fields cannot be injected into the reference of `{class}` for `{field}`. To do so, use `---@class` for `{node}`.' MWS_NOT_SUPPORT = '{} 目前還不支援多工作目錄,我可能需要重新啟動才能支援新的工作目錄...' 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, |