diff --git a/packages/core/src/core/diff-viewer/internal/base.ts b/packages/core/src/core/diff-viewer/internal/base.ts index 94eea81c..39ec06dc 100644 --- a/packages/core/src/core/diff-viewer/internal/base.ts +++ b/packages/core/src/core/diff-viewer/internal/base.ts @@ -74,6 +74,8 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri private readonly _onDidTabChange = this._disposables.add(new Emitter()); public readonly onDidTabChange: Event = this._onDidTabChange.event; + private sequencer = new Sequencer(); + getFullPath(filePath: string) { return path.join(this.appConfig.workspaceDir, filePath); } @@ -90,11 +92,11 @@ 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); @@ -102,6 +104,10 @@ export class DiffViewerContribution implements ClientAppContribution, MenuContri 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 ( @@ -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)); }; @@ -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; @@ -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) || {