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

Deliver working directory changes to Positron #133

Merged
merged 8 commits into from
Nov 1, 2023

Conversation

jmcphers
Copy link
Contributor

This change is a companion to posit-dev/positron#1740; it causes ark to emit events to Positron when the working directory changes. The events are emitted over the frontend comm, and are always fed to the comm when it is first created so that Positron has a view of the initial working directory.

This change doesn't depend on posit-dev/positron#1740, nor does posit-dev/positron#1740 depend on it; they can be merged independently.

Comment on lines 74 to 80
// Get the current busy status
let busy = r_task(|| {
let main = RMain::get();
main.is_busy
});
self.send_event(PositronEvent::Busy(BusyEvent { busy }));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you help me understand why you need to send this here? When the busy status changed in fn busy(), this positron event was fired immediately.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried removing this and everything still seems to work fine

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I think I see.

This is establishing an initial link to the frontend, which might also happen on reconnect right? Like CMD+R where the frontend is refreshed but the Kernel is persistent and gets reconnected?

So we have to forward on the initial working directory and initial busy state of the reconnected Kernel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's it exactly. There is no way for the frontend to query for this state so we just send it on over as soon as the frontend connects, then deliver updates whenever it changes.

I just added the busy changes since I was in the neighborhood; I think we'll need them to fix posit-dev/positron#1243 (though this PR does not entirely fix that issue).

Zooming out a little more I think we will need to have some idea of a session state that encompasses all of the stuff the client needs to know, in one bundle. But one step at a time. :-)

/// front end if the working directory has changed.
pub fn poll_working_directory(&mut self) -> Result<()> {
// Get the current working directory
let mut current_dir = std::env::current_dir()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I was curious about current_dir() so I looked at the docs, which say:

This function currently corresponds to the getcwd function on Unix and the GetCurrentDirectoryW function on Windows.

And that corresponds pretty nicely to what R's getwd() does!

https://github.com/wch/r-source/blob/458cfb5da5609ac46ee7d7f38041c6576755d482/src/main/util.c#L765-L792

The only thing I note is that in R it looks like \\ is turned into / on Windows by this helper
https://github.com/wch/r-source/blob/458cfb5da5609ac46ee7d7f38041c6576755d482/src/main/util.c#L1726-L1733

I figure we can deal with that if it gets confusing once I get a Windows computer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I intentionally avoided any explicit mention of path separators here and I'm hopeful that'll get us where we need to be on Windows!


// Get the current busy status
let busy = r_task(|| {
let main = RMain::get();
Copy link
Contributor

Choose a reason for hiding this comment

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

I am mildly worried about the fact that RMain might not be available at this point in time. Technically kernel.connect() (which sets up the shell thread to listen to comm open messages that might call this) is called before start_r() (which sets up RMain). It's like we need RMain::initialized() which could return false if R_MAIN is None, in which case you could return false for the Busy state here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea; implemented in 8c1baab.

crates/ark/src/kernel.rs Outdated Show resolved Hide resolved
crates/ark/src/interface.rs Outdated Show resolved Hide resolved
jmcphers and others added 2 commits November 1, 2023 08:15
Co-authored-by: Davis Vaughan <davis@rstudio.com>
Co-authored-by: Davis Vaughan <davis@rstudio.com>
@jmcphers jmcphers merged commit 5e07438 into main Nov 1, 2023
1 check passed
@DavisVaughan DavisVaughan deleted the feature/current-working-directory branch October 14, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants