Return a code action for each diagnostic record#1718
Merged
andyleejordan merged 2 commits intomasterfrom Feb 23, 2022
Merged
Conversation
Currently, PSSA's `SuggestCorrections` property of the `DiagnosticRecord` object already is an array, but no built-in rules return more than one suggested correction, which led to `PowerShellEditorServices` not correctly translating this array before returning it as an code action as it only ever displayed one. This fixes it by making it generic again so it returns a code action for each suggest correction. It's basically just performing a `foreach` loop and calling `ToTextEdit` just once. This is a pre-requisite for an implementation of this, where a built-in rule will return multiple suggest corrections: PowerShell/PSScriptAnalyzer#1767 I've manually tested this with a modified version of PSScriptAnalyzer where I return two suggested corrections. The extension's UI now shows me the two different suggested code actions and also applies them correctly.
Contributor
|
Sorry, forgot about this one. Since this change is slightly different, will re-test just to confirm |
Member
Author
|
The actual changes should be no different, I cherry-picked the commit: a4c4fdf |
Contributor
|
Ok, just seeing the other changes made me think there is a chance it could affect it. I tested with the latest preview extension since it's already released and can confirm it still works the way I tested it with my own build :-) |
Member
Author
|
Yay! Thanks for testing!! |
andyleejordan
added a commit
that referenced
this pull request
Mar 31, 2022
With the recent fix in PR #1718, PSES processes now all Correction objects from PSSA but the message specifically was just taken from the last correction here. I did not notice this at first because I thought I had to tweak my rule first to emit two different messages until I realized it was another bug in PSES. Related: PowerShell/PSScriptAnalyzer#1782 Co-authored-by: Andy Schwartzmeyer <andrew@schwartzmeyer.com>
Closed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, PSSA's
SuggestCorrectionsproperty of theDiagnosticRecordobject already is an array, but no built-in rulesreturn more than one suggested correction, which led to
PowerShellEditorServicesnot correctly translating this array beforereturning it as an code action as it only ever displayed one. This fixes
it by making it generic again so it returns a code action for each
suggest correction. It's basically just performing a
foreachloop andcalling
ToTextEditjust once.This is a pre-requisite for an implementation of this, where a built-in
rule will return multiple suggest corrections:
PowerShell/PSScriptAnalyzer#1767
I've manually tested this with a modified version of PSScriptAnalyzer
where I return two suggested corrections. The extension's UI now shows
me the two different suggested code actions and also applies them
correctly.
Replaces #1713.