-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Handle reloading of REPL Window #24148
Conversation
src/client/repl/nativeRepl.ts
Outdated
wsMementoUri = wsMemento ? Uri.parse(wsMemento) : undefined; | ||
|
||
if (!wsMementoUri || getTabNameForUri(wsMementoUri) !== 'Python REPL') { | ||
await this.cleanRepl(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are in here because this.notebookDocument
is undefined
. So why are you clearing it again? also, it does not seem like it gets set or used here (in this if block) so why is this being checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for case: #24148 (comment)
This case, memento URI will be referencing old native REPL, whereas in reality the untitled notebook have already taken over the URI of the old native REPL. In this case, to prevent native REPL creeping into the untitled jupyter notebook, we have to explicitly check for if the URI belongs to Python REPL, and properly clean up everything so that new native REPL can be created with different URI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my question here was about this.notebookDocument
. Its state does not seem to change within this if, so why are we clearing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh I read this wrong, I understand this now. Yeah it wont change inside the if block, so no need at all:
c3648f5
if (notebookDocument) { | ||
if (mementoValue) { | ||
if (!notebookDocument) { | ||
notebookDocument = await workspace.openNotebookDocument(mementoValue as Uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid depending directly on workspace
, window
, commands
. if you want to use our Unit Test framework effectively. One of the things you do with Unit testing is control the boundary. These APIs are the boundary for the extension, and using them directly like this can break that boundary too often. Also, this is a broad namespace, makes it hard to mock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10000% agree. I created #24426
I think I should go through major refactoring for native REPL code soon, and replace all these workspace, window APIs
@@ -20,22 +21,39 @@ import { PVSC_EXTENSION_ID } from '../common/constants'; | |||
export async function openInteractiveREPL( | |||
notebookController: NotebookController, | |||
notebookDocument: NotebookDocument | undefined, | |||
): Promise<NotebookEditor> { | |||
mementoValue: Uri | undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like this should not be passed to this function. The function already takes a notebookDocument. You can make notebookDocument arg flexible NotebookDocument | Uri | undefined
. If notebook document is instance of Uri, use openNotebookDocument, else use the notebookDocument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this, 639caaf
Resolves: #24021