Skip to content
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

Allow multiple code actions if there is more than one SuggestedCorrection of a diagnostic record returned by PSSA #1713

Closed

Conversation

bergmeister
Copy link
Contributor

@bergmeister bergmeister commented Feb 16, 2022

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 lead to PowerShellEditorServices not 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 calling ToTextEdit just once, a diff that ignored whitespace due to increased indentation will make this much clearer
This 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)

@bergmeister bergmeister changed the title Allow multiple code action if there is more than one SuggestedCorrection of a diagnostic record returned by PSSA Allow multiple code actions if there is more than one SuggestedCorrection of a diagnostic record returned by PSSA Feb 16, 2022
@andyleejordan
Copy link
Member

Thanks @bergmeister! Just to double check, this is backwards compatible right? Like it won't break things with the current version of PSSA?

@bergmeister
Copy link
Contributor Author

bergmeister commented Feb 18, 2022

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.

@andyleejordan
Copy link
Member

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.

@andyleejordan
Copy link
Member

Uh, weird, I tried to cherry pick a13202c and got fatal: bad object a13202cb487285766d04479edf8a3cf21086a4c9

@bergmeister
Copy link
Contributor Author

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...
Well the change is small, so manually copying it over to another branch is fine anyway

@andyleejordan
Copy link
Member

@bergmeister Not a clue! I did cherry-pick over to here if you want to double check #1718

@andyleejordan
Copy link
Member

Fixed in #1718! Closing. Thanks @bergmeister!

@andyleejordan
Copy link
Member

This is out in PowerShell Preview v2022.2.2!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants