Skip to content
Merged
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
40 changes: 26 additions & 14 deletions packages/core/src/core/diff-viewer/internal/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
private readonly _onDidTabChange = this._disposables.add(new Emitter<ITabChangedEvent>());
public readonly onDidTabChange: Event<ITabChangedEvent> = this._onDidTabChange.event;

private sequencer = new Sequencer();

getFullPath(filePath: string) {
return path.join(this.appConfig.workspaceDir, filePath);
}
Expand All @@ -90,18 +92,22 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
return result;
}

openFileInTab = async (filePath: string, content: string, options?: IResourceOpenOptions) => {
private async _openFileInTab(filePath: string, content: string, options?: IResourceOpenOptions) {
const fullPath = this.getFullPath(filePath);
if (!fsExtra.pathExistsSync(fullPath)) {
fsExtra.ensureFileSync(fullPath);
fsExtra.writeFileSync(fullPath, content);
if (!await fsExtra.pathExists(fullPath)) {
await fsExtra.ensureFile(fullPath);
await fsExtra.writeFile(fullPath, content);
}

const uri = URI.file(fullPath);
return {
uri,
result: await this.workbenchEditorService.open(uri, options),
};
}

openFileInTab = async (filePath: string, content: string, options?: IResourceOpenOptions) => {
return this.sequencer.queue(() => this._openFileInTab(filePath, content, options));
};

private _openDiffInTab = async (
Expand Down Expand Up @@ -165,8 +171,12 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
previewer.revealFirstDiff();
};

private sequencer = new Sequencer();
openDiffInTab = async (filePath, oldContent, newContent, options?: IResourceOpenOptions) => {
openDiffInTab = async (
filePath: string,
oldContent: string,
newContent: string,
options?: IResourceOpenOptions,
) => {
await this.sequencer.queue(() => this._openDiffInTab(filePath, oldContent, newContent, options));
};

Expand Down Expand Up @@ -304,7 +314,7 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
toChangedLines: 0,
};

const snapshot = resourceDiff.createSnapshot();
const snapshot = resourceDiff.currentSnapshotStore || resourceDiff.createSnapshot();
const list = snapshot.decorationSnapshotData.partialEditWidgetList;
const unresolved = list.filter(v => v.status === 'pending');
result.total = list.length;
Expand All @@ -317,15 +327,17 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri
}

getDiffInfoForUri = (uri: URI) => {
let resourceDiff = (this.inlineDiffHandler as any)._previewerNodeStore.get(uri.toString()) as
| InlineStreamDiffHandler
| undefined;
let resourceDiff: InlineStreamDiffHandler | undefined;

const previewer = this.inlineDiffHandler.getPreviewer() as LiveInlineDiffPreviewer;
if (previewer && previewer.isModel(uri.toString())) {
resourceDiff = previewer.getNode();
}

if (!resourceDiff) {
const previewer = this.inlineDiffHandler.getPreviewer() as LiveInlineDiffPreviewer;
if (previewer && previewer.isModel(uri.toString())) {
resourceDiff = previewer.getNode();
}
resourceDiff = (this.inlineDiffHandler as any)._previewerNodeStore.get(uri.toString()) as
| InlineStreamDiffHandler
| undefined;
}

return this.computeDiffInfo(resourceDiff) || {
Expand Down