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 - tweak API for the SCM sync view #193470

Merged
merged 1 commit into from
Sep 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 12 additions & 21 deletions src/vs/workbench/api/browser/mainThreadSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
this._quickDiff.dispose();
this._quickDiff = undefined;
}

if (features.hasHistoryProvider && !this._historyProvider) {
this._historyProvider = {
actionButton: () => this._historyProviderActionButton ?? undefined,
currentHistoryItemGroup: () => this._historyProviderCurrentHistoryItemGroup ?? undefined,
provideHistoryItems: (historyItemGroupId, options) => this.provideHistoryItems(historyItemGroupId, options),
provideHistoryItemChanges: (historyItemId: string) => this.provideHistoryItemChanges(historyItemId),
resolveHistoryItemGroupCommonAncestor: (historyItemGroupId1, historyItemGroupId2) => this.resolveHistoryItemGroupCommonAncestor(historyItemGroupId1, historyItemGroupId2),
};
} else if (features.hasHistoryProvider === false && this._historyProvider) {
this._historyProvider = undefined;
}
}

$registerGroups(_groups: [number /*handle*/, string /*id*/, string /*label*/, SCMGroupFeatures][]): void {
Expand Down Expand Up @@ -305,16 +317,6 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
return result && URI.revive(result);
}

$registerHistoryProvider(): void {
this._historyProvider = {
actionButton: () => this._historyProviderActionButton ?? undefined,
currentHistoryItemGroup: () => this._historyProviderCurrentHistoryItemGroup ?? undefined,
provideHistoryItems: (historyItemGroupId, options) => this.provideHistoryItems(historyItemGroupId, options),
provideHistoryItemChanges: (historyItemId: string) => this.provideHistoryItemChanges(historyItemId),
resolveHistoryItemGroupCommonAncestor: (historyItemGroupId1, historyItemGroupId2) => this.resolveHistoryItemGroupCommonAncestor(historyItemGroupId1, historyItemGroupId2),
};
}

$onDidChangeHistoryProviderActionButton(actionButton?: SCMActionButtonDto | null): void {
this._historyProviderActionButton = actionButton;
this._onDidChangeHistoryProviderActionButton.fire();
Expand Down Expand Up @@ -551,17 +553,6 @@ export class MainThreadSCM implements MainThreadSCMShape {
}
}

$registerHistoryProvider(sourceControlHandle: number): void {
const repository = this._repositories.get(sourceControlHandle);

if (!repository) {
return;
}

const provider = repository.provider as MainThreadSCMProvider;
provider.$registerHistoryProvider();
}

