Skip to content

Commit 31f8313

Browse files
authored
SCM - 💄 history provider observables cleanup (microsoft#221474)
1 parent 665dd63 commit 31f8313

File tree

7 files changed

+29
-48
lines changed

7 files changed

+29
-48
lines changed

‎extensions/git/src/historyProvider.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
8383
this.currentHistoryItemGroup = {
8484
id: `refs/heads/${this.repository.HEAD.name ?? ''}`,
8585
name: this.repository.HEAD.name ?? '',
86-
revision: this.repository.HEAD.commit ?? '',
86+
revision: this.repository.HEAD.commit,
8787
remote: this.repository.HEAD.upstream ? {
8888
id: `refs/remotes/${this.repository.HEAD.upstream.remote}/${this.repository.HEAD.upstream.name}`,
8989
name: `${this.repository.HEAD.upstream.remote}/${this.repository.HEAD.upstream.name}`,
90-
revision: this.repository.HEAD.upstream.commit ?? ''
90+
revision: this.repository.HEAD.upstream.commit
9191
} : undefined,
9292
base: mergeBase ? {
9393
id: `refs/remotes/${mergeBase.remote}/${mergeBase.name}`,
9494
name: `${mergeBase.remote}/${mergeBase.name}`,
95-
revision: mergeBase.commit ?? ''
95+
revision: mergeBase.commit
9696
} : undefined
9797
};
9898

‎src/vs/workbench/api/browser/mainThreadSCM.ts‎

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Barrier } from 'vs/base/common/async';
77
import { URI, UriComponents } from 'vs/base/common/uri';
88
import { Event, Emitter } from 'vs/base/common/event';
9-
import { derivedOpts, observableValue, observableValueOpts } from 'vs/base/common/observable';
9+
import { derived, observableValue, observableValueOpts } from 'vs/base/common/observable';
1010
import { IDisposable, DisposableStore, combinedDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
1111
import { ISCMService, ISCMRepository, ISCMProvider, ISCMResource, ISCMResourceGroup, ISCMResourceDecorations, IInputValidation, ISCMViewService, InputValidationType, ISCMActionButtonDescriptor } from 'vs/workbench/contrib/scm/common/scm';
1212
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape, SCMProviderFeatures, SCMRawResourceSplices, SCMGroupFeatures, MainContext, SCMHistoryItemGroupDto, SCMHistoryItemDto } from '../common/extHost.protocol';
@@ -17,7 +17,7 @@ import { MarshalledId } from 'vs/base/common/marshallingIds';
1717
import { ThemeIcon } from 'vs/base/common/themables';
1818
import { IMarkdownString } from 'vs/base/common/htmlContent';
1919
import { IQuickDiffService, QuickDiffProvider } from 'vs/workbench/contrib/scm/common/quickDiff';
20-
import { ISCMHistoryItem, ISCMHistoryItemChange, ISCMHistoryItemGroup, ISCMHistoryItemGroupWithRevision, ISCMHistoryOptions, ISCMHistoryProvider } from 'vs/workbench/contrib/scm/common/history';
20+
import { ISCMHistoryItem, ISCMHistoryItemChange, ISCMHistoryItemGroup, ISCMHistoryOptions, ISCMHistoryProvider } from 'vs/workbench/contrib/scm/common/history';
2121
import { ResourceTree } from 'vs/base/common/resourceTree';
2222
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
2323
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
@@ -49,12 +49,6 @@ function toISCMHistoryItem(historyItemDto: SCMHistoryItemDto): ISCMHistoryItem {
4949
return { ...historyItemDto, icon, labels };
5050
}
5151

52-
function historyItemGroupEquals(a: ISCMHistoryItemGroup | undefined, b: ISCMHistoryItemGroup | undefined): boolean {
53-
return a?.id === b?.id && a?.name === b?.name &&
54-
a?.base?.id === b?.base?.id && a?.base?.name === b?.base?.name &&
55-
a?.remote?.id === b?.remote?.id && a?.remote?.name === b?.remote?.name;
56-
}
57-
5852
class SCMInputBoxContentProvider extends Disposable implements ITextModelContentProvider {
5953
constructor(
6054
textModelService: ITextModelService,
@@ -171,26 +165,18 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
171165
private _onDidChangeCurrentHistoryItemGroup = new Emitter<void>();
172166
readonly onDidChangeCurrentHistoryItemGroup = this._onDidChangeCurrentHistoryItemGroup.event;
173167

174-
private _currentHistoryItemGroup: ISCMHistoryItemGroupWithRevision | undefined;
175-
get currentHistoryItemGroup(): ISCMHistoryItemGroupWithRevision | undefined { return this._currentHistoryItemGroup; }
176-
set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroupWithRevision | undefined) {
168+
private _currentHistoryItemGroup: ISCMHistoryItemGroup | undefined;
169+
get currentHistoryItemGroup(): ISCMHistoryItemGroup | undefined { return this._currentHistoryItemGroup; }
170+
set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined) {
177171
this._currentHistoryItemGroup = historyItemGroup;
178172
this._onDidChangeCurrentHistoryItemGroup.fire();
179173
}
180174

181-
/**
182-
* Changes when the id/name changes for the current, remote, or base history item group
183-
*/
184-
private readonly _currentHistoryItemGroupObs = derivedOpts<ISCMHistoryItemGroup | undefined>({
185-
owner: this, equalsFn: historyItemGroupEquals,
186-
}, reader => this._currentHistoryItemGroupWithRevisionObs.read(reader));
187-
get currentHistoryItemGroupObs() { return this._currentHistoryItemGroupObs; }
175+
readonly currentHistoryItemGroupIdObs = derived<string | undefined>(this, reader => this.currentHistoryItemGroup?.id);
176+
readonly currentHistoryItemGroupNameObs = derived<string | undefined>(this, reader => this.currentHistoryItemGroup?.name);
188177

189-
/**
190-
* Changes when the id/name/revision changes for the current, remote, or base history item group
191-
*/
192-
private readonly _currentHistoryItemGroupWithRevisionObs = observableValueOpts<ISCMHistoryItemGroupWithRevision | undefined>({ owner: this, equalsFn: structuralEquals }, undefined);
193-
get currentHistoryItemGroupWithRevisionObs() { return this._currentHistoryItemGroupWithRevisionObs; }
178+
private readonly _currentHistoryItemGroupObs = observableValueOpts<ISCMHistoryItemGroup | undefined>({ owner: this, equalsFn: structuralEquals }, undefined);
179+
get currentHistoryItemGroupObs() { return this._currentHistoryItemGroupObs; }
194180

195181
constructor(private readonly proxy: ExtHostSCMShape, private readonly handle: number) { }
196182

@@ -227,8 +213,8 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
227213
}));
228214
}
229215

230-
$onDidChangeCurrentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroupWithRevision | undefined): void {
231-
this._currentHistoryItemGroupWithRevisionObs.set(historyItemGroup, undefined);
216+
$onDidChangeCurrentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined): void {
217+
this._currentHistoryItemGroupObs.set(historyItemGroup, undefined);
232218
}
233219
}
234220

‎src/vs/workbench/api/common/extHost.protocol.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ export type SCMRawResourceSplices = [
15161516
export interface SCMHistoryItemGroupDto {
15171517
readonly id: string;
15181518
readonly name: string;
1519-
readonly revision: string;
1519+
readonly revision?: string;
15201520
readonly base?: Omit<Omit<SCMHistoryItemGroupDto, 'base'>, 'remote'>;
15211521
readonly remote?: Omit<Omit<SCMHistoryItemGroupDto, 'base'>, 'remote'>;
15221522
}

‎src/vs/workbench/contrib/scm/browser/activity.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { autorun, autorunWithStore, derived, IObservable, observableFromEvent }
2525
import { observableConfigValue } from 'vs/platform/observable/common/platformObservableUtils';
2626
import { derivedObservableWithCache, latestChangedValue, observableFromEventOpts } from 'vs/base/common/observableInternal/utils';
2727
import { Command } from 'vs/editor/common/languages';
28-
import { ISCMHistoryItemGroup } from 'vs/workbench/contrib/scm/common/history';
2928

3029
const ActiveRepositoryContextKeys = {
3130
ActiveRepositoryName: new RawContextKey<string>('scmActiveRepositoryName', ''),
@@ -135,9 +134,10 @@ export class SCMActiveRepositoryController extends Disposable implements IWorkbe
135134

136135
this._register(autorun(reader => {
137136
const repository = this._activeRepository.read(reader);
138-
const currentHistoryItemGroup = repository?.provider.historyProviderObs.read(reader)?.currentHistoryItemGroupObs.read(reader);
137+
const historyProvider = repository?.provider.historyProviderObs.read(reader);
138+
const branchName = historyProvider?.currentHistoryItemGroupNameObs.read(reader);
139139

140-
this._updateActiveRepositoryContextKeys(repository, currentHistoryItemGroup);
140+
this._updateActiveRepositoryContextKeys(repository?.provider.name, branchName);
141141
}));
142142
}
143143

@@ -196,9 +196,9 @@ export class SCMActiveRepositoryController extends Disposable implements IWorkbe
196196
}
197197
}
198198

