Skip to content

Commit fec21d0

Browse files
authored
Update NativeNotebook types in type definition (#13527)
1 parent a4c6cea commit fec21d0

File tree

10 files changed

+615
-586
lines changed

10 files changed

+615
-586
lines changed

src/client/datascience/interactive-ipynb/nativeEditorViewTracker.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Memento, Uri } from 'vscode';
33
import { IExtensionSingleActivationService } from '../../activation/types';
44
import { UseCustomEditorApi } from '../../common/constants';
55
import { IDisposableRegistry, IMemento, WORKSPACE_MEMENTO } from '../../common/types';
6-
import { isUntitled } from '../notebookStorage/nativeEditorStorage';
76
import { INotebookEditor, INotebookEditorProvider } from '../types';
87

98
const MEMENTO_KEY = 'nativeEditorViewTracking';
@@ -48,9 +47,9 @@ export class NativeEditorViewTracker implements IExtensionSingleActivationServic
4847
const fileKey = editor.file.toString();
4948

5049
// Skip untitled files. They have to be changed first.
51-
if (!list.includes(fileKey) && (!isUntitled(editor.model) || editor.isDirty)) {
50+
if (!list.includes(fileKey) && (!editor.model.isUntitled || editor.isDirty)) {
5251
this.workspaceMemento.update(MEMENTO_KEY, [...list, fileKey]);
53-
} else if (isUntitled(editor.model) && editor.model) {
52+
} else if (editor.model.isUntitled && editor.model) {
5453
editor.model.changed(this.onUntitledChanged.bind(this, editor.file));
5554
}
5655
}

src/client/datascience/notebookStorage/baseModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { nbformat } from '@jupyterlab/coreutils/lib/nbformat';
55
import { Event, EventEmitter, Memento, Uri } from 'vscode';
66
import { ICryptoUtils } from '../../common/types';
7+
import { isUntitledFile } from '../../common/utils/misc';
78
import { pruneCell } from '../common';
89
import { NotebookModelChange } from '../interactive-common/interactiveWindowTypes';
910
import {
@@ -12,7 +13,6 @@ import {
1213
} from '../jupyter/kernels/helpers';
1314
import { KernelConnectionMetadata } from '../jupyter/kernels/types';
1415
import { ICell, INotebookMetadataLive, INotebookModel } from '../types';
15-
import { isUntitled } from './nativeEditorStorage';
1616

1717
export const ActiveKernelIdList = `Active_Kernel_Id_List`;
1818
// This is the number of kernel ids that will be remembered between opening and closing VS code
@@ -121,7 +121,7 @@ export abstract class BaseNotebookModel implements INotebookModel {
121121
}
122122

123123
public get isUntitled(): boolean {
124-
return isUntitled(this);
124+
return isUntitledFile(this.file);
125125
}
126126
public get cells(): ICell[] {
127127
return this._cells;

src/client/datascience/notebookStorage/nativeEditorStorage.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ import { VSCodeNotebookModel } from './vscNotebookModel';
2929
const KeyPrefix = 'notebook-storage-';
3030
const NotebookTransferKey = 'notebook-transfered';
3131

32-
export function isUntitled(model?: INotebookModel): boolean {
33-
return isUntitledFile(model?.file);
34-
}
35-
3632
export function getNextUntitledCounter(file: Uri | undefined, currentValue: number): number {
3733
if (file && isUntitledFile(file)) {
3834
const basename = path.basename(file.fsPath, 'ipynb');

src/client/datascience/notebookStorage/vscNotebookModel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export class VSCodeNotebookModel extends BaseNotebookModel {
7272
cells: []
7373
};
7474
}
75+
public get isUntitled(): boolean {
76+
return this.document ? this.document.isUntitled : super.isUntitled;
77+
}
7578

7679
constructor(
7780
isTrusted: boolean,

src/test/datascience/nativeEditorViewTracker.unit.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,22 @@ suite('DataScience - View tracker', () => {
6161
when(editorProvider.onDidOpenNotebookEditor).thenReturn(openEvent.event);
6262
editor1 = mock(NativeEditor);
6363
when(editor1.file).thenReturn(file1);
64+
when(editor1.isUntitled).thenReturn(false);
65+
const model1 = mock<INotebookModel>();
66+
when(editor1.model).thenReturn(instance(model1));
67+
when(model1.isUntitled).thenReturn(false);
6468
editor2 = mock(NativeEditor);
6569
when(editor2.file).thenReturn(file2);
66-
editor1 = mock(NativeEditor);
67-
when(editor1.file).thenReturn(file1);
70+
when(editor2.isUntitled).thenReturn(false);
71+
const model2 = mock<INotebookModel>();
72+
when(editor2.model).thenReturn(instance(model2));
73+
when(model2.isUntitled).thenReturn(false);
6874
untitled1 = mock(NativeEditor);
6975
when(untitled1.file).thenReturn(untitledFile);
7076
when(untitled1.model).thenReturn(instance(untitledModel));
7177
when(untitledModel.file).thenReturn(untitledFile);
7278
when(untitledModel.changed).thenReturn(untitledChangeEvent.event);
79+
when(untitledModel.isUntitled).thenReturn(true);
7380
memento = new MockMemento();
7481
});
7582

src/test/datascience/notebook/helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ export function createNotebookDocument(
427427
isDirty: false,
428428
languages: [],
429429
uri: model.file,
430+
isUntitled: false,
430431
viewType,
431432
metadata: {
432433
cellEditable: model.isTrusted,

src/test/datascience/notebook/rendererExension.unit.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ suite('DataScience - NativeNotebook Renderer Extension', () => {
2727
isDirty: false,
2828
languages: [],
2929
metadata: {},
30+
isUntitled: false,
3031
viewType: JupyterNotebookView
3132
};
3233
const nonJupyterNotebook: NotebookDocument = {
3334
cells: [],
3435
uri: Uri.file('one.xyz'),
3536
fileName: '',
37+
isUntitled: false,
3638
isDirty: false,
3739
languages: [],
3840
metadata: {},

types/vscode-proposed/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export interface NotebookDocument {
215215
readonly fileName: string;
216216
readonly viewType: string;
217217
readonly isDirty: boolean;
218+
readonly isUntitled: boolean;
218219
readonly cells: NotebookCell[];
219220
languages: string[];
220221
displayOrder?: GlobPattern[];
@@ -569,6 +570,7 @@ export namespace notebook {
569570

570571
export const onDidOpenNotebookDocument: Event<NotebookDocument>;
571572
export const onDidCloseNotebookDocument: Event<NotebookDocument>;
573+
export const onDidSaveNotebookDocument: Event<NotebookDocument>;
572574

573575
/**
574576
* All currently known notebook documents.

0 commit comments

Comments
 (0)