-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters