-
-
Notifications
You must be signed in to change notification settings - Fork 386
improve the missing-fields logic to be able to correctly handle classes defined several times #2770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sumneko
merged 11 commits into
LuaLS:master
from
NeOzay:inconsistent-behavior-(missing-fields)
Aug 1, 2024
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3ce73be
improve diagnosis (missing-fields).
NeOzay 0b8102e
improve missing-fields diagnostic logic
NeOzay 7582afd
update changelog
NeOzay 69c992d
Merge branch 'master' into inconsistent-behavior-(missing-fields)
NeOzay c084104
also detects missing index fields
NeOzay eca4758
Merge commit 'c08410458924a9f3c604e662cfce80f0f86d5b78' into inconsis…
NeOzay f706a96
Update changelog.md
NeOzay 9035afd
Update script/core/diagnostics/missing-fields.lua
NeOzay df9db56
compute table keys once
NeOzay 3b5947f
Merge branch 'master' into inconsistent-behavior-(missing-fields)
NeOzay 585cc20
Merge branch 'master' into inconsistent-behavior-(missing-fields)
sumneko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -15,61 +15,74 @@ return function (uri, callback) | |
| guide.eachSourceType(state.ast, 'table', function (src) | ||
| await.delay() | ||
|
|
||
| vm.removeNode(src) -- the node is not updated correctly, reason still unknown | ||
| local defs = vm.getDefs(src) | ||
| local sortedDefs = {} | ||
| for _, def in ipairs(defs) do | ||
| if def.type == 'doc.class' and def.bindSource then | ||
| if guide.isInRange(def.bindSource, src.start) then | ||
| if def.type == 'doc.class' then | ||
| if def.bindSource and guide.isInRange(def.bindSource, src.start) then | ||
| return | ||
| end | ||
| local className = def.class[1] | ||
| if not sortedDefs[className] then | ||
| sortedDefs[className] = {} | ||
| end | ||
| local samedefs = sortedDefs[className] | ||
| samedefs[#samedefs+1] = def | ||
| end | ||
| if def.type == 'doc.type.array' | ||
| or def.type == 'doc.type.table' then | ||
| return | ||
| end | ||
| end | ||
| local warnings = {} | ||
| for _, def in ipairs(defs) do | ||
| if def.type == 'doc.class' then | ||
| if not def.fields then | ||
| return | ||
| end | ||
|
|
||
| local requiresKeys = {} | ||
| 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 | ||
| local warnings = {} | ||
| for _, samedefs in pairs(sortedDefs) do | ||
| local missedKeys = {} | ||
| local className | ||
| for _, def in ipairs(samedefs) do | ||
| className = def.class[1] | ||
NeOzay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if not def.fields or #def.fields == 0 then | ||
| goto continue | ||
| end | ||
|
|
||
| if #requiresKeys == 0 then | ||
| return | ||
| end | ||
| local myKeys = {} | ||
| for _, field in ipairs(src) do | ||
| local key = vm.getKeyName(field) | ||
| local key = vm.getKeyName(field) or field.tindex | ||
| 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 | ||
| for _, field in ipairs(def.fields) do | ||
| if not field.optional | ||
| and not vm.compileNode(field):isNullable() then | ||
| local key = vm.getKeyName(field) | ||
| if not key then | ||
| local fieldnode = vm.compileNode(field.field)[1] | ||
| if fieldnode and fieldnode.type == 'doc.type.integer' then | ||
| ---@cast fieldnode parser.object | ||
| key = vm.getKeyName(fieldnode) | ||
| end | ||
| end | ||
|
|
||
| if #missedKeys == 0 then | ||
| return | ||
| if key and not myKeys[key] then | ||
| if type(key) == "number" then | ||
| missedKeys[#missedKeys+1] = ('`[%s]`'):format(key) | ||
| else | ||
| missedKeys[#missedKeys+1] = ('`%s`'):format(key) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| ::continue:: | ||
| end | ||
|
|
||
| warnings[#warnings+1] = lang.script('DIAG_MISSING_FIELDS', def.class[1], table.concat(missedKeys, ', ')) | ||
| if #missedKeys == 0 then | ||
| return | ||
| end | ||
|
|
||
| warnings[#warnings+1] = lang.script('DIAG_MISSING_FIELDS', className, table.concat(missedKeys, ', ')) | ||
| end | ||
|
|
||
| if #warnings == 0 then | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.