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

Allow opening diffs from Cloud Changes view #179477

Merged
merged 1 commit into from Apr 7, 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
54 changes: 46 additions & 8 deletions src/vs/workbench/contrib/editSessions/browser/editSessionsViews.ts
Expand Up @@ -10,7 +10,7 @@ import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiati
import { Registry } from 'vs/platform/registry/common/platform';
import { TreeView, TreeViewPane } from 'vs/workbench/browser/parts/views/treeView';
import { Extensions, ITreeItem, ITreeViewDataProvider, ITreeViewDescriptor, IViewsRegistry, TreeItemCollapsibleState, TreeViewItemHandleArg, ViewContainer } from 'vs/workbench/common/views';
import { EDIT_SESSIONS_DATA_VIEW_ID, EDIT_SESSIONS_SCHEME, EDIT_SESSIONS_SHOW_VIEW, EDIT_SESSIONS_TITLE, IEditSessionsStorageService } from 'vs/workbench/contrib/editSessions/common/editSessions';
import { ChangeType, EDIT_SESSIONS_DATA_VIEW_ID, EDIT_SESSIONS_SCHEME, EDIT_SESSIONS_SHOW_VIEW, EDIT_SESSIONS_TITLE, IEditSessionsStorageService } from 'vs/workbench/contrib/editSessions/common/editSessions';
import { URI } from 'vs/base/common/uri';
import { fromNow } from 'vs/base/common/date';
import { Codicon } from 'vs/base/common/codicons';
Expand All @@ -19,6 +19,10 @@ import { registerAction2, Action2, MenuId } from 'vs/platform/actions/common/act
import { ContextKeyExpr, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { joinPath } from 'vs/base/common/resources';
import { IFileService } from 'vs/platform/files/common/files';
import { basename } from 'vs/base/common/path';

const EDIT_SESSIONS_COUNT_KEY = 'editSessionsCount';
const EDIT_SESSIONS_COUNT_CONTEXT_KEY = new RawContextKey<number>(EDIT_SESSIONS_COUNT_KEY, 0);
Expand Down Expand Up @@ -170,7 +174,9 @@ class EditSessionDataViewDataProvider implements ITreeViewDataProvider {

constructor(
@IEditSessionsStorageService private readonly editSessionsStorageService: IEditSessionsStorageService,
@IContextKeyService private readonly contextKeyService: IContextKeyService
@IContextKeyService private readonly contextKeyService: IContextKeyService,
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
@IFileService private readonly fileService: IFileService,
) {
this.editSessionsCount = EDIT_SESSIONS_COUNT_CONTEXT_KEY.bindTo(this.contextKeyService);
}
Expand Down Expand Up @@ -247,20 +253,52 @@ class EditSessionDataViewDataProvider implements ITreeViewDataProvider {
return [];
}

return (data.editSession.folders.find((folder) => folder.name === folderName)?.workingChanges ?? []).map((change) => {
const resource = URI.from({ scheme: EDIT_SESSIONS_SCHEME, authority: 'remote-session-content', path: `/${data.ref}/${folderName}/${change.relativeFilePath}` });
const currentWorkspaceFolder = this.workspaceContextService.getWorkspace().folders.find((folder) => folder.name === folderName);
const editSessionFolder = data.editSession.folders.find((folder) => folder.name === folderName);

if (!editSessionFolder) {
return [];
}

return Promise.all(editSessionFolder.workingChanges.map(async (change) => {
const cloudChangeUri = URI.from({ scheme: EDIT_SESSIONS_SCHEME, authority: 'remote-session-content', path: `/${data.ref}/${folderName}/${change.relativeFilePath}` });

if (currentWorkspaceFolder?.uri) {
// find the corresponding file in the workspace
const localCopy = joinPath(currentWorkspaceFolder.uri, change.relativeFilePath);
if (change.type === ChangeType.Addition && await this.fileService.exists(localCopy)) {
return {
handle: cloudChangeUri.toString(),
resourceUri: cloudChangeUri,
collapsibleState: TreeItemCollapsibleState.None,
label: { label: change.relativeFilePath },
themeIcon: Codicon.file,
command: {
id: 'vscode.diff',
title: localize('compare changes', 'Compare Changes'),
arguments: [
localCopy,
cloudChangeUri,
`${basename(change.relativeFilePath)} (${localize('local copy', 'Local Copy')} \u2194 ${localize('cloud changes', 'Cloud Changes')})`,
undefined
]
}
};
}
}

return {
handle: resource.toString(),
resourceUri: resource,
handle: cloudChangeUri.toString(),
resourceUri: cloudChangeUri,
collapsibleState: TreeItemCollapsibleState.None,
label: { label: change.relativeFilePath },
themeIcon: Codicon.file,
command: {
id: API_OPEN_EDITOR_COMMAND_ID,
title: localize('open file', 'Open File'),
arguments: [resource, undefined, undefined]
arguments: [cloudChangeUri, undefined, undefined]
}
};
});
}));
}
}