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 - 💄 more observable clean-up #221485

Merged
merged 2 commits into from
Jul 11, 2024
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
22 changes: 5 additions & 17 deletions src/vs/workbench/api/browser/mainThreadSCM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,11 @@ class MainThreadSCMResource implements ISCMResource {
}

class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
readonly currentHistoryItemGroupId = derived<string | undefined>(this, reader => this.currentHistoryItemGroup.read(reader)?.id);
readonly currentHistoryItemGroupName = derived<string | undefined>(this, reader => this.currentHistoryItemGroup.read(reader)?.name);

private _onDidChangeCurrentHistoryItemGroup = new Emitter<void>();
readonly onDidChangeCurrentHistoryItemGroup = this._onDidChangeCurrentHistoryItemGroup.event;

private _currentHistoryItemGroup: ISCMHistoryItemGroup | undefined;
get currentHistoryItemGroup(): ISCMHistoryItemGroup | undefined { return this._currentHistoryItemGroup; }
set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined) {
this._currentHistoryItemGroup = historyItemGroup;
this._onDidChangeCurrentHistoryItemGroup.fire();
}

readonly currentHistoryItemGroupIdObs = derived<string | undefined>(this, reader => this.currentHistoryItemGroup?.id);
readonly currentHistoryItemGroupNameObs = derived<string | undefined>(this, reader => this.currentHistoryItemGroup?.name);

private readonly _currentHistoryItemGroupObs = observableValueOpts<ISCMHistoryItemGroup | undefined>({ owner: this, equalsFn: structuralEquals }, undefined);
get currentHistoryItemGroupObs() { return this._currentHistoryItemGroupObs; }
private readonly _currentHistoryItemGroup = observableValueOpts<ISCMHistoryItemGroup | undefined>({ owner: this, equalsFn: structuralEquals }, undefined);
get currentHistoryItemGroup() { return this._currentHistoryItemGroup; }

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

Expand Down Expand Up @@ -214,7 +203,7 @@ class MainThreadSCMHistoryProvider implements ISCMHistoryProvider {
}

$onDidChangeCurrentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined): void {
this._currentHistoryItemGroupObs.set(historyItemGroup, undefined);
this._currentHistoryItemGroup.set(historyItemGroup, undefined);
}
}

Expand Down Expand Up @@ -461,7 +450,6 @@ class MainThreadSCMProvider implements ISCMProvider, QuickDiffProvider {
return;
}

this._historyProvider.currentHistoryItemGroup = currentHistoryItemGroup ?? undefined;
this._historyProviderObs.get()?.$onDidChangeCurrentHistoryItemGroup(currentHistoryItemGroup);
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/browser/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class SCMActiveRepositoryController extends Disposable implements IWorkbe
this._register(autorun(reader => {
const repository = this._activeRepository.read(reader);
const historyProvider = repository?.provider.historyProviderObs.read(reader);
const branchName = historyProvider?.currentHistoryItemGroupNameObs.read(reader);
const branchName = historyProvider?.currentHistoryItemGroupName.read(reader);

this._updateActiveRepositoryContextKeys(repository?.provider.name, branchName);
}));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/browser/menus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export class SCMHistoryProviderMenus implements ISCMHistoryProviderMenus, IDispo

