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

Handle reloading of REPL Window #24148

Merged
merged 26 commits into from
Nov 19, 2024
Merged

Conversation

anthonykim1
Copy link

Resolves: #24021

@anthonykim1 anthonykim1 self-assigned this Sep 21, 2024
@anthonykim1 anthonykim1 added area-repl feature-request Request for new features or functionality labels Sep 21, 2024
@anthonykim1 anthonykim1 added bug Issue identified by VS Code Team member as probable bug and removed feature-request Request for new features or functionality labels Nov 18, 2024
@anthonykim1 anthonykim1 marked this pull request as ready for review November 18, 2024 08:16
@vs-code-engineering vs-code-engineering bot added this to the November 2024 milestone Nov 18, 2024
src/client/repl/nativeRepl.ts Outdated Show resolved Hide resolved
src/client/repl/nativeRepl.ts Outdated Show resolved Hide resolved
src/test/repl/nativeRepl.test.ts Outdated Show resolved Hide resolved
@anthonykim1 anthonykim1 marked this pull request as draft November 19, 2024 00:23
@anthonykim1 anthonykim1 marked this pull request as ready for review November 19, 2024 00:26
@anthonykim1 anthonykim1 marked this pull request as draft November 19, 2024 00:27
@anthonykim1 anthonykim1 marked this pull request as ready for review November 19, 2024 04:28
src/client/repl/nativeRepl.ts Outdated Show resolved Hide resolved
src/client/repl/nativeRepl.ts Outdated Show resolved Hide resolved
wsMementoUri = wsMemento ? Uri.parse(wsMemento) : undefined;

if (!wsMementoUri || getTabNameForUri(wsMementoUri) !== 'Python REPL') {
await this.cleanRepl();
Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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?

Copy link
Author

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);
Copy link
Member

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.

Copy link
Author

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,
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

I love this, 639caaf

@anthonykim1 anthonykim1 marked this pull request as draft November 19, 2024 15:48
@anthonykim1 anthonykim1 marked this pull request as ready for review November 19, 2024 16:31
@anthonykim1 anthonykim1 merged commit 8ac716d into microsoft:main Nov 19, 2024
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-repl bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

REPL: support window reload
3 participants