Show kernel options in a picker (#20274)
Closes #18341 * [x] Remove "Change Kernel" Doc link from REPL menu * [x] Remove chevron * [x] Set a higher min width * [x] Include the language along with the kernel name Future PRs will address * Add support for Python envs (#18291, #16757, #15563) * Add support for Remote kernels * Project settings support (#16898) Release Notes: - Added kernel picker for repl --------- Co-authored-by: Nate Butler <iamnbutler@gmail.com>
This commit is contained in:
parent
f6d4a73c34
commit
36fe364c05
13 changed files with 492 additions and 63 deletions
|
@ -12,6 +12,56 @@ use crate::repl_store::ReplStore;
|
|||
use crate::session::SessionEvent;
|
||||
use crate::{KernelSpecification, Session};
|
||||
|
||||
pub fn assign_kernelspec(
|
||||
kernel_specification: KernelSpecification,
|
||||
weak_editor: WeakView<Editor>,
|
||||
cx: &mut WindowContext,
|
||||
) -> Result<()> {
|
||||
let store = ReplStore::global(cx);
|
||||
if !store.read(cx).is_enabled() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let fs = store.read(cx).fs().clone();
|
||||
let telemetry = store.read(cx).telemetry().clone();
|
||||
|
||||
if let Some(session) = store.read(cx).get_session(weak_editor.entity_id()).cloned() {
|
||||
// Drop previous session, start new one
|
||||
session.update(cx, |session, cx| {
|
||||
session.clear_outputs(cx);
|
||||
session.shutdown(cx);
|
||||
cx.notify();
|
||||
});
|
||||
}
|
||||
|
||||
let session = cx
|
||||
.new_view(|cx| Session::new(weak_editor.clone(), fs, telemetry, kernel_specification, cx));
|
||||
|
||||
weak_editor
|
||||
.update(cx, |_editor, cx| {
|
||||
cx.notify();
|
||||
|
||||
cx.subscribe(&session, {
|
||||
let store = store.clone();
|
||||
move |_this, _session, event, cx| match event {
|
||||
SessionEvent::Shutdown(shutdown_event) => {
|
||||
store.update(cx, |store, _cx| {
|
||||
store.remove_session(shutdown_event.entity_id());
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
})
|
||||
.ok();
|
||||
|
||||
store.update(cx, |store, _cx| {
|
||||
store.insert_session(weak_editor.entity_id(), session.clone());
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run(editor: WeakView<Editor>, move_down: bool, cx: &mut WindowContext) -> Result<()> {
|
||||
let store = ReplStore::global(cx);
|
||||
if !store.read(cx).is_enabled() {
|
||||
|
@ -96,9 +146,10 @@ pub fn run(editor: WeakView<Editor>, move_down: bool, cx: &mut WindowContext) ->
|
|||
anyhow::Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum SessionSupport {
|
||||
ActiveSession(View<Session>),
|
||||
Inactive(Box<KernelSpecification>),
|
||||
Inactive(KernelSpecification),
|
||||
RequiresSetup(LanguageName),
|
||||
Unsupported,
|
||||
}
|
||||
|
@ -119,7 +170,7 @@ pub fn session(editor: WeakView<Editor>, cx: &mut WindowContext) -> SessionSuppo
|
|||
});
|
||||
|
||||
match kernelspec {
|
||||
Some(kernelspec) => SessionSupport::Inactive(Box::new(kernelspec)),
|
||||
Some(kernelspec) => SessionSupport::Inactive(kernelspec),
|
||||
None => {
|
||||
if language_supported(&language) {
|
||||
SessionSupport::RequiresSetup(language.name())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue