Skip to content

Commit

Permalink
new diag: inject-field
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Aug 14, 2023
1 parent 525d095 commit 63edb99
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions locale/en-us/script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...'
Expand Down
2 changes: 2 additions & 0 deletions locale/pt-br/script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...'
Expand Down
2 changes: 2 additions & 0 deletions locale/zh-cn/script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ DIAG_GLOBAL_ELEMENT =
'全局变量。'
DIAG_MISSING_FIELDS =
'缺少字段: {}'
DIAG_INJECT_FIELD =
'不能在 `{class}` 的引用中注入字段 `{field}` 。如要这么做,请对 `{node}` 使用 `---@class` 。'

MWS_NOT_SUPPORT =
'{} 目前还不支持多工作目录,我可能需要重启才能支持新的工作目录...'
Expand Down
2 changes: 2 additions & 0 deletions locale/zh-tw/script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
'{} 目前還不支援多工作目錄,我可能需要重新啟動才能支援新的工作目錄...'
Expand Down
37 changes: 28 additions & 9 deletions script/core/diagnostics/inject-field.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 63edb99

Please sign in to comment.