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 - refactor getChildren(), add Refresh action #193805

Merged
merged 1 commit into from
Sep 22, 2023
Merged
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
218 changes: 131 additions & 87 deletions src/vs/workbench/contrib/scm/browser/scmSyncViewPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ class SCMSyncPaneViewModel {
return mode;
}

private async refresh(repository?: ISCMRepository): Promise<void> {
async refresh(repository?: ISCMRepository): Promise<void> {
if (this.repositories.size === 0) {
return;
}
Expand Down Expand Up @@ -685,7 +685,7 @@ class SCMSyncDataSource implements IAsyncDataSource<TreeElement, TreeElement> {
const historyItemGroup = historyProvider?.currentHistoryItemGroup;

if (!historyProvider || !historyItemGroup) {
return children;
return [];
}

// Action Button
Expand All @@ -698,101 +698,144 @@ class SCMSyncDataSource implements IAsyncDataSource<TreeElement, TreeElement> {
} as ISCMActionButton);
}

// History item group base
const historyItemGroupBase = await historyProvider.resolveHistoryItemGroupBase(historyItemGroup.id);
if (!historyItemGroupBase) {
return children;
}
// History item groups
children.push(...await this.getHistoryItemGroups(element));
} else if (isSCMHistoryItemGroupTreeElement(element)) {
children.push(...await this.getHistoryItems(element));
} else if (isSCMHistoryItemTreeElement(element)) {
children.push(...await this.getHistoryItemChanges(element));
} else if (ResourceTree.isResourceNode(element)) {
children.push(...element.children);
} else {
throw new Error('getChildren Method not implemented.');
}

// Common ancestor, ahead, behind
const ancestor = await historyProvider.resolveHistoryItemGroupCommonAncestor(historyItemGroup.id, historyItemGroupBase.id);
return children;
}

