({ kind, title, requireExactlyOne = false, waitForMatch = true }: { kind?: vs.CodeActionKind, title?: string, requireExactlyOne?: boolean, waitForMatch?: boolean }, range: vs.Range)
| 708 | } |
| 709 | |
| 710 | export async function getCodeActions({ kind, title, requireExactlyOne = false, waitForMatch = true }: { kind?: vs.CodeActionKind, title?: string, requireExactlyOne?: boolean, waitForMatch?: boolean }, range: vs.Range) { |
| 711 | let codeActions: vs.CodeAction[] = []; |
| 712 | let matchingActions = await waitFor(async () => { |
| 713 | codeActions = await vs.commands.executeCommand<vs.CodeAction[]>("vscode.executeCodeActionProvider", currentDoc().uri, range); |
| 714 | const matchingActions = codeActions.filter((ca) => (!kind || kind.contains(ca.kind!)) && (!title || ca.title === title)); |
| 715 | return (!waitForMatch || matchingActions.length) ? matchingActions : undefined; |
| 716 | }); |
| 717 | |
| 718 | matchingActions ??= []; |
| 719 | |
| 720 | if (requireExactlyOne && matchingActions.length !== 1) |
| 721 | throw new Error(`Expected to find "${kind?.value}/${title}", but found ${codeActions.map((ca) => `"${ca.kind?.value}/${ca.title}"`).join(", ")}`); |
| 722 | |
| 723 | return matchingActions; |
| 724 | } |
| 725 | |
| 726 | export async function executeCodeAction({ kind, title }: { kind?: vs.CodeActionKind, title?: string }, range: vs.Range) { |
| 727 | const matchingActions = await getCodeActions({ kind, title, requireExactlyOne: true }, range); |
no test coverage detected