I am creating a VS Code extension. I want to add a custom button to the Git message field of the VS Code Source Control tab?
To be specific location, please see the screenshot below:
I want to add a custom button to this location. Just like GitHub Copilot did.
So my question are:
You need to use the contribSourceControlInputBoxMenu
API proposal. See also its issue ticket: SourceControl - SourceControlInputBoxValueProvider API proposal #195474.
The API proposal is current empty. At a previous point in time, it looked like this:
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ declare module 'vscode' { // https://github.com/microsoft/vscode/issues/195474 export namespace scm { export function registerSourceControlInputBoxValueProvider(sourceControlId: string, provider: SourceControlInputBoxValueProvider): Disposable; } export interface SourceControlInputBoxValueProviderContext { readonly resourceGroupId: string; readonly resources: readonly Uri[]; } export interface SourceControlInputBoxValueProvider { readonly label: string; readonly icon?: Uri | { light: Uri; dark: Uri } | ThemeIcon; provideValue(rootUri: Uri, context: SourceControlInputBoxValueProviderContext[], token: CancellationToken): ProviderResult<string | undefined>; } }
You could take a look at the GitHub Copilot Chat extension's minified code as an example (download VSIX, rename filename extension to ".zip", unzip). In its extension manifest, it has this:
"scm/inputBox": [ { "command": "github.copilot.git.generateCommitMessage", "when": "scmProvider == git" } ]
See also https://code.visualstudio.com/api/advanced-topics/using-proposed-api.
When the API still existed, the way to change the value of the input box was vscode.extensions.getExtension('vscode.git')?.exports.getAPI(1).repositories[0].inputBox.value = newvalue;
.
Note that later versions of GitHub Copilot started using the scminput
language instead of the scm/inputbox
menu contribution point (see the github.copilot.enable
setting).