MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / getCodeActions

Function getCodeActions

src/test/helpers.ts:710–724  ·  view source on GitHub ↗
({ kind, title, requireExactlyOne = false, waitForMatch = true }: { kind?: vs.CodeActionKind, title?: string, requireExactlyOne?: boolean, waitForMatch?: boolean }, range: vs.Range)

Source from the content-addressed store, hash-verified

708}
709
710export 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
726export async function executeCodeAction({ kind, title }: { kind?: vs.CodeActionKind, title?: string }, range: vs.Range) {
727 const matchingActions = await getCodeActions({ kind, title, requireExactlyOne: true }, range);

Calls 2

waitForFunction · 0.90
currentDocFunction · 0.85

Tested by

no test coverage detected