Implement RunningKernel trait for native and remote kernels (#20934)

This PR introduces a unified interface for both native and remote
kernels through the `RunningKernel` trait. When either the native kernel
or the remote kernels are started, they return a `Box<dyn
RunningKernel>` to make it easier to work with the session. As a bonus
of this refactor, I've dropped some of the mpsc channels to instead opt
for passing messages directly to `session.route(message)`. There was a
lot of simplification of `Session` by moving responsibilities to
`NativeRunningKernel`.

No release notes yet until this is finalized.

* [x] Detect remote kernelspecs from configured remote servers
* [x] Launch kernel on demand

For now, this allows you to set env vars `JUPYTER_SERVER` and
`JUPYTER_TOKEN` to access a remote server. `JUPYTER_SERVER` should be a
base path like `http://localhost:8888` or
`https://notebooks.gesis.org/binder/jupyter/user/rubydata-binder-w6igpy4l/`

Release Notes:

- N/A
This commit is contained in:
Kyle Kelley 2024-11-21 14:00:19 -08:00 committed by GitHub
parent f74f670865
commit 72613b7668
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 478 additions and 230 deletions

View file

@ -6,7 +6,7 @@ use futures::{
future::Shared,
stream,
};
use gpui::{AppContext, Model, Task};
use gpui::{AppContext, Model, Task, WindowContext};
use language::LanguageName;
pub use native_kernel::*;
@ -16,7 +16,7 @@ pub use remote_kernels::*;
use anyhow::Result;
use runtimelib::{ExecutionState, JupyterKernelspec, JupyterMessage, KernelInfoReply};
use ui::SharedString;
use ui::{Icon, IconName, SharedString};
pub type JupyterMessageChannel = stream::SelectAll<Receiver<JupyterMessage>>;
@ -59,6 +59,19 @@ impl KernelSpecification {
Self::Remote(spec) => spec.kernelspec.language.clone(),
})
}
pub fn icon(&self, cx: &AppContext) -> Icon {
let lang_name = match self {
Self::Jupyter(spec) => spec.kernelspec.language.clone(),
Self::PythonEnv(spec) => spec.kernelspec.language.clone(),
Self::Remote(spec) => spec.kernelspec.language.clone(),
};
file_icons::FileIcons::get(cx)
.get_type_icon(&lang_name.to_lowercase())
.map(Icon::from_path)
.unwrap_or(Icon::new(IconName::ReplNeutral))
}
}
pub fn python_env_kernel_specifications(
@ -134,7 +147,7 @@ pub trait RunningKernel: Send + Debug {
fn set_execution_state(&mut self, state: ExecutionState);
fn kernel_info(&self) -> Option<&KernelInfoReply>;
fn set_kernel_info(&mut self, info: KernelInfoReply);
fn force_shutdown(&mut self) -> anyhow::Result<()>;
fn force_shutdown(&mut self, cx: &mut WindowContext) -> Task<anyhow::Result<()>>;
}
#[derive(Debug, Clone)]