Skip to content

Commit

Permalink
add cursorless.private.logQuickActions internal command (#2136)
Browse files Browse the repository at this point in the history
Useful for development as we add new Cursorless actions based on VSCode
quick actions. We should prob put this in
#1775 once that
exists, but until then, seems harmless here

## Checklist

- [-] I have added
[tests](https://www.cursorless.org/docs/contributing/test-case-recorder/)
- [-] I have updated the
[docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and
[cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet)
- [-] I have not broken the cheatsheet
  • Loading branch information
pokey authored Dec 16, 2023
1 parent 071258f commit 77cc4b2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/common/src/cursorlessCommandIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
),
Expand Down
6 changes: 6 additions & 0 deletions packages/cursorless-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
41 changes: 41 additions & 0 deletions packages/cursorless-vscode/src/logQuickActions.ts
Original file line number Diff line number Diff line change
@@ -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<CodeAction[]>(
"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;
}
5 changes: 4 additions & 1 deletion packages/cursorless-vscode/src/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 77cc4b2

Please sign in to comment.