Skip to content

Commit

Permalink
SCM - switch action button to observable to avoid using the onDidChan…
Browse files Browse the repository at this point in the history
…ge event (#229958)
  • Loading branch information
lszomoru committed Sep 27, 2024
1 parent e4f4c45 commit f429fff
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/vs/workbench/api/browser/mainThreadSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
get contextValue(): string { return this._providerId; }

get acceptInputCommand(): Command | undefined { return this.features.acceptInputCommand; }
get actionButton(): ISCMActionButtonDescriptor | undefined { return this.features.actionButton ?? undefined; }

private readonly _count = observableValue<number | undefined>(this, undefined);
get count() { return this._count; }
Expand All @@ -285,6 +284,9 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
private readonly _commitTemplate = observableValue<string>(this, '');
get commitTemplate() { return this._commitTemplate; }

private readonly _actionButton = observableValue<ISCMActionButtonDescriptor | undefined>(this, undefined);
get actionButton(): IObservable<ISCMActionButtonDescriptor | undefined> { return this._actionButton; }

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

Expand Down Expand Up @@ -323,6 +325,10 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
this._commitTemplate.set(features.commitTemplate, undefined);
}

if (typeof features.actionButton !== 'undefined') {
this._actionButton.set(features.actionButton, undefined);
}

if (typeof features.count !== 'undefined') {
this._count.set(features.count, undefined);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ export interface SCMProviderFeatures {
count?: number;
commitTemplate?: string;
acceptInputCommand?: languages.Command;
actionButton?: SCMActionButtonDto | null;
actionButton?: SCMActionButtonDto;
statusBarCommands?: ICommandDto[];
}

Expand Down
16 changes: 13 additions & 3 deletions src/vs/workbench/api/common/extHostSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { checkProposedApiEnabled, isProposedApiEnabled } from '../../services/ex
import { ExtHostDocuments } from './extHostDocuments.js';
import { Schemas } from '../../../base/common/network.js';
import { isLinux } from '../../../base/common/platform.js';
import { structuralEquals } from '../../../base/common/equals.js';

type ProviderHandle = number;
type GroupHandle = number;
Expand Down Expand Up @@ -654,13 +655,21 @@ class ExtHostSourceControl implements vscode.SourceControl {
checkProposedApiEnabled(this._extension, 'scmActionButton');
return this._actionButton;
}

set actionButton(actionButton: vscode.SourceControlActionButton | undefined) {
checkProposedApiEnabled(this._extension, 'scmActionButton');
this._actionButtonDisposables.value = new DisposableStore();

// We have to do this check before converting the command to it's internal
// representation since that would always create a command with a unique
// identifier
if (structuralEquals(this._actionButton, actionButton)) {
return;
}

this._actionButton = actionButton;
this._actionButtonDisposables.value = new DisposableStore();

const internal = actionButton !== undefined ?
const actionButtonDto = actionButton !== undefined ?
{
command: {
...this._commands.converter.toInternal(actionButton.command, this._actionButtonDisposables.value),
Expand All @@ -671,7 +680,8 @@ class ExtHostSourceControl implements vscode.SourceControl {
}),
enabled: actionButton.enabled
} satisfies SCMActionButtonDto : undefined;
this.#proxy.$updateSourceControl(this.handle, { actionButton: internal ?? null });

this.#proxy.$updateSourceControl(this.handle, { actionButton: actionButtonDto });
}


Expand Down
9 changes: 7 additions & 2 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2449,7 +2449,12 @@ export class SCMViewPane extends ViewPane {
for (const repository of added) {
const repositoryDisposables = new DisposableStore();

repositoryDisposables.add(repository.provider.onDidChange(() => this.updateChildren(repository)));
repositoryDisposables.add(autorun(reader => {
/** @description action button */
repository.provider.actionButton.read(reader);
this.updateChildren(repository);
}));

repositoryDisposables.add(repository.input.onDidChangeVisibility(() => this.updateChildren(repository)));
repositoryDisposables.add(repository.provider.onDidChangeResourceGroups(() => this.updateChildren(repository)));

Expand Down Expand Up @@ -2835,7 +2840,7 @@ class SCMTreeDataSource extends Disposable implements IAsyncDataSource<ISCMViewS
const children: TreeElement[] = [];

inputOrElement = isSCMRepository(inputOrElement) ? inputOrElement : this.scmViewService.visibleRepositories[0];
const actionButton = inputOrElement.provider.actionButton;
const actionButton = inputOrElement.provider.actionButton.get();
const resourceGroups = inputOrElement.provider.groups;

// SCM Input
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/scm/common/scm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface ISCMProvider extends IDisposable {
readonly commitTemplate: IObservable<string>;
readonly historyProvider: IObservable<ISCMHistoryProvider | undefined>;
readonly acceptInputCommand?: Command;
readonly actionButton?: ISCMActionButtonDescriptor;
readonly actionButton: IObservable<ISCMActionButtonDescriptor | undefined>;
readonly statusBarCommands: IObservable<readonly Command[] | undefined>;
readonly onDidChange: Event<void>;

Expand Down Expand Up @@ -124,7 +124,7 @@ export interface ISCMActionButtonDescriptor {
export interface ISCMActionButton {
readonly type: 'actionButton';
readonly repository: ISCMRepository;
readonly button?: ISCMActionButtonDescriptor;
readonly button: ISCMActionButtonDescriptor;
}

export interface ISCMInput {
Expand Down

0 comments on commit f429fff

Please sign in to comment.