// Incoming
if (historyItemGroupBase) {
children.push({
id: historyItemGroupBase.id,
label: `$(cloud-download) ${historyItemGroupBase.label}`,
description: localize('incoming', "Incoming Changes"),
ancestor: ancestor?.id,
count: ancestor?.behind ?? 0,
repository: element,
type: 'historyItemGroup'
} as SCMHistoryItemGroupTreeElement);
}
private async getHistoryItemGroups(element: ISCMRepository): Promise<SCMHistoryItemGroupTreeElement[]> {
const scmProvider = element.provider;
const historyProvider = scmProvider.historyProvider;
const currentHistoryItemGroup = historyProvider?.currentHistoryItemGroup;

// Outgoing
if (historyItemGroup) {
children.push({
id: historyItemGroup.id,
label: `$(cloud-upload) ${historyItemGroup.label}`,
description: localize('outgoing', "Outgoing Changes"),
ancestor: ancestor?.id,
count: ancestor?.ahead ?? 0,
repository: element,
type: 'historyItemGroup'
} as SCMHistoryItemGroupTreeElement);
}
} else if (isSCMHistoryItemGroupTreeElement(element)) {
const scmProvider = element.repository.provider;
const historyProvider = scmProvider.historyProvider;
if (!historyProvider || !currentHistoryItemGroup) {
return [];
}

if (!historyProvider) {
return children;
}
// History item group base
const historyItemGroupBase = await historyProvider.resolveHistoryItemGroupBase(currentHistoryItemGroup.id);
if (!historyItemGroupBase) {
return [];
}

const historyItems = await historyProvider.provideHistoryItems(element.id, { limit: { id: element.ancestor } }) ?? [];
children.push(...historyItems.map(historyItem => ({
id: historyItem.id,
label: historyItem.label,
description: historyItem.description,
icon: historyItem.icon,
historyItemGroup: element,
type: 'historyItem'
} as SCMHistoryItemTreeElement)));
} else if (isSCMHistoryItemTreeElement(element)) {
const repository = element.historyItemGroup.repository;
const historyProvider = repository.provider.historyProvider;
// Common ancestor, ahead, behind
const ancestor = await historyProvider.resolveHistoryItemGroupCommonAncestor(currentHistoryItemGroup.id, historyItemGroupBase.id);

const children: SCMHistoryItemGroupTreeElement[] = [];
// Incoming
if (historyItemGroupBase) {
children.push({
id: historyItemGroupBase.id,
label: `$(cloud-download) ${historyItemGroupBase.label}`,
description: localize('incoming', "Incoming Changes"),
ancestor: ancestor?.id,
count: ancestor?.behind ?? 0,
repository: element,
type: 'historyItemGroup'
} as SCMHistoryItemGroupTreeElement);
}

if (!historyProvider) {
return children;
}
// Outgoing
children.push({
id: currentHistoryItemGroup.id,
label: `$(cloud-upload) ${currentHistoryItemGroup.label}`,
description: localize('outgoing', "Outgoing Changes"),
ancestor: ancestor?.id,
count: ancestor?.ahead ?? 0,
repository: element,
type: 'historyItemGroup'
} as SCMHistoryItemGroupTreeElement);

// History Item Changes
const changes = await historyProvider.provideHistoryItemChanges(element.id) ?? [];

if (this.viewMode() === ViewMode.List) {
// List
children.push(...changes.map(change => ({
uri: change.uri,
originalUri: change.originalUri,
modifiedUri: change.modifiedUri,
renameUri: change.renameUri,
historyItem: element,
type: 'historyItemChange'
} as SCMHistoryItemChangeTreeElement)));
} else {
// Tree
const tree = new ResourceTree<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>(element, repository.provider.rootUri ?? URI.file('/'), this.uriIdentityService.extUri);
for (const change of changes) {
tree.add(change.uri, {
uri: change.uri,
originalUri: change.originalUri,
modifiedUri: change.modifiedUri,
renameUri: change.renameUri,
historyItem: element,
type: 'historyItemChange'
} as SCMHistoryItemChangeTreeElement);
}
return children;
}

children.push(...tree.root.children);
}
} else if (ResourceTree.isResourceNode(element)) {
children.push(...element.children);
} else {
throw new Error('getChildren Method not implemented.');
private async getHistoryItems(element: SCMHistoryItemGroupTreeElement): Promise<SCMHistoryItemTreeElement[]> {
const scmProvider = element.repository.provider;
const historyProvider = scmProvider.historyProvider;

if (!historyProvider) {
return [];
}

return children;
const historyItems = await historyProvider.provideHistoryItems(element.id, { limit: { id: element.ancestor } }) ?? [];
return historyItems.map(historyItem => ({
id: historyItem.id,
label: historyItem.label,
description: historyItem.description,
icon: historyItem.icon,
historyItemGroup: element,
type: 'historyItem'
} as SCMHistoryItemTreeElement));
}

private async getHistoryItemChanges(element: SCMHistoryItemTreeElement): Promise<(SCMHistoryItemChangeTreeElement | SCMHistoryItemChangeResourceTreeNode)[]> {
const repository = element.historyItemGroup.repository;
const historyProvider = repository.provider.historyProvider;

if (!historyProvider) {
return [];
}

// History Item Changes
const changes = await historyProvider.provideHistoryItemChanges(element.id) ?? [];

if (this.viewMode() === ViewMode.List) {
// List
return changes.map(change => ({
uri: change.uri,
originalUri: change.originalUri,
modifiedUri: change.modifiedUri,
renameUri: change.renameUri,
historyItem: element,
type: 'historyItemChange'
} as SCMHistoryItemChangeTreeElement));
}

// Tree
const tree = new ResourceTree<SCMHistoryItemChangeTreeElement, SCMHistoryItemTreeElement>(element, repository.provider.rootUri ?? URI.file('/'), this.uriIdentityService.extUri);
for (const change of changes) {
tree.add(change.uri, {
uri: change.uri,
originalUri: change.originalUri,
modifiedUri: change.modifiedUri,
renameUri: change.renameUri,
historyItem: element,
type: 'historyItemChange'
} as SCMHistoryItemChangeTreeElement);
}

return [...tree.root.children];
}

}

class RefreshAction extends ViewAction<SCMSyncViewPane> {
constructor() {
super({
id: 'workbench.scm.sync.action.refresh',
title: localize('refresh', "Refresh"),
viewId: SYNC_VIEW_PANE_ID,
f1: false,
icon: Codicon.refresh,
menu: {
id: MenuId.ViewTitle,
group: 'navigation'
}
});
}

async runInView(_: ServicesAccessor, view: SCMSyncViewPane): Promise<void> {
view.viewModel.refresh();
}
}

Expand Down Expand Up @@ -840,5 +883,6 @@ class SetTreeViewModeAction extends ViewAction<SCMSyncViewPane> {
}
}

registerAction2(RefreshAction);
registerAction2(SetListViewModeAction);
registerAction2(SetTreeViewModeAction);