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

Notify when all editors associated with a NotebookDocument have been closed #97835

Closed
DonJayamanne opened this issue May 14, 2020 · 1 comment
Assignees
Labels
api bug Issue identified by VS Code Team member as probable bug notebook

Comments

@DonJayamanne
Copy link
Contributor

DonJayamanne commented May 14, 2020

  • VSCode Version: Master
  • OS Version: Mac

Provide a way to determine when all editors associated with a NotebookDocument have been closed.

  • Open file A.ipynb
  • Open file A.ipynb again on the side.
  • User saves A.ipynb as B.ipynb
  • Now VSC Closes NotebookBookDocument A.ipyn (event fired notebook.onDidCloseNotebookDocument)
  • This isn't correct, we still have NotebookDocument A.ipyn open, as we have another editor for this file remaining.

Suggestions

  • Add a dispose method NotebookData.dispose, that will be invoked by VSC when all editors associated with that Notebook are closed.
    • Inline with Custom editors API.
    • This way we (extension authors) know when all editors associated with a document have been closed.
    • No need to rely on onDidCloseNotebookDocument (though this might still be useful for extension authors who do not provide NotebookContentProviders)

Why do we need this

  • We need this to ensure the kernel state (in extension) is transitioned across to the new editor when possible.
  • Scenario: Disposing kernel (when all editors are closed)
    • User opens A.ipynb file
    • User opens this notebook again (side by side)
    • User runs a cell
    • User closes one of the A.ipynb editors & VSC fires onDidCloseNotebookDocument
    • We assume all Notebook Editors associated with A.ipynb have been closed and we dispose the kernel.
    • However user still has another A.ipynb file
    • The kernel associate with an active notebook Editor A.ipynb is now in a bad state (running cells is now broken)
  • Scenario: Similar to previous scenario (but with SaveAs)
    • User opens existing A.ipynb file
    • User has the same notebook opened twice (side by side)
    • User runs a cell
    • Users saves one of the editors as New.ipynb
    • At this point VSC closes one of A.ipyb editor and opens New.ipynb
    • VSC fires onDidCloseNotebookDocument for A.ipynb
    • We assume A.ipynb has been closed and dispose the kernel.
    • But we still have an editor for A.ipynb
  • Scenario (user renames an nb file)
    • Again same as previous scenarios
    • We need to move kernel to new resource if user renames a file
    • This can be done only when we know for a fact that all editors associated with an nb have been closed.

Does this issue occur when all extensions are disabled?: Yes/No

@rebornix /cc

@DonJayamanne DonJayamanne changed the title Notification when all editors associated with a NotebookDocument are closed Notify when all editors associated with a NotebookDocument have been closed May 14, 2020
@rebornix rebornix added the api label Jun 2, 2020
@rebornix rebornix added the bug Issue identified by VS Code Team member as probable bug label Oct 8, 2020
@rebornix
Copy link
Member

rebornix commented Nov 9, 2020

This isn't correct, we still have NotebookDocument A.ipyn open, as we have another editor for this file remaining.

In latest Insiders, when a notebook file renamed, all editors attached in the editor pane will replace the old notebook document with the new one, in your particular case, there is no A.ipynb file open in the workspace anymore.

@rebornix rebornix closed this as completed Nov 9, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api bug Issue identified by VS Code Team member as probable bug notebook
Projects
None yet
Development

No branches or pull requests

2 participants