◐ Shell
clean mode source ↗

Return a code action for each diagnostic record by andyleejordan · Pull Request #1718 · PowerShell/PowerShellEditorServices

and others added 2 commits

February 18, 2022 16:34
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.

@andyleejordan andyleejordan changed the title Andschwa/multiple codeactions Return a code action for each diagnostic record

Feb 19, 2022

SeeminglyScience

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>