Create new VS Code commands with all required boilerplate
Scaffold a new VS Code command with all required boilerplate.
/add-command [name]
myNewFeature (becomes gitlens.myNewFeature)GlCommandBase — No editor required (opening panels, showing pickers)ActiveEditorCommand — Requires active editorActiveEditorCachedCommand — Like ActiveEditorCommand with "repeat last command" support:views, :graph, :scm suffixes for context menussrc/commands/{commandName}.tsimport type { TextEditor, Uri } from 'vscode';
import type { Container } from '../container.js';
import { command } from '../system/-webview/command.js';
import { {BaseClass} } from './commandBase.js';
export interface {CommandName}CommandArgs {
// Define args if needed
}
@command()
export class {CommandName}Command extends {BaseClass} {
constructor(private readonly container: Container) {
super([
'gitlens.{commandId}',
// Add variants here
]);
}
async execute(editor?: TextEditor, uri?: Uri, args?: {CommandName}CommandArgs): Promise<void> {
// TODO: Implement
}
}
src/commands.tsimport './commands/{commandName}.js';
contributions.jsonUnder "commands" key:
"gitlens.{commandId}": {
"label": "{Label}",
"category": "GitLens",
"commandPalette": "gitlens:enabled"
}
For :views variant:
"gitlens.{commandId}:views": {
"label": "{Label}",
"icon": "$(icon-name)",
"menus": {
"view/item/context": [{
"when": "viewItem =~ /gitlens:/ && gitlens:enabled",
"group": "1_gitlens"
}]
}
}
pnpm run generate:contributions && pnpm run generate:commandTypes
when Clausesgitlens:enabled — Extension is enabled!gitlens:readonly — Not in readonly mode!gitlens:untrusted — Workspace is trustedgitlens:plus — Pro features availableviewItem =~ /gitlens:commit/ — On a commit nodeviewItem =~ /gitlens:branch/ — On a branch node