Skip to content

Commit 77cc4b2

Browse files
authored
add cursorless.private.logQuickActions internal command (#2136)
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
1 parent 071258f commit 77cc4b2

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

packages/common/src/cursorlessCommandIds.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class VisibleCommand extends Command implements CommandDescription {
2525
export const cursorlessCommandIds = [
2626
"cursorless.command",
2727
"cursorless.internal.updateCheatsheetDefaults",
28+
"cursorless.private.logQuickActions",
2829
"cursorless.keyboard.escape",
2930
"cursorless.keyboard.modal.modeOff",
3031
"cursorless.keyboard.modal.modeOn",
@@ -86,6 +87,9 @@ export const cursorlessCommandDescriptions: Record<
8687
["cursorless.internal.updateCheatsheetDefaults"]: new HiddenCommand(
8788
"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.",
8889
),
90+
["cursorless.private.logQuickActions"]: new HiddenCommand(
91+
"Log the quick actions available at the current cursor position",
92+
),
8993
["cursorless.takeSnapshot"]: new HiddenCommand(
9094
"Take a snapshot of the current editor state",
9195
),

packages/cursorless-vscode/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"onView:cursorless.scopes",
5050
"onCommand:cursorless.command",
5151
"onCommand:cursorless.internal.updateCheatsheetDefaults",
52+
"onCommand:cursorless.private.logQuickActions",
5253
"onCommand:cursorless.keyboard.escape",
5354
"onCommand:cursorless.keyboard.modal.modeOff",
5455
"onCommand:cursorless.keyboard.modal.modeOn",
@@ -143,6 +144,11 @@
143144
"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.",
144145
"enablement": "false"
145146
},
147+
{
148+
"command": "cursorless.private.logQuickActions",
149+
"title": "Cursorless: Log the quick actions available at the current cursor position",
150+
"enablement": "false"
151+
},
146152
{
147153
"command": "cursorless.takeSnapshot",
148154
"title": "Cursorless: Take a snapshot of the current editor state",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { CodeAction, commands, window } from "vscode";
2+
3+
/**
4+
* Displays quick actions at the current cursor position in the active text
5+
* editor.
6+
* @param kind Optional parameter specifying the kind of quick actions to
7+
* display. Note that kinds are hierarchical, so if you pass a more generic
8+
* kind, the more specific sub-kinds will be logged.
9+
* @returns A promise that resolves to an array of available code actions.
10+
*/
11+
export async function logQuickActions(kind?: string) {
12+
const editor = window.activeTextEditor;
13+
14+
if (editor == null) {
15+
window.showErrorMessage("No active editor");
16+
return;
17+
}
18+
19+
const availableCodeActions = (
20+
await commands.executeCommand<CodeAction[]>(
21+
"vscode.executeCodeActionProvider",
22+
editor.document.uri,
23+
editor.selections[0],
24+
kind,
25+
)
26+
).map(({ title, kind, isPreferred }) => ({
27+
title,
28+
kind: kind?.value,
29+
isPreferred,
30+
}));
31+
32+
availableCodeActions.forEach((availableCodeAction) => {
33+
console.log(`${JSON.stringify(availableCodeAction, null, 2)}`);
34+
});
35+
36+
window.showInformationMessage(
37+
"Run command 'Developer: Toggle Developer Tools' to see available code actions",
38+
);
39+
40+
return availableCodeActions;
41+
}

packages/cursorless-vscode/src/registerCommands.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import {
1010
updateDefaults,
1111
} from "@cursorless/cursorless-engine";
1212
import * as vscode from "vscode";
13+
import { ScopeVisualizer } from "./ScopeVisualizerCommandApi";
1314
import { showDocumentation, showQuickPick } from "./commands";
1415
import { VscodeIDE } from "./ide/vscode/VscodeIDE";
1516
import { VscodeHats } from "./ide/vscode/hats/VscodeHats";
1617
import { KeyboardCommands } from "./keyboard/KeyboardCommands";
17-
import { ScopeVisualizer } from "./ScopeVisualizerCommandApi";
18+
import { logQuickActions } from "./logQuickActions";
1819

1920
export function registerCommands(
2021
extensionContext: vscode.ExtensionContext,
@@ -56,6 +57,8 @@ export function registerCommands(
5657
["cursorless.showQuickPick"]: showQuickPick,
5758
["cursorless.showDocumentation"]: showDocumentation,
5859

60+
["cursorless.private.logQuickActions"]: logQuickActions,
61+
5962
// Hats
6063
["cursorless.toggleDecorations"]: hats.toggle,
6164
["cursorless.recomputeDecorationStyles"]: hats.recomputeDecorationStyles,

0 commit comments

Comments
 (0)