199-
private _updateActiveRepositoryContextKeys(repository: ISCMRepository | undefined, currentHistoryItemGroup: ISCMHistoryItemGroup | undefined): void {
200-
this._activeRepositoryNameContextKey.set(repository?.provider.name ?? '');
201-
this._activeRepositoryBranchNameContextKey.set(currentHistoryItemGroup?.name ?? '');
199+
private _updateActiveRepositoryContextKeys(repositoryName: string | undefined, branchName: string | undefined): void {
200+
this._activeRepositoryNameContextKey.set(repositoryName ?? '');
201+
this._activeRepositoryBranchNameContextKey.set(branchName ?? '');
202202
}
203203
}
204204

‎src/vs/workbench/contrib/scm/browser/workingSet.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class SCMWorkingSetController extends Disposable implements IWorkbenchCon
6565

6666
disposables.add(autorun(async reader => {
6767
const historyProvider = repository.provider.historyProviderObs.read(reader);
68-
const currentHistoryItemGroupId = historyProvider?.currentHistoryItemGroupObs.read(reader)?.id;
68+
const currentHistoryItemGroupId = historyProvider?.currentHistoryItemGroupIdObs.read(reader);
6969

7070
if (!currentHistoryItemGroupId) {
7171
return;

‎src/vs/workbench/contrib/scm/common/history.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export interface ISCMHistoryProvider {
2121

2222
readonly onDidChangeCurrentHistoryItemGroup: Event<void>;
2323

24-
get currentHistoryItemGroup(): ISCMHistoryItemGroupWithRevision | undefined;
25-
set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroupWithRevision | undefined);
24+
get currentHistoryItemGroup(): ISCMHistoryItemGroup | undefined;
25+
set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined);
26+
27+
readonly currentHistoryItemGroupIdObs: IObservable<string | undefined>;
28+
readonly currentHistoryItemGroupNameObs: IObservable<string | undefined>;
2629
readonly currentHistoryItemGroupObs: IObservable<ISCMHistoryItemGroup | undefined>;
27-
readonly currentHistoryItemGroupWithRevisionObs: IObservable<ISCMHistoryItemGroupWithRevision | undefined>;
2830

2931
provideHistoryItems(historyItemGroupId: string, options: ISCMHistoryOptions): Promise<ISCMHistoryItem[] | undefined>;
3032
provideHistoryItems2(options: ISCMHistoryOptions): Promise<ISCMHistoryItem[] | undefined>;
@@ -51,18 +53,11 @@ export interface ISCMHistoryOptions {
5153
export interface ISCMHistoryItemGroup {
5254
readonly id: string;
5355
readonly name: string;
56+
readonly revision?: string;
5457
readonly base?: Omit<Omit<ISCMHistoryItemGroup, 'base'>, 'remote'>;
5558
readonly remote?: Omit<Omit<ISCMHistoryItemGroup, 'base'>, 'remote'>;
5659
}
5760

58-
export interface ISCMHistoryItemGroupWithRevision {
59-
readonly id: string;
60-
readonly name: string;
61-
readonly revision: string;
62-
readonly base?: Omit<Omit<ISCMHistoryItemGroupWithRevision, 'base'>, 'remote'>;
63-
readonly remote?: Omit<Omit<ISCMHistoryItemGroupWithRevision, 'base'>, 'remote'>;
64-
}
65-
6661
export interface SCMHistoryItemGroupTreeElement {
6762
readonly id: string;
6863
readonly label: string;

‎src/vscode-dts/vscode.proposed.scmHistoryProvider.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ declare module 'vscode' {
4242
export interface SourceControlHistoryItemGroup {
4343
readonly id: string;
4444
readonly name: string;
45-
readonly revision: string;
45+
readonly revision?: string;
4646
readonly base?: Omit<Omit<SourceControlHistoryItemGroup, 'base'>, 'remote'>;
4747
readonly remote?: Omit<Omit<SourceControlHistoryItemGroup, 'base'>, 'remote'>;
4848
}

0 commit comments

Comments
 (0)