Skip to content

SCM - all calls from extHostSCM to mainThreadSCM should use a sequencer to ensure that the source control object is created #213792

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

Merged
merged 1 commit into from
May 29, 2024
Merged
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
52 changes: 27 additions & 25 deletions src/vs/workbench/api/common/extHostSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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 { asPromise } from 'vs/base/common/async';
import { asPromise, Sequencer } 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 } from './extHost.protocol';
import { sortedDiff, equals } from 'vs/base/common/arrays';
Expand Down Expand Up @@ -259,7 +259,7 @@ export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {

set value(value: string) {
value = value ?? '';
this.#proxy.$setInputBoxValue(this._sourceControlHandle, value);
this._sequencer.queue(async () => this.#proxy.$setInputBoxValue(this._sourceControlHandle, value));
this.updateValue(value);
}

Expand All @@ -276,7 +276,7 @@ export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
}

set placeholder(placeholder: string) {
this.#proxy.$setInputBoxPlaceholder(this._sourceControlHandle, placeholder);
this._sequencer.queue(async () => this.#proxy.$setInputBoxPlaceholder(this._sourceControlHandle, placeholder));
this._placeholder = placeholder;
}

Expand All @@ -296,7 +296,7 @@ export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
}

this._validateInput = fn;
this.#proxy.$setValidationProviderIsEnabled(this._sourceControlHandle, !!fn);
this._sequencer.queue(async () => this.#proxy.$setValidationProviderIsEnabled(this._sourceControlHandle, !!fn));
}

private _enabled: boolean = true;
Expand All @@ -313,7 +313,7 @@ export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
}

this._enabled = enabled;
this.#proxy.$setInputBoxEnablement(this._sourceControlHandle, enabled);
this._sequencer.queue(async () => this.#proxy.$setInputBoxEnablement(this._sourceControlHandle, enabled));
}

private _visible: boolean = true;
Expand All @@ -330,7 +330,7 @@ export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
}

this._visible = visible;
this.#proxy.$setInputBoxVisibility(this._sourceControlHandle, visible);
this._sequencer.queue(async () => this.#proxy.$setInputBoxVisibility(this._sourceControlHandle, visible));
}

get document(): vscode.TextDocument {
Expand All @@ -339,15 +339,15 @@ export class ExtHostSCMInputBox implements vscode.SourceControlInputBox {
return this.#extHostDocuments.getDocument(this._documentUri);
}

constructor(private _extension: IExtensionDescription, _extHostDocuments: ExtHostDocuments, proxy: MainThreadSCMShape, private _sourceControlHandle: number, private _documentUri: URI) {
constructor(private _extension: IExtensionDescription, _extHostDocuments: ExtHostDocuments, proxy: MainThreadSCMShape, private _sequencer: Sequencer, private _sourceControlHandle: number, private _documentUri: URI) {
this.#extHostDocuments = _extHostDocuments;
this.#proxy = proxy;
}

showValidationMessage(message: string | vscode.MarkdownString, type: vscode.SourceControlInputBoxValidationType) {
checkProposedApiEnabled(this._extension, 'scmValidation');

this.#proxy.$showValidationMessage(this._sourceControlHandle, message, type as any);
this._sequencer.queue(async () => this.#proxy.$showValidationMessage(this._sourceControlHandle, message, type as any));
}

$onInputBoxValueChange(value: string): void {
Expand Down Expand Up @@ -386,14 +386,14 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
get label(): string { return this._label; }
set label(label: string) {
this._label = label;
this._proxy.$updateGroupLabel(this._sourceControlHandle, this.handle, label);
this._sequencer.queue(async () => this._proxy.$updateGroupLabel(this._sourceControlHandle, this.handle, label));
}

private _hideWhenEmpty: boolean | undefined = undefined;
get hideWhenEmpty(): boolean | undefined { return this._hideWhenEmpty; }
set hideWhenEmpty(hideWhenEmpty: boolean | undefined) {
this._hideWhenEmpty = hideWhenEmpty;
this._proxy.$updateGroup(this._sourceControlHandle, this.handle, this.features);
this._sequencer.queue(async () => this._proxy.$updateGroup(this._sourceControlHandle, this.handle, this.features));
}

get features(): SCMGroupFeatures {
Expand All @@ -413,6 +413,7 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
constructor(
private _proxy: MainThreadSCMShape,
private _commands: ExtHostCommands,
private _sequencer: Sequencer,
private _sourceControlHandle: number,
private _id: string,
private _label: string,
Expand Down Expand Up @@ -511,6 +512,7 @@ class ExtHostSourceControl implements vscode.SourceControl {

#proxy: MainThreadSCMShape;

private readonly _sequencer = new Sequencer();
private _groups: Map<GroupHandle, ExtHostSourceControlResourceGroup> = new Map<GroupHandle, ExtHostSourceControlResourceGroup>();

get id(): string {
Expand Down Expand Up @@ -540,7 +542,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
}

this._count = count;
this.#proxy.$updateSourceControl(this.handle, { count });
this._sequencer.queue(async () => this.#proxy.$updateSourceControl(this.handle, { count }));
}

private _quickDiffProvider: vscode.QuickDiffProvider | undefined = undefined;
Expand All @@ -555,7 +557,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
if (isProposedApiEnabled(this._extension, 'quickDiffProvider')) {
quickDiffLabel = quickDiffProvider?.label;
}
this.#proxy.$updateSourceControl(this.handle, { hasQuickDiffProvider: !!quickDiffProvider, quickDiffLabel });
this._sequencer.queue(async () => this.#proxy.$updateSourceControl(this.handle, { hasQuickDiffProvider: !!quickDiffProvider, quickDiffLabel }));
}

private _historyProvider: vscode.SourceControlHistoryProvider | undefined;
Expand All @@ -573,12 +575,12 @@ class ExtHostSourceControl implements vscode.SourceControl {
this._historyProvider = historyProvider;
this._historyProviderDisposable.value = new DisposableStore();

this.#proxy.$updateSourceControl(this.handle, { hasHistoryProvider: !!historyProvider });
this._sequencer.queue(async () => this.#proxy.$updateSourceControl(this.handle, { hasHistoryProvider: !!historyProvider }));

if (historyProvider) {
this._historyProviderDisposable.value.add(historyProvider.onDidChangeCurrentHistoryItemGroup(() => {
this._historyProviderCurrentHistoryItemGroup = historyProvider?.currentHistoryItemGroup;
this.#proxy.$onDidChangeHistoryProviderCurrentHistoryItemGroup(this.handle, this._historyProviderCurrentHistoryItemGroup);
this._sequencer.queue(async () => this.#proxy.$onDidChangeHistoryProviderCurrentHistoryItemGroup(this.handle, this._historyProviderCurrentHistoryItemGroup));
}));
}
}
Expand All @@ -595,7 +597,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
}

this._commitTemplate = commitTemplate;
this.#proxy.$updateSourceControl(this.handle, { commitTemplate });
this._sequencer.queue(async () => this.#proxy.$updateSourceControl(this.handle, { commitTemplate }));
}

private readonly _acceptInputDisposables = new MutableDisposable<DisposableStore>();
Expand All @@ -611,7 +613,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
this._acceptInputCommand = acceptInputCommand;

const internal = this._commands.converter.toInternal(acceptInputCommand, this._acceptInputDisposables.value);
this.#proxy.$updateSourceControl(this.handle, { acceptInputCommand: internal });
this._sequencer.queue(async () => this.#proxy.$updateSourceControl(this.handle, { acceptInputCommand: internal }));
}

private readonly _actionButtonDisposables = new MutableDisposable<DisposableStore>();
Expand All @@ -635,7 +637,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
description: actionButton.description,
enabled: actionButton.enabled
} : undefined;
this.#proxy.$updateSourceControl(this.handle, { actionButton: internal ?? null });
this._sequencer.queue(async () => this.#proxy.$updateSourceControl(this.handle, { actionButton: internal ?? null }));
}


Expand All @@ -656,7 +658,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
this._statusBarCommands = statusBarCommands;

const internal = (statusBarCommands || []).map(c => this._commands.converter.toInternal(c, this._statusBarDisposables.value!)) as ICommandDto[];
this.#proxy.$updateSourceControl(this.handle, { statusBarCommands: internal });
this._sequencer.queue(async () => this.#proxy.$updateSourceControl(this.handle, { statusBarCommands: internal }));
}

private _selected: boolean = false;
Expand Down Expand Up @@ -687,16 +689,16 @@ class ExtHostSourceControl implements vscode.SourceControl {
query: _rootUri ? `rootUri=${encodeURIComponent(_rootUri.toString())}` : undefined
});

this._inputBox = new ExtHostSCMInputBox(_extension, _extHostDocuments, this.#proxy, this.handle, inputBoxDocumentUri);
this.#proxy.$registerSourceControl(this.handle, _id, _label, _rootUri, inputBoxDocumentUri);
this._sequencer.queue(() => this.#proxy.$registerSourceControl(this.handle, _id, _label, _rootUri, inputBoxDocumentUri));
this._inputBox = new ExtHostSCMInputBox(_extension, _extHostDocuments, this.#proxy, this._sequencer, this.handle, inputBoxDocumentUri);
}

private createdResourceGroups = new Map<ExtHostSourceControlResourceGroup, IDisposable>();
private updatedResourceGroups = new Set<ExtHostSourceControlResourceGroup>();

createResourceGroup(id: string, label: string, options?: { multiDiffEditorEnableViewChanges?: boolean }): ExtHostSourceControlResourceGroup {
const multiDiffEditorEnableViewChanges = isProposedApiEnabled(this._extension, 'scmMultiDiffEditor') && options?.multiDiffEditorEnableViewChanges === true;
const group = new ExtHostSourceControlResourceGroup(this.#proxy, this._commands, this.handle, id, label, multiDiffEditorEnableViewChanges, this._extension);
const group = new ExtHostSourceControlResourceGroup(this.#proxy, this._commands, this._sequencer, this.handle, id, label, multiDiffEditorEnableViewChanges, this._extension);
const disposable = Event.once(group.onDidDispose)(() => this.createdResourceGroups.delete(group));
this.createdResourceGroups.set(group, disposable);
this.eventuallyAddResourceGroups();
Expand All @@ -720,7 +722,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
this.updatedResourceGroups.delete(group);
updateListener.dispose();
this._groups.delete(group.handle);
this.#proxy.$unregisterGroup(this.handle, group.handle);
this._sequencer.queue(async () => this.#proxy.$unregisterGroup(this.handle, group.handle));
});

groups.push([group.handle, group.id, group.label, group.features, group.multiDiffEditorEnableViewChanges]);
Expand All @@ -734,7 +736,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
this._groups.set(group.handle, group);
}

this.#proxy.$registerGroups(this.handle, groups, splices);
this._sequencer.queue(async () => this.#proxy.$registerGroups(this.handle, groups, splices));
this.createdResourceGroups.clear();
}

Expand All @@ -753,7 +755,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
});

if (splices.length > 0) {
this.#proxy.$spliceResourceStates(this.handle, splices);
this._sequencer.queue(async () => this.#proxy.$spliceResourceStates(this.handle, splices));
}

this.updatedResourceGroups.clear();
Expand All @@ -774,7 +776,7 @@ class ExtHostSourceControl implements vscode.SourceControl {
this._statusBarDisposables.dispose();

this._groups.forEach(group => group.dispose());
this.#proxy.$unregisterSourceControl(this.handle);
this._sequencer.queue(async () => this.#proxy.$unregisterSourceControl(this.handle));
}
}

Expand Down
Loading