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

Ability to clear cell output in NativeNotebook #12307

Merged
merged 8 commits into from
Jun 12, 2020

Conversation

DonJayamanne
Copy link

For #10496
For #12274

Fixing https://github.com/microsoft/vscode-python/issues/12274 only for native notebooks here. Was an easy fix.

// tslint:disable-next-line: no-suspicious-comment
//TODO: VSC doesn't handle this well.
// What if user doesn't save it.
if (model.isUntitled) {
Copy link
Author

Choose a reason for hiding this comment

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

VSC Have fixed upstream issues.

const cell = findMappedNotebookCellModel(change.document, vscCell, model.cells);
cell.data.outputs = [];
updateVSCNotebookCellMetadata(vscCell.metadata, cell);
model.update({
Copy link
Author

Choose a reason for hiding this comment

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

We want to trigger an event.

data: newCellData
};

model.update({
Copy link
Author

Choose a reason for hiding this comment

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

We will mutate the cells in place, we don't want to change the cells as the cell mapping stops working

@@ -135,42 +152,22 @@ function handleCellMove(change: NotebookCellsChangeEvent, model: INotebookModel)
const cellToSwap = findMappedNotebookCellModel(change.document, insertChange.items[0]!, model.cells);
const cellToSwapWith = model.cells[insertChange.start];
assert.notEqual(cellToSwap, cellToSwapWith, 'Cannot swap cell with the same cell');
model.update({
Copy link
Author

Choose a reason for hiding this comment

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

We will mutate the cells in place, we don't want to change the cells as the cell mapping stops working

}
function handleCellInsertion(change: NotebookCellsChangeEvent, model: INotebookModel) {
assert.equal(change.changes.length, 1, 'When inserting cells we must have only 1 change');
assert.equal(change.changes[0].items.length, 1, 'Insertion of more than 1 cell is not supported');
const insertChange = change.changes[0];
const cell = change.changes[0].items[0];
const newCell = createCellFromVSCNotebookCell(change.document, cell, model);

model.update({
Copy link
Author

Choose a reason for hiding this comment

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

We will mutate the cells in place, we don't want to change the cells as the cell mapping stops working

}
};
const updateCell: INotebookModelModifyChange = {
Copy link
Author

Choose a reason for hiding this comment

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

We will mutate the cells in place, we don't want to change the cells as the cell mapping stops working

* However we are interested in cell output being cleared (when user clears output).
*/
function clearCellOutput(change: NotebookCellOutputsChangeEvent, model: INotebookModel) {
if (!change.cells.every((cell) => cell.outputs.length === 0)) {
Copy link
Member

Choose a reason for hiding this comment

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

Just a quick question on this check. If an output change comes in, and it had two cells in the output change and one cell cleared the output and another cell still had output, it looks like this check would skip the output clear for the cell. But I'm not sure if that is a situation that could happen. Instead of this check do we want to just perform the operation below on any cells in the change that do have output length === 0?

Copy link
Author

@DonJayamanne DonJayamanne Jun 12, 2020

Choose a reason for hiding this comment

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

We only clear the cells that were cleared by the user. change.cells didn't contain all cells of notebook, but only the cleared cells.
Ie if you clear one cell then this array would contain just one item in the list change.cells

Copy link
Member

Choose a reason for hiding this comment

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

Yup, I can tell that it's just the cells involved with the change. It just looks to me like this NotebookCellOutputsChangeEvent can be more general than just the user clearing output for a cell. Just making sure that VSCode would not do something like batch up calls to it (like update output in cell A and clear output in cell B) then just call OutputsChanged once. If that wouldn't happen then the check seems fine to me, and you would have the best judgement on if that's the case or not.

Copy link
Author

Choose a reason for hiding this comment

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

Yup got it, at this stage that cannot be handled not the way i have written this.
I'd hope VS Code doesn't bundle such events, then it means events are not fired as they happen.
I would suggest we leave this as is for now.

Copy link
Member

@IanMatthewHuff IanMatthewHuff left a comment

Choose a reason for hiding this comment

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

Had one quick question on the clearCellOutput function, but the rest all looked good.

@@ -213,11 +216,19 @@ export class NativeEditorNotebookModel implements INotebookModel {
break;
case 'save':
this._state.saveChangeCount = this._state.changeCount;
// Trigger event.
if (this.useNativeEditorApi) {
Copy link

Choose a reason for hiding this comment

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

This feels rather crappy. Logic seems like it could be handled by a sub class?

Copy link
Author

Choose a reason for hiding this comment

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

I don't think we need to complicate this by adding a sub class, most of this code will get much simpler when we use native editor. Else using sub classes we need to look at child class and parent class what's going on.

Copy link
Author

@DonJayamanne DonJayamanne Jun 12, 2020

Choose a reason for hiding this comment

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

Will make the change.

Copy link
Author

Choose a reason for hiding this comment

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

No I think its simpler this way, now i need to create another class and make private methods protected. I think this is simpler there's barely much going on here.
Again, when we use NativeNotebook majority of the code will go away (no undo/redo, etc).

Copy link

Choose a reason for hiding this comment

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

Sounds okay to me. Just wanted to mention it.


In reply to: 439513672 [](ancestors = 439513672)

Copy link
Author

Choose a reason for hiding this comment

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

Sounds okay to me. Just wanted to mention it.

Oh it is a valid suggestion, if there was a bit more code I'd do it, i did want to do it here. Started it out & realized it wasn't worth it.

@@ -5,6 +5,7 @@

import { nbformat } from '@jupyterlab/coreutils';
import { inject, injectable } from 'inversify';
import { IDisposable } from 'monaco-editor';
Copy link

Choose a reason for hiding this comment

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

o [](start = 14, length = 1)

I don't believe you want this one.

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.

🕐

@DonJayamanne DonJayamanne requested a review from rchiodo June 12, 2020 16:15
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:

@sonarqubecloud
Copy link

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 ff1d4b0 into microsoft:master Jun 12, 2020
@DonJayamanne DonJayamanne deleted the clear branch June 12, 2020 18:18
@lock lock bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
no-changelog No news entry required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants