Skip to content

Commit 088f8fe

Browse files
committed
fix microsoft#105917. Bind file watch on diff resources.
1 parent 3dc43cb commit 088f8fe

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ import { getZoomLevel } from 'vs/base/browser/browser';
2727
import { NotebookLayoutInfo } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
2828
import { DIFF_CELL_MARGIN, INotebookTextDiffEditor } from 'vs/workbench/contrib/notebook/browser/diff/common';
2929
import { Emitter } from 'vs/base/common/event';
30-
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
30+
import { DisposableStore, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
3131
import { NotebookDiffEditorEventDispatcher, NotebookLayoutChangedEvent } from 'vs/workbench/contrib/notebook/browser/viewModel/eventDispatcher';
3232
import { EditorPane } from 'vs/workbench/browser/parts/editor/editorPane';
3333
import { INotebookDiffEditorModel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
34+
import { FileService } from 'vs/platform/files/common/fileService';
35+
import { IFileService } from 'vs/platform/files/common/files';
3436

3537
export const IN_NOTEBOOK_TEXT_DIFF_EDITOR = new RawContextKey<boolean>('isInNotebookTextDiffEditor', false);
3638

@@ -48,6 +50,8 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
4850
private _eventDispatcher: NotebookDiffEditorEventDispatcher | undefined;
4951
protected _scopeContextKeyService!: IContextKeyService;
5052
private _model: INotebookDiffEditorModel | null = null;
53+
private _modifiedResourceDisposableStore = new DisposableStore();
54+
5155
get textModel() {
5256
return this._model?.modified.notebook;
5357
}
@@ -58,6 +62,7 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
5862
@IContextKeyService readonly contextKeyService: IContextKeyService,
5963
@INotebookEditorWorkerService readonly notebookEditorWorkerService: INotebookEditorWorkerService,
6064
@IConfigurationService private readonly configurationService: IConfigurationService,
65+
@IFileService private readonly _fileService: FileService,
6166

6267
@ITelemetryService telemetryService: ITelemetryService,
6368
@IStorageService storageService: IStorageService,
@@ -142,7 +147,34 @@ export class NotebookTextDiffEditor extends EditorPane implements INotebookTextD
142147
return;
143148
}
144149

150+
this._modifiedResourceDisposableStore.add(this._fileService.watch(this._model.modified.resource));
151+
this._modifiedResourceDisposableStore.add(this._fileService.onDidFilesChange(async e => {
152+
if (this._model === null) {
153+
return;
154+
}
155+
156+
if (e.changes.find(change => change.resource.toString() === this._model!.modified.resource.toString())) {
157+
await this._model.resolveModifiedFromDisk();
158+
await this.updateLayout();
159+
return;
160+
}
161+
162+
if (e.changes.find(change => change.resource.toString() === this._model!.original.resource.toString())) {
163+
await this._model.resolveOriginalFromDisk();
164+
await this.updateLayout();
165+
return;
166+
}
167+
}));
168+
169+
145170
this._eventDispatcher = new NotebookDiffEditorEventDispatcher();
171+
await this.updateLayout();
172+
}
173+
174+
async updateLayout() {
175+
if (!this._model) {
176+
return;
177+
}
146178

147179
const diffResult = await this.notebookEditorWorkerService.computeDiff(this._model.original.resource, this._model.modified.resource);
148180
const cellChanges = diffResult.cellsDiff.changes;

src/vs/workbench/contrib/notebook/browser/notebookDiffEditorInput.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class NotebookDiffEditorModel extends EditorModel implements INotebookDiffEditor
3939
await this.original.load({ forceReadFromDisk: true });
4040
}
4141

42+
async resolveModifiedFromDisk() {
43+
await this.modified.load({ forceReadFromDisk: true });
44+
}
45+
4246
dispose(): void {
4347

4448
}

src/vs/workbench/contrib/notebook/common/notebookCommon.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ export interface INotebookDiffEditorModel extends IEditorModel {
651651
original: INotebookEditorModel;
652652
modified: INotebookEditorModel;
653653
resolveOriginalFromDisk(): Promise<void>;
654+
resolveModifiedFromDisk(): Promise<void>;
654655
}
655656

656657
export interface INotebookTextModelBackup {

0 commit comments

Comments
 (0)