Skip to content

Update NotebookModel with changes from VS Code Notebook UI #12048

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

Merged
merged 10 commits into from
Jun 1, 2020

Conversation

DonJayamanne
Copy link

@DonJayamanne DonJayamanne commented May 28, 2020

For #10496

  • Update our model when user edits VS Code cells

Todo:

  • Tests (changes to notebooks)
  • Updating our model when user edits code in cells (separate pr)
  • Copying/pasting cells with support for cell output (separate pr)
  • Tests for handling of closing/disposing notebooks when closing nbs (separate PR)

Will be filing issues (work items) for the pending tasks

@DonJayamanne DonJayamanne changed the title WIP Update NotebookModel with changes from VS Code Notebook UI May 28, 2020
@@ -363,6 +363,11 @@ export interface INotebookModelModifyChange extends INotebookModelChange {
newCells: ICell[];
oldCells: ICell[];
}
export interface INotebookModelCellExecutionCountChange extends INotebookModelChange {
Copy link
Author

Choose a reason for hiding this comment

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

New event.
Using our model as the source of truth. Hence when we update cell execution count, I need an event so I can update VSC code cell.

*
* Hence, we only need to handle auto save when executing cell.s
*/
// @injectable()
Copy link
Author

Choose a reason for hiding this comment

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

TODO: Dumped with solution so i don't forget this.

Copy link
Author

Choose a reason for hiding this comment

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

Will create separate github issue to track this.

traceError(`Unable to find matching cell for ${source}`);
return cells[0];
}
assert.ok(found.length, `NotebookCell not found, for CellId = ${source.id} in ${source}`);
Copy link
Author

Choose a reason for hiding this comment

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

Fall back just in case VS Code changes their API.
Their API will certainly change, hence this is a good way to track it - i.e. our extension should go kaboom.
FYI - Fairly certain this API will change some time soon microsoft/vscode#98828

* If a VS Code cell changes, then ensure we update the corresponding cell in our INotebookModel.
* I.e. if a cell is added/deleted/moved then update our model.
*/
export function updateCellModelWithChangesToVSCCell(
Copy link
Author

Choose a reason for hiding this comment

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

This file ensures we update changes to VSCode cell when our notebook cell changes, e.g. when we execute cells, then our Notebook model changes and we fire events (existing code), we handle those events here and update the VS Code cells.

Similarly, when user adds/deletes cells then we handle those VSCode cells here and update our model.

I.e. this file is where we keep both models in sync.

}
assert.equal(cell.language, PYTHON_LANGUAGE, 'Cannot create a non Python cell');
return {
// TODO: Translate output into nbformat.IOutput.
Copy link
Author

Choose a reason for hiding this comment

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

Will add githuhub issue for this.

@DonJayamanne DonJayamanne marked this pull request as ready for review May 29, 2020 23:43
});

// tslint:disable-next-line: no-any
change.cell.outputs = cellOutputsToVSCCellOutputs(newCellData.outputs as any);
Copy link

Choose a reason for hiding this comment

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

I assume this is done because this is what causes VS code to update?

Copy link
Author

Choose a reason for hiding this comment

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

Yes

@DonJayamanne DonJayamanne added the no-changelog No news entry required label Jun 1, 2020
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 1, 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 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@DonJayamanne DonJayamanne merged commit 176f9c3 into microsoft:master Jun 1, 2020
@DonJayamanne DonJayamanne deleted the handleNBChanges branch June 1, 2020 18:09
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