private getOutgoingHistoryItemGroupMenu(menuId: MenuId, historyItemGroup: SCMHistoryItemGroupTreeElement): IMenu {
const contextKeyService = this.contextKeyService.createOverlay([
['scmHistoryItemGroupHasRemote', !!historyItemGroup.repository.provider.historyProvider?.currentHistoryItemGroup?.remote],
['scmHistoryItemGroupHasRemote', !!historyItemGroup.repository.provider.historyProvider?.currentHistoryItemGroup.get()?.remote],
]);

return this.menuService.createMenu(menuId, contextKeyService);
Expand Down
26 changes: 8 additions & 18 deletions src/vs/workbench/contrib/scm/browser/scmViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ import { IMenuWorkbenchToolBarOptions, WorkbenchToolBar } from 'vs/platform/acti
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { DropdownWithPrimaryActionViewItem } from 'vs/platform/actions/browser/dropdownWithPrimaryActionViewItem';
import { clamp, rot } from 'vs/base/common/numbers';
import { ILogService } from 'vs/platform/log/common/log';
import { MarkdownString } from 'vs/base/common/htmlContent';
import type { IHoverOptions, IManagedHover, IManagedHoverTooltipMarkdownString } from 'vs/base/browser/ui/hover/hover';
import { IHoverService, WorkbenchHoverDelegate } from 'vs/platform/hover/browser/hover';
Expand Down Expand Up @@ -1241,7 +1240,7 @@ class SeparatorRenderer implements ICompressibleTreeRenderer<SCMViewSeparatorEle
return { label, toolBar, elementDisposables: new DisposableStore(), templateDisposables };
}
renderElement(element: ITreeNode<SCMViewSeparatorElement, void>, index: number, templateData: SeparatorTemplate, height: number | undefined): void {
const currentHistoryItemGroup = element.element.repository.provider.historyProvider?.currentHistoryItemGroup;
const currentHistoryItemGroup = element.element.repository.provider.historyProvider?.currentHistoryItemGroup.get();

// Label
templateData.label.setLabel(element.element.label, undefined, { title: element.element.ariaLabel });
Expand Down Expand Up @@ -2937,7 +2936,6 @@ export class SCMViewPane extends ViewPane {
options: IViewPaneOptions,
@ICommandService private readonly commandService: ICommandService,
@IEditorService private readonly editorService: IEditorService,
@ILogService private readonly logService: ILogService,
@IMenuService private readonly menuService: IMenuService,
@ISCMService private readonly scmService: ISCMService,
@ISCMViewService private readonly scmViewService: ISCMViewService,
Expand Down Expand Up @@ -3363,19 +3361,11 @@ export class SCMViewPane extends ViewPane {
repositoryDisposables.add(repository.input.onDidChangeVisibility(() => this.updateChildren(repository)));
repositoryDisposables.add(repository.provider.onDidChangeResourceGroups(() => this.updateChildren(repository)));

repositoryDisposables.add(Event.runAndSubscribe(repository.provider.onDidChangeHistoryProvider, () => {
if (!repository.provider.historyProvider) {
this.logService.debug('SCMViewPane:onDidChangeVisibleRepositories - no history provider present');
return;
}

repositoryDisposables.add(repository.provider.historyProvider.onDidChangeCurrentHistoryItemGroup(() => {
this.historyProviderDataSource.deleteCacheEntry(repository);
this.updateChildren(repository);
this.logService.debug('SCMViewPane:onDidChangeCurrentHistoryItemGroup - update children');
}));
repositoryDisposables.add(autorun(reader => {
repository.provider.historyProviderObs.read(reader)?.currentHistoryItemGroup.read(reader);

this.logService.debug('SCMViewPane:onDidChangeVisibleRepositories - onDidChangeCurrentHistoryItemGroup listener added');
this.historyProviderDataSource.deleteCacheEntry(repository);
this.updateChildren(repository);
}));

const resourceGroupDisposables = repositoryDisposables.add(new DisposableMap<ISCMResourceGroup, IDisposable>());
Expand Down Expand Up @@ -3779,7 +3769,7 @@ class SCMTreeHistoryProviderDataSource extends Disposable {

const scmProvider = element.provider;
const historyProvider = scmProvider.historyProvider;
const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup;
const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup.get();

if (!historyProvider || !currentHistoryItemGroup || (showIncomingChanges === 'never' && showOutgoingChanges === 'never') || showHistoryGraph) {
return [];
Expand Down Expand Up @@ -3897,9 +3887,9 @@ class SCMTreeHistoryProviderDataSource extends Disposable {
const { showHistoryGraph } = this._getConfiguration();

const historyProvider = element.provider.historyProvider;
const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup;
const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup.get();

if (!currentHistoryItemGroup || !showHistoryGraph) {
if (!historyProvider || !currentHistoryItemGroup || !showHistoryGraph) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/scm/browser/workingSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class SCMWorkingSetController extends Disposable implements IWorkbenchCon

disposables.add(autorun(async reader => {
const historyProvider = repository.provider.historyProviderObs.read(reader);
const currentHistoryItemGroupId = historyProvider?.currentHistoryItemGroupIdObs.read(reader);
const currentHistoryItemGroupId = historyProvider?.currentHistoryItemGroupId.read(reader);

if (!currentHistoryItemGroupId) {
return;
Expand Down
13 changes: 3 additions & 10 deletions src/vs/workbench/contrib/scm/common/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Event } from 'vs/base/common/event';
import { IObservable } from 'vs/base/common/observable';
import { ThemeIcon } from 'vs/base/common/themables';
import { URI } from 'vs/base/common/uri';
Expand All @@ -18,15 +17,9 @@ export interface ISCMHistoryProviderMenus {
}

export interface ISCMHistoryProvider {

readonly onDidChangeCurrentHistoryItemGroup: Event<void>;

get currentHistoryItemGroup(): ISCMHistoryItemGroup | undefined;
set currentHistoryItemGroup(historyItemGroup: ISCMHistoryItemGroup | undefined);

readonly currentHistoryItemGroupIdObs: IObservable<string | undefined>;
readonly currentHistoryItemGroupNameObs: IObservable<string | undefined>;
readonly currentHistoryItemGroupObs: IObservable<ISCMHistoryItemGroup | undefined>;
readonly currentHistoryItemGroupId: IObservable<string | undefined>;
readonly currentHistoryItemGroupName: IObservable<string | undefined>;
readonly currentHistoryItemGroup: IObservable<ISCMHistoryItemGroup | undefined>;

provideHistoryItems(historyItemGroupId: string, options: ISCMHistoryOptions): Promise<ISCMHistoryItem[] | undefined>;
provideHistoryItems2(options: ISCMHistoryOptions): Promise<ISCMHistoryItem[] | undefined>;
Expand Down
Loading