Skip to content
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
37 changes: 10 additions & 27 deletions src/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
*--------------------------------------------------------------------------------------------*/

import * as DOM from 'vs/base/browser/dom';
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
import { IEditorOpenContext } from 'vs/workbench/common/editor';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { CancellationToken } from 'vs/base/common/cancellation';
import { MultiDiffEditorWidget } from 'vs/editor/browser/widget/multiDiffEditorWidget/multiDiffEditorWidget';
import { IEditorOptions } from 'vs/platform/editor/common/editor';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
import { IEditorOpenContext } from 'vs/workbench/common/editor';
import { MultiDiffEditorInput } from 'vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditorInput';
import { MultiDiffEditorWidget } from 'vs/editor/browser/widget/multiDiffEditorWidget/multiDiffEditorWidget';
import { toDisposable } from 'vs/base/common/lifecycle';
import { ConstLazyPromise, IDiffEntry } from 'vs/editor/browser/widget/multiDiffEditorWidget/model';

export class MultiDiffEditor extends EditorPane {
static readonly ID = 'multiDiffEditor';
Expand All @@ -27,7 +24,6 @@ export class MultiDiffEditor extends EditorPane {
constructor(
@IInstantiationService private readonly instantiationService: InstantiationService,
@ITelemetryService telemetryService: ITelemetryService,
@ITextModelService private readonly textModelService: ITextModelService,
@IThemeService themeService: IThemeService,
@IStorageService storageService: IStorageService
) {
Expand All @@ -40,21 +36,8 @@ export class MultiDiffEditor extends EditorPane {

override async setInput(input: MultiDiffEditorInput, options: IEditorOptions | undefined, context: IEditorOpenContext, token: CancellationToken): Promise<void> {
await super.setInput(input, options, context, token);

const rs = await Promise.all(input.resources.map(async r => ({
originalRef: await this.textModelService.createModelReference(r.original!),
modifiedRef: await this.textModelService.createModelReference(r.modified!),
title: r.resource.fsPath,
})));

this._multiDiffEditorWidget?.setModel({
onDidChange: () => toDisposable(() => { }),
diffs: rs.map(r => new ConstLazyPromise<IDiffEntry>({
original: r.originalRef.object.textEditorModel,
modified: r.modifiedRef.object.textEditorModel,
title: r.title,
})),
});
const vm = await input.getViewModel();
this._multiDiffEditorWidget?.setModel(vm);
}

layout(dimension: DOM.Dimension): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { localize } from 'vs/nls';
import { URI } from 'vs/base/common/uri';
import { DEFAULT_EDITOR_ASSOCIATION, EditorInputCapabilities } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { ConstLazyPromise, IDiffEntry, IMultiDocumentDiffEditorModel } from 'vs/editor/browser/widget/multiDiffEditorWidget/model';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { toDisposable } from 'vs/base/common/lifecycle';

export class MultiDiffEditorInput extends EditorInput {
static readonly ID: string = 'workbench.input.multiDiffEditor';
Expand All @@ -31,9 +34,39 @@ export class MultiDiffEditorInput extends EditorInput {
return DEFAULT_EDITOR_ASSOCIATION.id;
}

constructor(readonly label: string | undefined, readonly resources: readonly MultiDiffEditorInputData[]) {
private _viewModel: IMultiDocumentDiffEditorModel | undefined;

constructor(
readonly label: string | undefined,
readonly resources: readonly MultiDiffEditorInputData[],
@ITextModelService private readonly _textModelService: ITextModelService,
) {
super();
}

async getViewModel(): Promise<IMultiDocumentDiffEditorModel> {
if (!this._viewModel) {
this._viewModel = await this._createViewModel();
}
return this._viewModel;
}

private async _createViewModel(): Promise<IMultiDocumentDiffEditorModel> {
const rs = await Promise.all(this.resources.map(async r => ({
originalRef: await this._textModelService.createModelReference(r.original!),
modifiedRef: await this._textModelService.createModelReference(r.modified!),
title: r.resource.fsPath,
})));

return {
onDidChange: () => toDisposable(() => { }),
diffs: rs.map(r => new ConstLazyPromise<IDiffEntry>({
original: r.originalRef.object.textEditorModel,
modified: r.modifiedRef.object.textEditorModel,
title: r.title,
})),
};
}
}

export class MultiDiffEditorInputData {
Expand Down