Skip to content

Commit 3eec502

Browse files
authored
SCM - fix "Open File" action when viewing a history item in the multi-file diff editor (microsoft#258196)
1 parent ee89f51 commit 3eec502

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

src/vs/workbench/contrib/chat/browser/chatEditing/chatEditingServiceImpl.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ class ChatEditingMultiDiffSource implements IResolvedMultiDiffSource {
483483
entryDiff.originalURI,
484484
entryDiff.modifiedURI,
485485
undefined,
486+
undefined,
486487
{
487488
[chatEditingResourceContextKey.key]: entry.entryId,
488489
},
@@ -494,6 +495,7 @@ class ChatEditingMultiDiffSource implements IResolvedMultiDiffSource {
494495
entry.originalURI,
495496
entry.modifiedURI,
496497
undefined,
498+
undefined,
497499
{
498500
[chatEditingResourceContextKey.key]: entry.entryId,
499501
// [inChatEditingSessionContextKey.key]: true

src/vs/workbench/contrib/multiDiffEditor/browser/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class GoToFileAction extends Action2 {
5656
}
5757

5858
await editorService.openEditor({
59+
label: item?.goToFileEditorTitle,
5960
resource: targetUri,
6061
options: {
6162
selection: selections?.[0],

src/vs/workbench/contrib/multiDiffEditor/browser/multiDiffSourceResolverService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class MultiDiffEditorItem {
3636
readonly originalUri: URI | undefined,
3737
readonly modifiedUri: URI | undefined,
3838
readonly goToFileUri: URI | undefined,
39+
readonly goToFileEditorTitle?: string | undefined,
3940
readonly contextKeys?: Record<string, ContextKeyValue>
4041
) {
4142
if (!originalUri && !modifiedUri) {

src/vs/workbench/contrib/multiDiffEditor/browser/scmMultiDiffSourceResolver.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { ValueWithChangeEvent } from '../../../../base/common/event.js';
77
import { Disposable } from '../../../../base/common/lifecycle.js';
88
import { observableFromEvent, ValueWithChangeEventFromObservable, waitForState } from '../../../../base/common/observable.js';
9+
import { basename } from '../../../../base/common/path.js';
910
import { URI, UriComponents } from '../../../../base/common/uri.js';
1011
import { IMultiDiffEditorOptions } from '../../../../editor/browser/widget/multiDiffEditor/multiDiffEditorWidgetImpl.js';
1112
import { localize2 } from '../../../../nls.js';
@@ -89,21 +90,23 @@ interface ScmHistoryItemUriFields {
8990
readonly repositoryId: string;
9091
readonly historyItemId: string;
9192
readonly historyItemParentId?: string;
93+
readonly historyItemDisplayId?: string;
9294
}
9395

9496
export class ScmHistoryItemResolver implements IMultiDiffSourceResolver {
9597
static readonly scheme = 'scm-history-item';
9698

9799
public static getMultiDiffSourceUri(provider: ISCMProvider, historyItem: ISCMHistoryItem): URI {
98-
const historyItemParentId = historyItem.parentIds.length > 0 ? historyItem.parentIds[0] : undefined;
99-
100100
return URI.from({
101101
scheme: ScmHistoryItemResolver.scheme,
102102
path: provider.rootUri?.fsPath,
103103
query: JSON.stringify({
104104
repositoryId: provider.id,
105105
historyItemId: historyItem.id,
106-
historyItemParentId
106+
historyItemParentId: historyItem.parentIds.length > 0
107+
? historyItem.parentIds[0]
108+
: undefined,
109+
historyItemDisplayId: historyItem.displayId
107110
} satisfies ScmHistoryItemUriFields)
108111
}, true);
109112
}
@@ -124,13 +127,14 @@ export class ScmHistoryItemResolver implements IMultiDiffSourceResolver {
124127
return undefined;
125128
}
126129

127-
const { repositoryId, historyItemId, historyItemParentId } = query;
130+
const { repositoryId, historyItemId, historyItemParentId, historyItemDisplayId } = query;
128131
if (typeof repositoryId !== 'string' || typeof historyItemId !== 'string' ||
129-
(typeof historyItemParentId !== 'string' && historyItemParentId !== undefined)) {
132+
(typeof historyItemParentId !== 'string' && historyItemParentId !== undefined) ||
133+
(typeof historyItemDisplayId !== 'string' && historyItemDisplayId !== undefined)) {
130134
return undefined;
131135
}
132136

133-
return { repositoryId, historyItemId, historyItemParentId };
137+
return { repositoryId, historyItemId, historyItemParentId, historyItemDisplayId };
134138
}
135139

136140
constructor(@ISCMService private readonly _scmService: ISCMService) { }
@@ -140,14 +144,21 @@ export class ScmHistoryItemResolver implements IMultiDiffSourceResolver {
140144
}
141145

142146
async resolveDiffSource(uri: URI): Promise<IResolvedMultiDiffSource> {
143-
const { repositoryId, historyItemId, historyItemParentId } = ScmHistoryItemResolver.parseUri(uri)!;
147+
const { repositoryId, historyItemId, historyItemParentId, historyItemDisplayId } = ScmHistoryItemResolver.parseUri(uri)!;
144148

145149
const repository = this._scmService.getRepository(repositoryId);
146150
const historyProvider = repository?.provider.historyProvider.get();
147151
const historyItemChanges = await historyProvider?.provideHistoryItemChanges(historyItemId, historyItemParentId) ?? [];
148152

149153
const resources = ValueWithChangeEvent.const<readonly MultiDiffEditorItem[]>(
150-
historyItemChanges.map(change => new MultiDiffEditorItem(change.originalUri, change.modifiedUri, change.uri)));
154+
historyItemChanges.map(change => {
155+
const goToFileEditorTitle = change.modifiedUri
156+
? `${basename(change.modifiedUri.fsPath)} (${historyItemDisplayId ?? historyItemId})`
157+
: undefined;
158+
159+
return new MultiDiffEditorItem(change.originalUri, change.modifiedUri, change.modifiedUri, goToFileEditorTitle);
160+
})
161+
);
151162

152163
return { resources };
153164
}

src/vs/workbench/contrib/notebook/browser/diff/notebookDiffViewModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ export abstract class NotebookMultiDiffEditorItem extends MultiDiffEditorItem {
466466
public kind: 'Cell' | 'Metadata' | 'Output',
467467
contextKeys?: Record<string, ContextKeyValue>,
468468
) {
469-
super(originalUri, modifiedUri, goToFileUri, contextKeys);
469+
super(originalUri, modifiedUri, goToFileUri, undefined, contextKeys);
470470
}
471471
}
472472

0 commit comments

Comments
 (0)