Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCM - add input box value provider proposal #198232

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/vs/workbench/api/browser/mainThreadSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import { URI, UriComponents } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
import { IDisposable, DisposableStore, combinedDisposable, dispose } from 'vs/base/common/lifecycle';
import { ISCMService, ISCMRepository, ISCMProvider, ISCMResource, ISCMResourceGroup, ISCMResourceDecorations, IInputValidation, ISCMViewService, InputValidationType, ISCMActionButtonDescriptor } from 'vs/workbench/contrib/scm/common/scm';
import { IDisposable, DisposableStore, combinedDisposable, dispose, DisposableMap } from 'vs/base/common/lifecycle';
import { ISCMService, ISCMRepository, ISCMProvider, ISCMResource, ISCMResourceGroup, ISCMResourceDecorations, IInputValidation, ISCMViewService, InputValidationType, ISCMActionButtonDescriptor, ISCMInputValueProvider, ISCMInputValueProviderContext } from 'vs/workbench/contrib/scm/common/scm';
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape, SCMProviderFeatures, SCMRawResourceSplices, SCMGroupFeatures, MainContext, SCMHistoryItemDto, SCMActionButtonDto, SCMHistoryItemGroupDto, SCMInputActionButtonDto } from '../common/extHost.protocol';
import { Command } from 'vs/editor/common/languages';
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
Expand Down Expand Up @@ -45,6 +45,19 @@ function getSCMHistoryItemIcon(historyItem: SCMHistoryItemDto): URI | { light: U
}
}

function getIconFromIconDto(iconDto?: UriComponents | { light: UriComponents; dark: UriComponents } | ThemeIcon): URI | { light: URI; dark: URI } | ThemeIcon | undefined {
if (iconDto === undefined) {
return undefined;
} else if (URI.isUri(iconDto)) {
return URI.revive(iconDto);
} else if (ThemeIcon.isThemeIcon(iconDto)) {
return iconDto;
} else {
const icon = iconDto as { light: UriComponents; dark: UriComponents };
return { light: URI.revive(icon.light), dark: URI.revive(icon.dark) };
}
}

class MainThreadSCMResourceGroup implements ISCMResourceGroup {

readonly resources: ISCMResource[] = [];
Expand Down Expand Up @@ -422,12 +435,27 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
}
}

class MainThreadSCMInputBoxValueProvider implements ISCMInputValueProvider {

constructor(
private readonly proxy: ExtHostSCMShape,
private readonly handle: number,
readonly label: string,
readonly icon?: URI | ThemeIcon | { light: URI; dark: URI }) { }

provideValue(repositoryId: string, context: ISCMInputValueProviderContext[]): Promise<string | undefined> {
return this.proxy.$provideInputBoxValue(this.handle, repositoryId, context);
}

}

