Skip to content

Commit

Permalink
fix(diff-viewer): snapshot is not correct (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain authored Sep 11, 2024
1 parent 9b63ba8 commit d30cde7
Showing 1 changed file with 26 additions and 14 deletions.
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

0 comments on commit d30cde7

Please sign in to comment.