-
-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# changelog | ||
|
||
## 3.6.24 | ||
* `NEW` diagnostic: `missing-fields` | ||
* `FIX` shake of `codeLens` | ||
* `FIX` [#2145] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
local vm = require 'vm' | ||
local files = require 'files' | ||
local guide = require 'parser.guide' | ||
local await = require 'await' | ||
|
||
---@async | ||
return function (uri, callback) | ||
local state = files.getState(uri) | ||
if not state then | ||
return | ||
end | ||
|
||
---@async | ||
guide.eachSourceType(state.ast, 'table', function (src) | ||
await.delay() | ||
|
||
local defs = vm.getDefs(src) | ||
local requiresKeys = {} | ||
for _, def in ipairs(defs) do | ||
if def.type == 'doc.class' then | ||
if not def.fields then | ||
goto continue | ||
end | ||
if def.bindSource then | ||
if guide.isInRange(def.bindSource, src.start) then | ||
goto continue | ||
end | ||
end | ||
for _, field in ipairs(def.fields) do | ||
if not field.optional | ||
and not vm.compileNode(field):isNullable() then | ||
local key = vm.getKeyName(field) | ||
if key and not requiresKeys[key] then | ||
requiresKeys[key] = true | ||
requiresKeys[#requiresKeys+1] = key | ||
end | ||
end | ||
end | ||
end | ||
::continue:: | ||
end | ||
|
||
if #requiresKeys == 0 then | ||
return | ||
end | ||
|
||
local myKeys = {} | ||
for _, field in ipairs(src) do | ||
local key = vm.getKeyName(field) | ||
if key then | ||
myKeys[key] = true | ||
end | ||
end | ||
|
||
local missedKeys = {} | ||
for _, key in ipairs(requiresKeys) do | ||
if not myKeys[key] then | ||
missedKeys[#missedKeys+1] = ('`%s`'):format(key) | ||
end | ||
end | ||
|
||
if #missedKeys == 0 then | ||
return | ||
end | ||
|
||
callback { | ||
start = src.start, | ||
finish = src.finish, | ||
message = string.format('Missing fields: %s', table.concat(missedKeys, ', ')), | ||
} | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,7 @@ m.ints = {} | |
]] | ||
|
||
TEST [[ | ||
---@diagnostic disable: missing-fields | ||
---@class A | ||
---@field x A | ||
|