Allow multiple code actions if there is more than one SuggestedCorrection of a diagnostic record returned by PSSA#1713
Conversation
|
Thanks @bergmeister! Just to double check, this is backwards compatible right? Like it won't break things with the current version of PSSA? |
|
Yes. Nothing is changing in PSSA's interface, which is the DiagnosticRecord object. This PR fixes PSES to actually treat the SuggestedCorrections property as an array, which it is and therefore also returning a code action for each one instead of just only one for the first one. Even with the current version of PSSA one can write a custom rule that returns multiple suggested corrections. Just to be sure I also tested that the code action for the most common case of diagnostic records having just one suggested correction still works. |
|
Your PR is proving hard to work on; I don't know what's going on, but every time I checkout your branch I'm getting a grafted commit. I'm going to cherry pick it to a new branch. |
|
Uh, weird, I tried to cherry pick a13202c and got |
|
Weird indeed, have you tried doing that in a new clone as well in case the git db of your everyday PSES got issues. Or maybe there was a commit hash conflict since my fork is a different repo and although chances are very low, thery are not zero... |
|
@bergmeister Not a clue! I did cherry-pick over to here if you want to double check #1718 |
|
Fixed in #1718! Closing. Thanks @bergmeister! |
|
This is out in PowerShell Preview v2022.2.2! |
Currently, PSSA's
SuggestCorrectionsproperty of theDiagnosticRecordobject already is an array but no built-in rules return more than one suggested correction, which lead toPowerShellEditorServicesnot correctly translating this array before returning it as an code action but it only ever displayed one. This fixes it makes it generic again so it returns a code action for each suggest correction. It's basically just performing a foreach loop and callingToTextEditjust once, a diff that ignored whitespace due to increased indentation will make this much clearerThis is a pre-requisite for an implementation of this, where a built-inrule will return multiple suggest corrections: PowerShell/PSScriptAnalyzer#1767
I've manually tested this with a modified version of PSSA where I return 2 suggested corrections and when I build the PS extension with this change, the UI shows me the two different suggested code actions and also applies them correctly (as in they are different as they should be by design)