Skip to content

Commit b2c8b2a

Browse files
committed
1 parent 139ccc4 commit b2c8b2a

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

extensions/vscode-notebook-tests/src/notebook.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,10 @@ suite('regression', () => {
889889
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
890890
});
891891

892+
test('untitled file', async function () {
893+
await vscode.commands.executeCommand('workbench.action.files.newUntitledFile', { viewType: "notebookCoreTest" });
894+
assert.notEqual(vscode.notebook.activeNotebookEditor, undefined, 'untitled notebook editor is not undefined');
895+
});
892896
});
893897

894898
suite('webview', () => {

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
9191
if (this._notebook.supportBackup) {
9292
const tokenSource = new CancellationTokenSource();
9393
const backupId = await this._notebookService.backup(this.viewType, this.resource, tokenSource.token);
94-
const stats = await this._fileService.resolve(this.resource, { resolveMetadata: true });
94+
const stats = await this._resolveStats(this.resource);
9595

9696
return {
9797
meta: {
98-
mtime: stats.mtime || new Date().getTime(),
98+
mtime: stats?.mtime || new Date().getTime(),
9999
name: this._name,
100100
viewType: this._notebook.viewType,
101101
backupId: backupId
@@ -120,7 +120,7 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
120120
}
121121

122122
await this.load({ forceReadFromDisk: true });
123-
const newStats = await this._fileService.resolve(this.resource, { resolveMetadata: true });
123+
const newStats = await this._resolveStats(this.resource);
124124
this._lastResolvedFileStat = newStats;
125125

126126
this._notebook.setDirty(false);
@@ -159,7 +159,7 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
159159

160160
const notebook = await this._notebookService.createNotebookFromBackup(this.viewType!, this.resource, data.metadata, data.languages, data.cells, editorId);
161161
this._notebook = notebook!;
162-
const newStats = await this._fileService.resolve(this.resource, { resolveMetadata: true });
162+
const newStats = await this._resolveStats(this.resource);
163163
this._lastResolvedFileStat = newStats;
164164
this._register(this._notebook);
165165

@@ -181,7 +181,7 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
181181
private async loadFromProvider(forceReloadFromDisk: boolean, editorId: string | undefined, backupId: string | undefined) {
182182
const notebook = await this._notebookService.resolveNotebook(this.viewType!, this.resource, forceReloadFromDisk, editorId, backupId);
183183
this._notebook = notebook!;
184-
const newStats = await this._fileService.resolve(this.resource, { resolveMetadata: true });
184+
const newStats = await this._resolveStats(this.resource);
185185
this._lastResolvedFileStat = newStats;
186186

187187
this._register(this._notebook);
@@ -216,8 +216,8 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
216216
}
217217

218218
private async _assertStat() {
219-
const stats = await this._fileService.resolve(this.resource, { resolveMetadata: true });
220-
if (this._lastResolvedFileStat && stats.mtime > this._lastResolvedFileStat.mtime) {
219+
const stats = await this._resolveStats(this.resource);
220+
if (this._lastResolvedFileStat && stats && stats.mtime > this._lastResolvedFileStat.mtime) {
221221
return new Promise<'overwrite' | 'revert' | 'none'>(resolve => {
222222
const handle = this._notificationService.prompt(
223223
Severity.Info,
@@ -258,7 +258,7 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
258258

259259
const tokenSource = new CancellationTokenSource();
260260
await this._notebookService.save(this.notebook.viewType, this.notebook.uri, tokenSource.token);
261-
const newStats = await this._fileService.resolve(this.resource, { resolveMetadata: true });
261+
const newStats = await this._resolveStats(this.resource);
262262
this._lastResolvedFileStat = newStats;
263263
this._notebook.setDirty(false);
264264
return true;
@@ -278,12 +278,26 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
278278

279279
const tokenSource = new CancellationTokenSource();
280280
await this._notebookService.saveAs(this.notebook.viewType, this.notebook.uri, targetResource, tokenSource.token);
281-
const newStats = await this._fileService.resolve(this.resource, { resolveMetadata: true });
281+
const newStats = await this._resolveStats(this.resource);
282282
this._lastResolvedFileStat = newStats;
283283
this._notebook.setDirty(false);
284284
return true;
285285
}
286286

287+
private async _resolveStats(resource: URI) {
288+
if (resource.scheme === Schemas.untitled) {
289+
return undefined;
290+
}
291+
292+
try {
293+
const newStats = await this._fileService.resolve(this.resource, { resolveMetadata: true });
294+
return newStats;
295+
} catch (e) {
296+
return undefined;
297+
}
298+
299+
}
300+
287301
dispose() {
288302
super.dispose();
289303
}

0 commit comments

Comments
 (0)