Skip to content
Open
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
16 changes: 15 additions & 1 deletion extensions/git/src/quickDiffProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { FileType, l10n, LogOutputChannel, QuickDiffProvider, Uri, workspace } from 'vscode';
import { FileType, l10n, LogOutputChannel, QuickDiffProvider, TabInputTextDiff, TabInputTextMultiDiff, Uri, window, workspace } from 'vscode';
import { IRepositoryResolver, Repository } from './repository';
import { isDescendant, pathEquals } from './util';
import { toGitUri } from './uri';
Expand Down Expand Up @@ -71,6 +71,20 @@ export class GitQuickDiffProvider implements QuickDiffProvider {
return undefined;
}

const activeTabInput = window.tabGroups.activeTabGroup.activeTab?.input;

// Ignore file that is on the right-hand side of a diff editor
if (activeTabInput instanceof TabInputTextDiff && pathEquals(activeTabInput.modified.fsPath, uri.fsPath)) {
this.logger.trace(`[Repository][provideOriginalResource] Resource is on the right-hand side of a diff editor: ${uri.toString()}`);
return undefined;
}

// Ignore file that is on the right -hand side of a multi-file diff editor
Comment thread
RedCMD marked this conversation as resolved.
if (activeTabInput instanceof TabInputTextMultiDiff && activeTabInput.textDiffs.some(diff => pathEquals(diff.modified.fsPath, uri.fsPath))) {
this.logger.trace(`[Repository][provideOriginalResource] Resource is on the right-hand side of a multi-file diff editor: ${uri.toString()}`);
return undefined;
}

const originalResource = toGitUri(uri, '', { replaceFileExtension: true });
this.logger.trace(`[Repository][provideOriginalResource] Original resource: ${originalResource.toString()}`);

Expand Down
33 changes: 17 additions & 16 deletions src/vs/workbench/api/browser/mainThreadEditors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
return constObservable(undefined);
}

const editorModelUri = isITextModel(editorModel)
? editorModel.uri
: editorModel.modified.uri;

// TextEditor
if (isITextModel(editorModel)) {
const quickDiffModelRef = this._quickDiffModelService.createQuickDiffModelReference(editorModel.uri);
const quickDiffModelRef = this._quickDiffModelService.createQuickDiffModelReference(editorModelUri);
if (!quickDiffModelRef) {
return constObservable(undefined);
}
Expand All @@ -171,35 +175,32 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape {
});
}

// DiffEditor - we create a quick diff model (using the diff algorithm used by the diff editor)
// even for diff editor so that we can provide multiple "original resources" to diff with the original
// and modified resources.
// DirtyDiffModel - we create a dirty diff model for diff editor so that
// we can provide multiple "original resources" to diff with the modified
// resource.
const diffAlgorithm = this._configurationService.getValue<DiffAlgorithmName>('diffEditor.diffAlgorithm');
const quickDiffModelRef = this._quickDiffModelService.createQuickDiffModelReference(editorModel.modified.uri, { algorithm: diffAlgorithm });
const quickDiffModelRef = this._quickDiffModelService.createQuickDiffModelReference(editorModelUri, { algorithm: diffAlgorithm });
if (!quickDiffModelRef) {
return constObservable(undefined);
}

toDispose.push(quickDiffModelRef);
return observableFromEvent(Event.any(quickDiffModelRef.object.onDidChange, diffEditor.onDidUpdateDiff), () => {
const diffChanges = diffEditor.getDiffComputationResult()?.changes2 ?? [];
const diffInformation = [{
original: editorModel.original.uri,
modified: editorModel.modified.uri,
changes: diffChanges.map(change => change as LineRangeMapping)
}];

// Add quick diff information from secondary/contributed providers
const quickDiffInformation = quickDiffModelRef.object.getQuickDiffResults()
.filter(result => result.providerKind !== 'primary')
.map(result => ({
original: result.original,
modified: result.modified,
changes: result.changes2
}));

// Combine diff and quick diff information
return diffInformation.concat(quickDiffInformation);
const diffChanges = diffEditor.getDiffComputationResult()?.changes2 ?? [];
const diffInformation = [{
original: editorModel.original.uri,
modified: editorModel.modified.uri,
changes: diffChanges.map(change => change as LineRangeMapping)
}];

return [...quickDiffInformation, ...diffInformation];
Comment thread
RedCMD marked this conversation as resolved.
});
});

Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/contrib/scm/common/quickDiffService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,5 @@ export class QuickDiffService extends Disposable implements IQuickDiffService {

export async function getOriginalResource(quickDiffService: IQuickDiffService, uri: URI, language: string | undefined, isSynchronized: boolean | undefined): Promise<URI | null> {
const quickDiffs = await quickDiffService.getQuickDiffs(uri, language, isSynchronized);
const primaryQuickDiffs = quickDiffs.find(quickDiff => quickDiff.kind === 'primary');
return primaryQuickDiffs ? primaryQuickDiffs.originalResource : null;
return quickDiffs.length > 0 ? quickDiffs[0].originalResource : null;
Comment thread
RedCMD marked this conversation as resolved.
}