$onDidChangeHistoryProviderActionButton(sourceControlHandle: number, actionButton?: SCMActionButtonDto | null | undefined): void {
const repository = this._repositories.get(sourceControlHandle);

Expand Down
9 changes: 7 additions & 2 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,7 @@ export interface MainThreadExtensionServiceShape extends IDisposable {
}

export interface SCMProviderFeatures {
hasHistoryProvider?: boolean;
hasQuickDiffProvider?: boolean;
quickDiffLabel?: string;
count?: number;
Expand Down Expand Up @@ -1404,7 +1405,12 @@ export type SCMRawResourceSplices = [
export interface SCMHistoryItemGroupDto {
readonly id: string;
readonly label: string;
readonly upstream?: SCMHistoryItemGroupDto;
readonly upstream?: SCMRemoteHistoryItemGroupDto;
}

export interface SCMRemoteHistoryItemGroupDto {
readonly id: string;
readonly label: string;
}

export interface SCMHistoryItemDto {
Expand Down Expand Up @@ -1442,7 +1448,6 @@ export interface MainThreadSCMShape extends IDisposable {
$showValidationMessage(sourceControlHandle: number, message: string | IMarkdownString, type: InputValidationType): void;
$setValidationProviderIsEnabled(sourceControlHandle: number, enabled: boolean): void;

$registerHistoryProvider(sourceControlHandle: number): void;
$onDidChangeHistoryProviderActionButton(sourceControlHandle: number, actionButton?: SCMActionButtonDto | null): void;
$onDidChangeHistoryProviderCurrentHistoryItemGroup(sourceControlHandle: number, historyItemGroup: SCMHistoryItemGroupDto | undefined): void;
}
Expand Down
44 changes: 21 additions & 23 deletions src/vs/workbench/api/common/extHostSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,34 +548,32 @@ class ExtHostSourceControl implements vscode.SourceControl {
this._historyProvider = historyProvider;
this._historyProviderDisposable.value = new DisposableStore();

if (!historyProvider) {
return;
}
this.#proxy.$updateSourceControl(this.handle, { hasHistoryProvider: !!historyProvider });

this.#proxy.$registerHistoryProvider(this.handle);

this._historyProviderDisposable.value.add(historyProvider.onDidChangeCurrentHistoryItemGroup(() => {
if (historyItemGroupEquals(this._historyProviderCurrentHistoryItemGroup, historyProvider?.currentHistoryItemGroup)) {
return;
}
if (historyProvider) {
this._historyProviderDisposable.value.add(historyProvider.onDidChangeCurrentHistoryItemGroup(() => {
if (historyItemGroupEquals(this._historyProviderCurrentHistoryItemGroup, historyProvider?.currentHistoryItemGroup)) {
return;
}

this._historyProviderCurrentHistoryItemGroup = historyProvider?.currentHistoryItemGroup;
this.#proxy.$onDidChangeHistoryProviderCurrentHistoryItemGroup(this.handle, this._historyProviderCurrentHistoryItemGroup);
}));
this._historyProviderCurrentHistoryItemGroup = historyProvider?.currentHistoryItemGroup;
this.#proxy.$onDidChangeHistoryProviderCurrentHistoryItemGroup(this.handle, this._historyProviderCurrentHistoryItemGroup);
}));

this._historyProviderDisposable.value.add(historyProvider.onDidChangeActionButton(() => {
checkProposedApiEnabled(this._extension, 'scmActionButton');
this._historyProviderDisposable.value.add(historyProvider.onDidChangeActionButton(() => {
checkProposedApiEnabled(this._extension, 'scmActionButton');

this._historyProviderActionButtonDisposable.value = new DisposableStore();
const internal = historyProvider.actionButton !== undefined ?
{
command: this._commands.converter.toInternal(historyProvider.actionButton.command, this._historyProviderActionButtonDisposable.value),
description: historyProvider.actionButton.description,
enabled: historyProvider.actionButton.enabled
} : undefined;
this._historyProviderActionButtonDisposable.value = new DisposableStore();
const internal = historyProvider.actionButton !== undefined ?
{
command: this._commands.converter.toInternal(historyProvider.actionButton.command, this._historyProviderActionButtonDisposable.value),
description: historyProvider.actionButton.description,
enabled: historyProvider.actionButton.enabled
} : undefined;

this.#proxy.$onDidChangeHistoryProviderActionButton(this.handle, internal ?? null);
}));
this.#proxy.$onDidChangeHistoryProviderActionButton(this.handle, internal ?? null);
}));
}
}

private _commitTemplate: string | undefined = undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/browser/scm.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ viewsRegistry.registerViews([{
id: SYNC_VIEW_PANE_ID,
name: localize('source control sync', "Source Control Sync"),
ctorDescriptor: new SyncDescriptor(SCMSyncViewPane),
canToggleVisibility: false,
canToggleVisibility: true,
canMoveView: true,
weight: 20,
order: -998,
Expand Down
6 changes: 5 additions & 1 deletion src/vs/workbench/contrib/scm/browser/scmSyncViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ export class SCMSyncViewPane extends ViewPane {
this._viewModel = this.instantiationService.createInstance(SCMSyncPaneViewModel, this._tree);
}

protected override layoutBody(height: number, width: number): void {
super.layoutBody(height, width);
this._tree.layout(height, width);
}

private async onDidOpen(e: IOpenEvent<TreeElement | undefined>): Promise<void> {
if (!e.element) {
return;
Expand Down Expand Up @@ -464,7 +469,6 @@ class SCMSyncPaneViewModel {
// Multiple repositories or always show repositories
await this.tree.setInput([...this.repositories.keys()], { expanded });
}
this.tree.layout();
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/vs/workbench/contrib/scm/common/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export interface ISCMHistoryOptions {
export interface ISCMHistoryItemGroup {
readonly id: string;
readonly label: string;
readonly upstream?: ISCMHistoryItemGroup;
readonly upstream?: ISCMRemoteHistoryItemGroup;
}

export interface ISCMRemoteHistoryItemGroup {
readonly id: string;
readonly label: string;
}

export interface ISCMHistoryItem {
Expand Down
7 changes: 6 additions & 1 deletion src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ declare module 'vscode' {
export interface SourceControlHistoryItemGroup {
readonly id: string;
readonly label: string;
readonly upstream?: SourceControlHistoryItemGroup;
readonly upstream?: SourceControlRemoteHistoryItemGroup;
}

export interface SourceControlRemoteHistoryItemGroup {
readonly id: string;
readonly label: string;
}

export interface SourceControlHistoryItem {
Expand Down