diff --git a/packages/common/src/cursorlessCommandIds.ts b/packages/common/src/cursorlessCommandIds.ts index fb9b0fc7de..031698e479 100644 --- a/packages/common/src/cursorlessCommandIds.ts +++ b/packages/common/src/cursorlessCommandIds.ts @@ -25,6 +25,7 @@ class VisibleCommand extends Command implements CommandDescription { export const cursorlessCommandIds = [ "cursorless.command", "cursorless.internal.updateCheatsheetDefaults", + "cursorless.private.logQuickActions", "cursorless.keyboard.escape", "cursorless.keyboard.modal.modeOff", "cursorless.keyboard.modal.modeOn", @@ -86,6 +87,9 @@ export const cursorlessCommandDescriptions: Record< ["cursorless.internal.updateCheatsheetDefaults"]: new HiddenCommand( "Update the default values of the cheatsheet payload used on the website and for local development. Be sure to run this on stock community and cursorless.", ), + ["cursorless.private.logQuickActions"]: new HiddenCommand( + "Log the quick actions available at the current cursor position", + ), ["cursorless.takeSnapshot"]: new HiddenCommand( "Take a snapshot of the current editor state", ), diff --git a/packages/cursorless-vscode/package.json b/packages/cursorless-vscode/package.json index bd3eb3ee9a..51fb21eced 100644 --- a/packages/cursorless-vscode/package.json +++ b/packages/cursorless-vscode/package.json @@ -49,6 +49,7 @@ "onView:cursorless.scopes", "onCommand:cursorless.command", "onCommand:cursorless.internal.updateCheatsheetDefaults", + "onCommand:cursorless.private.logQuickActions", "onCommand:cursorless.keyboard.escape", "onCommand:cursorless.keyboard.modal.modeOff", "onCommand:cursorless.keyboard.modal.modeOn", @@ -143,6 +144,11 @@ "title": "Cursorless: Update the default values of the cheatsheet payload used on the website and for local development. Be sure to run this on stock community and cursorless.", "enablement": "false" }, + { + "command": "cursorless.private.logQuickActions", + "title": "Cursorless: Log the quick actions available at the current cursor position", + "enablement": "false" + }, { "command": "cursorless.takeSnapshot", "title": "Cursorless: Take a snapshot of the current editor state", diff --git a/packages/cursorless-vscode/src/logQuickActions.ts b/packages/cursorless-vscode/src/logQuickActions.ts new file mode 100644 index 0000000000..cbd4f2afd3 --- /dev/null +++ b/packages/cursorless-vscode/src/logQuickActions.ts @@ -0,0 +1,41 @@ +import { CodeAction, commands, window } from "vscode"; + +/** + * Displays quick actions at the current cursor position in the active text + * editor. + * @param kind Optional parameter specifying the kind of quick actions to + * display. Note that kinds are hierarchical, so if you pass a more generic + * kind, the more specific sub-kinds will be logged. + * @returns A promise that resolves to an array of available code actions. + */ +export async function logQuickActions(kind?: string) { + const editor = window.activeTextEditor; + + if (editor == null) { + window.showErrorMessage("No active editor"); + return; + } + + const availableCodeActions = ( + await commands.executeCommand( + "vscode.executeCodeActionProvider", + editor.document.uri, + editor.selections[0], + kind, + ) + ).map(({ title, kind, isPreferred }) => ({ + title, + kind: kind?.value, + isPreferred, + })); + + availableCodeActions.forEach((availableCodeAction) => { + console.log(`${JSON.stringify(availableCodeAction, null, 2)}`); + }); + + window.showInformationMessage( + "Run command 'Developer: Toggle Developer Tools' to see available code actions", + ); + + return availableCodeActions; +} diff --git a/packages/cursorless-vscode/src/registerCommands.ts b/packages/cursorless-vscode/src/registerCommands.ts index a6a5e08a8d..cbaae38ed8 100644 --- a/packages/cursorless-vscode/src/registerCommands.ts +++ b/packages/cursorless-vscode/src/registerCommands.ts @@ -10,11 +10,12 @@ import { updateDefaults, } from "@cursorless/cursorless-engine"; import * as vscode from "vscode"; +import { ScopeVisualizer } from "./ScopeVisualizerCommandApi"; import { showDocumentation, showQuickPick } from "./commands"; import { VscodeIDE } from "./ide/vscode/VscodeIDE"; import { VscodeHats } from "./ide/vscode/hats/VscodeHats"; import { KeyboardCommands } from "./keyboard/KeyboardCommands"; -import { ScopeVisualizer } from "./ScopeVisualizerCommandApi"; +import { logQuickActions } from "./logQuickActions"; export function registerCommands( extensionContext: vscode.ExtensionContext, @@ -56,6 +57,8 @@ export function registerCommands( ["cursorless.showQuickPick"]: showQuickPick, ["cursorless.showDocumentation"]: showDocumentation, + ["cursorless.private.logQuickActions"]: logQuickActions, + // Hats ["cursorless.toggleDecorations"]: hats.toggle, ["cursorless.recomputeDecorationStyles"]: hats.recomputeDecorationStyles,