Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify INotebookModel when using VSCode Notebooks #12604

Merged
merged 15 commits into from
Jun 29, 2020

Conversation

DonJayamanne
Copy link

@DonJayamanne DonJayamanne commented Jun 26, 2020

For #10496

  • Two INotebookModels, one for existing Notebook and one for VS Code Notebooks
  • VS Code Notebooks will not need a lot of the API in INotebookModel class (such as updates to cells, undo/redo, etc).
  • VSC Notebooks will use INotebookModel as a mere mirror (readonly view) of the actual VSC NotebookDocument.

This PR just refactors stuff (moving stuff to accommodate the two new INotebook classes).

Will submit separate PR that cleans up updating INotebookModel for VS Code Notebooks (wanted to keep PR and easy for review, else it looks like there's a lot going on, when in fact there isn't much new).

// tslint:disable-next-line: unified-signatures
load(file: Uri, contents?: string, skipDirtyContents?: boolean): Promise<INotebookModel>;
load(file: Uri, contents?: string, backupId?: string, forVSCodeNotebook?: boolean): Promise<INotebookModel>;
load(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an overloaded argument to decide whether to use the new INotebookModel class or old.
Proposal is to create two classes that implement INotebookModel, and based on this class we'd use the appropriate class.

I'll also move the code that keeps the INotebookModel in sync with VSC Notebook changes.
I.e. today we have code that handles VSC events & the like and updates INotebookModel, all of that will go into this new class so that its obvious that INOtebookModel is merely a readonly view of the VSC Notebook document.

@rchiodo /cc (in case u had any thoughts on this design)

@DonJayamanne DonJayamanne added the no-changelog No news entry required label Jun 26, 2020
@@ -1013,7 +1013,7 @@ export interface INotebookModel {
readonly isDirty: boolean;
readonly isUntitled: boolean;
readonly changed: Event<NotebookModelChange>;
readonly cells: Readonly<ICell>[];
readonly cells: readonly Readonly<ICell>[];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely no changes to cells directly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure INotebookModel is purely readonly.

@@ -176,8 +177,10 @@ function handleCellMove(change: NotebookCellsChangeEvent, model: INotebookModel)
assert.notEqual(cellToSwap, cellToSwapWith, 'Cannot swap cell with the same cell');

const indexOfCellToSwap = model.cells.indexOf(cellToSwap);
model.cells[insertChange.start] = cellToSwap;
model.cells[indexOfCellToSwap] = cellToSwapWith;
// tslint:disable-next-line: no-any
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hacks (cast readonly array to make changes), to keep PR small.
I'd rather submit a separate PR for this work.
Basically all of this code goes into the VSCNotebookModel class (it will update the cells internally).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate PR, will just move these into the new class.

@@ -259,7 +259,7 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
case InteractiveWindowMessages.Started:
if (this.model) {
// Load our cells, but don't wait for this to finish, otherwise the window won't load.
this.sendInitialCellsToWebView(this.model.cells, this.model.isTrusted)
this.sendInitialCellsToWebView([...this.model.cells], this.model.isTrusted)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we Array !== ReadOnlyArray.

Copy link

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@DonJayamanne DonJayamanne removed the no-changelog No news entry required label Jun 27, 2020
@sonarcloud
Copy link

sonarcloud bot commented Jun 29, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@DonJayamanne DonJayamanne added the no-changelog No news entry required label Jun 29, 2020
@DonJayamanne DonJayamanne merged commit a42b026 into microsoft:master Jun 29, 2020
@DonJayamanne DonJayamanne deleted the fixesToModel branch June 29, 2020 17:22
DonJayamanne added a commit that referenced this pull request Jun 29, 2020
For #10496
Part 2 of #12604
Move code related to updates to INotebookModel into the corresponding INotebookModel class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog No news entry required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants