reversing course
This commit is contained in:
parent
b9d1dfae8e
commit
fc1fb5538d
|
@ -109,15 +109,13 @@ apparent the next time `nu` is next launched with that plugin registry file.
|
|||
let custom_path = call.get_flag(engine_state, stack, "plugin-config")?;
|
||||
|
||||
// Start the plugin manually, to get the freshest signatures and to not affect engine
|
||||
// state. Provide a GC config that will stop it ASAP. We don't pass ctrlc_handlers since
|
||||
// this instance is temporary and won't be used to run commands.
|
||||
// state. Provide a GC config that will stop it ASAP.
|
||||
let plugin = Arc::new(PersistentPlugin::new(
|
||||
identity,
|
||||
PluginGcConfig {
|
||||
enabled: true,
|
||||
stop_after: 0,
|
||||
},
|
||||
None,
|
||||
));
|
||||
let interface = plugin.clone().get_plugin(Some((engine_state, stack)))?;
|
||||
let metadata = interface.get_metadata()?;
|
||||
|
|
|
@ -295,11 +295,7 @@ pub fn add_plugin_to_working_set(
|
|||
|
||||
// Add it to / get it from the working set
|
||||
let plugin = working_set.find_or_create_plugin(identity, || {
|
||||
Arc::new(PersistentPlugin::new(
|
||||
identity.clone(),
|
||||
gc_config.clone(),
|
||||
working_set.permanent_state.ctrlc_handlers.clone(),
|
||||
))
|
||||
Arc::new(PersistentPlugin::new(identity.clone(), gc_config.clone()))
|
||||
});
|
||||
|
||||
plugin.set_gc_config(&gc_config);
|
||||
|
|
|
@ -37,8 +37,8 @@ struct MutableState {
|
|||
preferred_mode: Option<PreferredCommunicationMode>,
|
||||
/// Garbage collector config
|
||||
gc_config: PluginGcConfig,
|
||||
/// Pool of ctrl-c handlers to subscribe to
|
||||
ctrlc_handlers: Option<ctrlc::Handlers>,
|
||||
/// RAII guard for this plugin's ctrl-c handler
|
||||
ctrlc_guard: Option<ctrlc::Guard>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
@ -54,17 +54,11 @@ struct RunningPlugin {
|
|||
interface: PluginInterface,
|
||||
/// Garbage collector for the plugin
|
||||
gc: PluginGc,
|
||||
/// RAII guard for this plugin's ctrl-c handler
|
||||
_ctrlc_guard: Option<ctrlc::Guard>,
|
||||
}
|
||||
|
||||
impl PersistentPlugin {
|
||||
/// Create a new persistent plugin. The plugin will not be spawned immediately.
|
||||
pub fn new(
|
||||
identity: PluginIdentity,
|
||||
gc_config: PluginGcConfig,
|
||||
ctrlc_handlers: Option<ctrlc::Handlers>,
|
||||
) -> PersistentPlugin {
|
||||
pub fn new(identity: PluginIdentity, gc_config: PluginGcConfig) -> PersistentPlugin {
|
||||
PersistentPlugin {
|
||||
identity,
|
||||
mutable: Mutex::new(MutableState {
|
||||
|
@ -72,7 +66,7 @@ impl PersistentPlugin {
|
|||
metadata: None,
|
||||
preferred_mode: None,
|
||||
gc_config,
|
||||
ctrlc_handlers,
|
||||
ctrlc_guard: None,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -220,22 +214,7 @@ impl PersistentPlugin {
|
|||
return self.spawn(envs, mutable);
|
||||
}
|
||||
|
||||
let guard = mutable
|
||||
.ctrlc_handlers
|
||||
.as_mut()
|
||||
.map(|ctrlc_handlers| {
|
||||
let interface = interface.clone();
|
||||
ctrlc_handlers.register(Box::new(move || {
|
||||
let _ = interface.ctrlc();
|
||||
}))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
mutable.running = Some(RunningPlugin {
|
||||
interface,
|
||||
gc,
|
||||
_ctrlc_guard: guard.clone(),
|
||||
});
|
||||
mutable.running = Some(RunningPlugin { interface, gc });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -320,6 +299,12 @@ impl RegisteredPlugin for PersistentPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
fn set_ctrlc_handler_guard(&self, guard: ctrlc::Guard) {
|
||||
if let Ok(mut mutable) = self.mutable.lock() {
|
||||
mutable.ctrlc_guard = Some(guard);
|
||||
}
|
||||
}
|
||||
|
||||
fn as_any(self: Arc<Self>) -> Arc<dyn std::any::Any + Send + Sync> {
|
||||
self
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
|||
|
||||
use nu_plugin_engine::{GetPlugin, PluginInterface};
|
||||
use nu_protocol::{
|
||||
engine::{EngineState, Stack},
|
||||
engine::{ctrlc, EngineState, Stack},
|
||||
PluginGcConfig, PluginIdentity, PluginMetadata, RegisteredPlugin, ShellError,
|
||||
};
|
||||
|
||||
|
@ -52,6 +52,10 @@ impl RegisteredPlugin for FakePersistentPlugin {
|
|||
// We don't have a GC
|
||||
}
|
||||
|
||||
fn set_ctrlc_handler_guard(&self, _guard: ctrlc::Guard) {
|
||||
// We don't have a Ctrl-C handler
|
||||
}
|
||||
|
||||
fn stop(&self) -> Result<(), ShellError> {
|
||||
// We can't stop
|
||||
Ok(())
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{any::Any, sync::Arc};
|
||||
|
||||
use crate::{PluginGcConfig, PluginIdentity, PluginMetadata, ShellError};
|
||||
use crate::{engine::ctrlc, PluginGcConfig, PluginIdentity, PluginMetadata, ShellError};
|
||||
|
||||
/// Trait for plugins registered in the [`EngineState`](crate::engine::EngineState).
|
||||
pub trait RegisteredPlugin: Send + Sync {
|
||||
|
@ -22,6 +22,9 @@ pub trait RegisteredPlugin: Send + Sync {
|
|||
/// Set garbage collection config for the plugin.
|
||||
fn set_gc_config(&self, gc_config: &PluginGcConfig);
|
||||
|
||||
/// Set a reference to the raii guard for the plugin's Ctrl-C handler.
|
||||
fn set_ctrlc_handler_guard(&self, guard: ctrlc::Guard);
|
||||
|
||||
/// Stop the plugin.
|
||||
fn stop(&self) -> Result<(), ShellError>;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user