File tree Expand file tree Collapse file tree 6 files changed +53
-5
lines changed
Expand file tree Collapse file tree 6 files changed +53
-5
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,11 @@ DIAG_GLOBAL_ELEMENT =
171171DIAG_MISSING_FIELDS =
172172' Missing fields: {}'
173173DIAG_INJECT_FIELD =
174- ' Fields cannot be injected into the reference of `{class}` for `{field}`. To do so, use `---@class` for `{node}`.'
174+ ' Fields cannot be injected into the reference of `{class}` for `{field}`. {fix}'
175+ DIAG_INJECT_FIELD_FIX_CLASS =
176+ ' To do so, use `---@class` for `{node}`.'
177+ DIAG_INJECT_FIELD_FIX_TABLE = -- TODO: need translate!
178+ ' 如要允许注入,请在定义中添加 `{fix}` 。'
175179
176180MWS_NOT_SUPPORT =
177181' {} does not support multi workspace for now, I may need to restart to support the new workspace ...'
Original file line number Diff line number Diff line change @@ -171,7 +171,11 @@ DIAG_GLOBAL_ELEMENT = -- TODO: need translate!
171171DIAG_MISSING_FIELDS = -- TODO: need translate!
172172' Missing fields: {}'
173173DIAG_INJECT_FIELD = -- TODO: need translate!
174- ' Fields cannot be injected into the reference of `{class}` for `{field}`. To do so, use `---@class` for `{node}`.'
174+ ' Fields cannot be injected into the reference of `{class}` for `{field}`. {fix}'
175+ DIAG_INJECT_FIELD_FIX_CLASS = -- TODO: need translate!
176+ ' To do so, use `---@class` for `{node}`.'
177+ DIAG_INJECT_FIELD_FIX_TABLE = -- TODO: need translate!
178+ ' 如要允许注入,请在定义中添加 `{fix}` 。'
175179
176180MWS_NOT_SUPPORT =
177181' {} não é suportado múltiplos espaços de trabalho por enquanto, posso precisar reiniciar para estabelecer um novo espaço de trabalho ...'
Original file line number Diff line number Diff line change @@ -171,7 +171,11 @@ DIAG_GLOBAL_ELEMENT =
171171DIAG_MISSING_FIELDS =
172172' 缺少字段: {}'
173173DIAG_INJECT_FIELD =
174- ' 不能在 `{class}` 的引用中注入字段 `{field}` 。如要这么做,请对 `{node}` 使用 `---@class` 。'
174+ ' 不能在 `{class}` 的引用中注入字段 `{field}` 。{fix}'
175+ DIAG_INJECT_FIELD_FIX_CLASS =
176+ ' 如要允许注入,请对 `{node}` 使用 `{fix}` 。'
177+ DIAG_INJECT_FIELD_FIX_TABLE =
178+ ' 如要允许注入,请在定义中添加 `{fix}` 。'
175179
176180MWS_NOT_SUPPORT =
177181' {} 目前还不支持多工作目录,我可能需要重启才能支持新的工作目录...'
Original file line number Diff line number Diff line change @@ -171,7 +171,11 @@ DIAG_GLOBAL_ELEMENT = -- TODO: need translate!
171171DIAG_MISSING_FIELDS = -- TODO: need translate!
172172' Missing fields: {}'
173173DIAG_INJECT_FIELD = -- TODO: need translate!
174- ' Fields cannot be injected into the reference of `{class}` for `{field}`. To do so, use `---@class` for `{node}`.'
174+ ' Fields cannot be injected into the reference of `{class}` for `{field}`. {fix}'
175+ DIAG_INJECT_FIELD_FIX_CLASS = -- TODO: need translate!
176+ ' To do so, use `---@class` for `{node}`.'
177+ DIAG_INJECT_FIELD_FIX_TABLE = -- TODO: need translate!
178+ ' 如要允许注入,请在定义中添加 `{fix}` 。'
175179
176180MWS_NOT_SUPPORT =
177181' {} 目前還不支援多工作目錄,我可能需要重新啟動才能支援新的工作目錄...'
Original file line number Diff line number Diff line change @@ -47,12 +47,28 @@ return function (uri, callback)
4747 if dnode and vm .getDefinedClass (uri , dnode ) then
4848 return
4949 end
50+ if def .type == ' doc.type.field' then
51+ return
52+ end
53+ end
54+
55+ local howToFix = lang .script (' DIAG_INJECT_FIELD_FIX_CLASS' , {
56+ node = hname (node ),
57+ fix = ' ---@class' ,
58+ })
59+ for _ , ndef in ipairs (vm .getDefs (node )) do
60+ if ndef .type == ' doc.type.table' then
61+ howToFix = lang .script (' DIAG_INJECT_FIELD_FIX_TABLE' , {
62+ fix = ' [any]: any' ,
63+ })
64+ break
65+ end
5066 end
5167
5268 local message = lang .script (' DIAG_INJECT_FIELD' , {
5369 class = vm .getInfer (node ):view (uri ),
5470 field = guide .getKeyName (src ),
55- node = hname ( node ) ,
71+ fix = howToFix ,
5672 })
5773 if src .type == ' setfield' and src .field then
5874 callback {
Original file line number Diff line number Diff line change @@ -23,3 +23,19 @@ local m
2323m.xx = 1 -- OK
2424m.yy = 1 -- OK
2525]]
26+
27+ TEST [[
28+ ---@type { xx: number }
29+ local m
30+
31+ m.xx = 1 -- OK
32+ m.<!yy!> = 1 -- Warning
33+ ]]
34+
35+ TEST [[
36+ ---@type { xx: number, [any]: any }
37+ local m
38+
39+ m.xx = 1 -- OK
40+ m.yy = 1 -- OK
41+ ]]
You can’t perform that action at this time.
0 commit comments