@extHostNamedCustomer(MainContext.MainThreadSCM)
export class MainThreadSCM implements MainThreadSCMShape {

private readonly _proxy: ExtHostSCMShape;
private _repositories = new Map<number, ISCMRepository>();
private _repositoryDisposables = new Map<number, IDisposable>();
private _inputBoxValueProviders = new DisposableMap<number>();
private readonly _disposables = new DisposableStore();

constructor(
Expand All @@ -447,6 +475,7 @@ export class MainThreadSCM implements MainThreadSCMShape {
dispose(this._repositoryDisposables.values());
this._repositoryDisposables.clear();

this._inputBoxValueProviders.dispose();
this._disposables.dispose();
}

Expand Down Expand Up @@ -496,6 +525,23 @@ export class MainThreadSCM implements MainThreadSCMShape {
this._repositories.delete(handle);
}

$registerSourceControlInputBoxValueProvider(handle: number, label: string, icon?: UriComponents | { light: UriComponents; dark: UriComponents } | ThemeIcon): void {
const provider = new MainThreadSCMInputBoxValueProvider(this._proxy, handle, label, getIconFromIconDto(icon));
const disposable = this.scmService.registerSCMInputValueProvider(provider);

this._inputBoxValueProviders.set(handle, disposable);
}

$unregisterSourceControlInputBoxValueProvider(handle: number): void {
const provider = this._inputBoxValueProviders.get(handle);
if (!provider) {
return;
}

provider.dispose();
this._inputBoxValueProviders.deleteAndDispose(handle);
}

$registerGroups(sourceControlHandle: number, groups: [number /*handle*/, string /*id*/, string /*label*/, SCMGroupFeatures][], splices: SCMRawResourceSplices[]): void {
const repository = this._repositories.get(sourceControlHandle);

Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,10 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
},
createSourceControl(id: string, label: string, rootUri?: vscode.Uri) {
return extHostSCM.createSourceControl(extension, id, label, rootUri);
},
registerSourceControlInputBoxValueProvider(provider: vscode.SourceControlInputBoxValueProvider): vscode.Disposable {
checkProposedApiEnabled(extension, 'scmInputBoxValueProvider');
return extHostSCM.registerSourceControlInputBoxValueProvider(extension, provider);
}
};

Expand Down
4 changes: 4 additions & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,9 @@ export interface MainThreadSCMShape extends IDisposable {

$onDidChangeHistoryProviderActionButton(sourceControlHandle: number, actionButton?: SCMActionButtonDto | null): void;
$onDidChangeHistoryProviderCurrentHistoryItemGroup(sourceControlHandle: number, historyItemGroup: SCMHistoryItemGroupDto | undefined): void;

$registerSourceControlInputBoxValueProvider(inputBoxValueProviderHandle: number, label: string, icon?: ThemeIcon | UriComponents | { light: UriComponents; dark: UriComponents }): void;
$unregisterSourceControlInputBoxValueProvider(inputBoxValueProviderHandle: number): void;
}

export interface MainThreadQuickDiffShape extends IDisposable {
Expand Down Expand Up @@ -2216,6 +2219,7 @@ export interface ExtHostTerminalServiceShape {

export interface ExtHostSCMShape {
$provideOriginalResource(sourceControlHandle: number, uri: UriComponents, token: CancellationToken): Promise<UriComponents | null>;
$provideInputBoxValue(inputBoxValueProviderHandle: number, sourceControlId: string, context: any): Promise<string | undefined>;
$onInputBoxValueChange(sourceControlHandle: number, value: string): void;
$executeResourceCommand(sourceControlHandle: number, groupHandle: number, handle: number, preserveFocus: boolean): Promise<void>;
$validateInput(sourceControlHandle: number, value: string, cursorPosition: number): Promise<[string | IMarkdownString, number] | undefined>;
Expand Down
40 changes: 39 additions & 1 deletion src/vs/workbench/api/common/extHostSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { URI, UriComponents } from 'vs/base/common/uri';
import { Event, Emitter } from 'vs/base/common/event';
import { debounce } from 'vs/base/common/decorators';
import { DisposableStore, IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';
import { DisposableStore, IDisposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { asPromise } from 'vs/base/common/async';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceSplice, SCMRawResourceSplices, IMainContext, ExtHostSCMShape, ICommandDto, MainThreadTelemetryShape, SCMGroupFeatures, SCMHistoryItemDto, SCMHistoryItemChangeDto, SCMHistoryItemGroupDto } from './extHost.protocol';
Expand Down Expand Up @@ -71,6 +71,19 @@ function getHistoryItemIconDto(historyItem: vscode.SourceControlHistoryItem): Ur
}
}

function getSourceControlInputBoxValueProviderIcon(provider: vscode.SourceControlInputBoxValueProvider): UriComponents | { light: UriComponents; dark: UriComponents } | ThemeIcon | undefined {
if (!provider.icon) {
return undefined;
} else if (URI.isUri(provider.icon)) {
return provider.icon;
} else if (ThemeIcon.isThemeIcon(provider.icon)) {
return provider.icon;
} else {
const icon = provider.icon as { light: URI; dark: URI };
return { light: icon.light, dark: icon.dark };
}
}

function compareResourceThemableDecorations(a: vscode.SourceControlResourceThemableDecorations, b: vscode.SourceControlResourceThemableDecorations): number {
if (!a.iconPath && !b.iconPath) {
return 0;
Expand Down Expand Up @@ -809,6 +822,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
export class ExtHostSCM implements ExtHostSCMShape {

private static _handlePool: number = 0;
private static _inputBoxValueProviderHandlePool: number = 0;

private _proxy: MainThreadSCMShape;
private readonly _telemetry: MainThreadTelemetryShape;
Expand All @@ -818,6 +832,8 @@ export class ExtHostSCM implements ExtHostSCMShape {
private readonly _onDidChangeActiveProvider = new Emitter<vscode.SourceControl>();
get onDidChangeActiveProvider(): Event<vscode.SourceControl> { return this._onDidChangeActiveProvider.event; }

private _inputBoxValueProviders: Map<number, vscode.SourceControlInputBoxValueProvider> = new Map<number, vscode.SourceControlInputBoxValueProvider>();

private _selectedSourceControlHandle: number | undefined;

constructor(
Expand Down Expand Up @@ -892,6 +908,28 @@ export class ExtHostSCM implements ExtHostSCMShape {
return sourceControl;
}

registerSourceControlInputBoxValueProvider(extension: IExtensionDescription, provider: vscode.SourceControlInputBoxValueProvider): vscode.Disposable {
this.logService.trace('ExtHostSCM#registerSourceControlInputBoxValueProvider', extension.identifier.value, provider.label);

const handle = ExtHostSCM._inputBoxValueProviderHandlePool++;
this._inputBoxValueProviders.set(handle, provider);
this._proxy.$registerSourceControlInputBoxValueProvider(handle, provider.label, getSourceControlInputBoxValueProviderIcon(provider));

return toDisposable(() => {
this._proxy.$unregisterSourceControlInputBoxValueProvider(handle);
this._inputBoxValueProviders.delete(handle);
});
}

async $provideInputBoxValue(inputBoxValueProviderHandle: number, sourceControlId: string, context: vscode.SourceControlInputBoxValueProviderContext[]): Promise<string | undefined> {
const provider = this._inputBoxValueProviders.get(inputBoxValueProviderHandle);
if (!provider) {
return undefined;
}

return await provider.provideValue(sourceControlId, context, CancellationToken.None) ?? undefined;
}

// Deprecated
getLastInputBox(extension: IExtensionDescription): ExtHostSCMInputBox | undefined {
this.logService.trace('ExtHostSCM#getLastInputBox', extension.identifier.value);
Expand Down
16 changes: 16 additions & 0 deletions src/vs/workbench/contrib/scm/common/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ export interface ISCMProvider extends IDisposable {
getOriginalResource(uri: URI): Promise<URI | null>;
}

export interface ISCMInputValueProviderContext {
readonly resourceGroupId: string;
readonly resources: readonly URI[];
}

export interface ISCMInputValueProvider {
readonly label: string;
readonly icon?: URI | { light: URI; dark: URI } | ThemeIcon;
provideValue(repositoryId: string, context: ISCMInputValueProviderContext[]): Promise<string | undefined>;
}

export const enum InputValidationType {
Error = 0,
Warning = 1,
Expand Down Expand Up @@ -173,6 +184,11 @@ export interface ISCMService {

registerSCMProvider(provider: ISCMProvider): ISCMRepository;
getRepository(id: string): ISCMRepository | undefined;

readonly onDidChangeInputValueProviders: Event<void>;
readonly inputValueProviders: Iterable<ISCMInputValueProvider>;

registerSCMInputValueProvider(provider: ISCMInputValueProvider): IDisposable;
}

export interface ISCMTitleMenu {
Expand Down
19 changes: 18 additions & 1 deletion src/vs/workbench/contrib/scm/common/scmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { Event, Emitter } from 'vs/base/common/event';
import { ISCMService, ISCMProvider, ISCMInput, ISCMRepository, IInputValidator, ISCMInputChangeEvent, SCMInputChangeReason, InputValidationType, IInputValidation, ISCMActionButtonDescriptor } from './scm';
import { ISCMService, ISCMProvider, ISCMInput, ISCMRepository, IInputValidator, ISCMInputChangeEvent, SCMInputChangeReason, InputValidationType, IInputValidation, ISCMActionButtonDescriptor, ISCMInputValueProvider } from './scm';
import { ILogService } from 'vs/platform/log/common/log';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
Expand Down Expand Up @@ -365,12 +365,18 @@ export class SCMService implements ISCMService {
private inputHistory: SCMInputHistory;
private providerCount: IContextKey<number>;

private readonly _inputValueProviders = new Set<ISCMInputValueProvider>();
get inputValueProviders(): Iterable<ISCMInputValueProvider> { return this._inputValueProviders; }

private readonly _onDidAddProvider = new Emitter<ISCMRepository>();
readonly onDidAddRepository: Event<ISCMRepository> = this._onDidAddProvider.event;

private readonly _onDidRemoveProvider = new Emitter<ISCMRepository>();
readonly onDidRemoveRepository: Event<ISCMRepository> = this._onDidRemoveProvider.event;

private readonly _onDidChangeInputValueProviders = new Emitter<void>();
readonly onDidChangeInputValueProviders: Event<void> = this._onDidChangeInputValueProviders.event;

constructor(
@ILogService private readonly logService: ILogService,
@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
Expand Down Expand Up @@ -405,4 +411,15 @@ export class SCMService implements ISCMService {
getRepository(id: string): ISCMRepository | undefined {
return this._repositories.get(id);
}

registerSCMInputValueProvider(provider: ISCMInputValueProvider): IDisposable {
this._inputValueProviders.add(provider);
this._onDidChangeInputValueProviders.fire();

return toDisposable(() => {
this._inputValueProviders.delete(provider);
this._onDidChangeInputValueProviders.fire();
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const allApiProposals = Object.freeze({
scmActionButton: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmActionButton.d.ts',
scmHistoryProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts',
scmInputBoxActionButton: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmInputBoxActionButton.d.ts',
scmInputBoxValueProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmInputBoxValueProvider.d.ts',
scmSelectedProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmSelectedProvider.d.ts',
scmTextDocument: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmTextDocument.d.ts',
scmValidation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmValidation.d.ts',
Expand Down
25 changes: 25 additions & 0 deletions src/vscode-dts/vscode.proposed.scmInputBoxValueProvider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*---------------------------------------------------------------------------------------------
* 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(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(sourceControlId: string, context: SourceControlInputBoxValueProviderContext[], token: CancellationToken): ProviderResult<string | undefined>;
}

}
Loading