From ff8f55a88b5cf8d8293082b192dd0e264bc8083d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E5=A3=B0?= Date: Wed, 11 Sep 2024 13:31:00 +0800 Subject: [PATCH 1/2] fix(diff-viewer): open file one by one --- .../src/core/diff-viewer/internal/base.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/core/src/core/diff-viewer/internal/base.ts b/packages/core/src/core/diff-viewer/internal/base.ts index 94eea81c..59a60f77 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)); }; From d1150c876cc594a8af531b66ba274f178c6318a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E5=A3=B0?= Date: Wed, 11 Sep 2024 14:18:12 +0800 Subject: [PATCH 2/2] fix: snapshot not correct --- .../core/src/core/diff-viewer/internal/base.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/core/src/core/diff-viewer/internal/base.ts b/packages/core/src/core/diff-viewer/internal/base.ts index 59a60f77..39ec06dc 100644 --- a/packages/core/src/core/diff-viewer/internal/base.ts +++ b/packages/core/src/core/diff-viewer/internal/base.ts @@ -314,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; @@ -327,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) || {