Set the working directory according to the editor file path (#14688)

Kernels now launch in the same directory as the script invoking them,
similar to notebook behavior.


![image](https://github.com/user-attachments/assets/def86308-bea4-4fa3-8211-132a282a5ecc)


Release Notes:

- N/A
This commit is contained in:
Kyle Kelley 2024-07-17 15:37:47 -07:00 committed by GitHub
parent f5f4578422
commit ba4fa17b83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 52 additions and 17 deletions

View file

@ -131,7 +131,7 @@ use std::{
mem,
num::NonZeroU32,
ops::{ControlFlow, Deref, DerefMut, Not as _, Range, RangeInclusive},
path::Path,
path::{Path, PathBuf},
rc::Rc,
sync::Arc,
time::{Duration, Instant},
@ -10386,6 +10386,22 @@ impl Editor {
cx.notify();
}
pub fn working_directory(&self, cx: &WindowContext) -> Option<PathBuf> {
if let Some(buffer) = self.buffer().read(cx).as_singleton() {
if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local()) {
if let Some(dir) = file.abs_path(cx).parent() {
return Some(dir.to_owned());
}
}
if let Some(project_path) = buffer.read(cx).project_path(cx) {
return Some(project_path.path.to_path_buf());
}
}
None
}
pub fn reveal_in_finder(&mut self, _: &RevealInFileManager, cx: &mut ViewContext<Self>) {
if let Some(buffer) = self.buffer().read(cx).as_singleton() {
if let Some(file) = buffer.read(cx).file().and_then(|f| f.as_local()) {