提交 7f3c4913 编写于 作者: R rebornix

notebook file watch re #104209.

上级 95b3a0a8
......@@ -14,6 +14,7 @@ import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebo
import { IReference } from 'vs/base/common/lifecycle';
import { INotebookEditorModel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IPathService } from 'vs/workbench/services/path/common/pathService';
import { IFileService } from 'vs/platform/files/common/files';
interface NotebookEditorInputOptions {
startDirty?: boolean;
......@@ -39,10 +40,33 @@ export class NotebookEditorInput extends EditorInput {
@IFilesConfigurationService private readonly _filesConfigurationService: IFilesConfigurationService,
@IFileDialogService private readonly _fileDialogService: IFileDialogService,
@IPathService private readonly _pathService: IPathService,
@IInstantiationService private readonly _instantiationService: IInstantiationService
@IInstantiationService private readonly _instantiationService: IInstantiationService,
@IFileService private readonly fileService: IFileService,
) {
super();
this._defaultDirtyState = !!options.startDirty;
this._register(this.fileService.watch(this.resource));
this.setupListeners();
}
async setupListeners() {
this._register(this.fileService.onDidFilesChange(async e => {
if (this._textModel && !this.isDirty() && e.contains(this.resource)) {
const lastResolvedFileStat = this._textModel.object.lastResolvedFileStat;
if (!lastResolvedFileStat) {
return;
}
const newStats = await this.fileService.resolve(this.resource, { resolveMetadata: true });
if (lastResolvedFileStat && newStats && newStats.mtime > lastResolvedFileStat.mtime) {
console.log(newStats);
await this._textModel.object.revert();
}
}
}));
}
getTypeId(): string {
......
......@@ -18,6 +18,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { Schemas } from 'vs/base/common/network';
import { IRevertOptions } from 'vs/workbench/common/editor';
import { basename } from 'vs/base/common/path';
import { IFileStatWithMetadata } from 'vs/platform/files/common/files';
export enum CellKind {
Markdown = 1,
......@@ -595,6 +596,7 @@ export interface INotebookEditorModel extends IEditorModel {
readonly resource: URI;
readonly viewType: string;
readonly notebook: NotebookTextModel;
readonly lastResolvedFileStat: IFileStatWithMetadata | undefined;
isDirty(): boolean;
isUntitled(): boolean;
save(): Promise<boolean>;
......
......@@ -44,6 +44,10 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
private _notebook!: NotebookTextModel;
private _lastResolvedFileStat: IFileStatWithMetadata | undefined;
get lastResolvedFileStat() {
return this._lastResolvedFileStat;
}
get notebook() {
return this._notebook;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册