mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 11:55:55 +02:00
Move from using a Block to an Arc'd Block (#3289)
This commit is contained in:
@ -61,7 +61,7 @@ impl Scope {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_custom_commands_with_name(&self, name: &str) -> Option<Vec<Block>> {
|
||||
pub fn get_custom_commands_with_name(&self, name: &str) -> Option<Vec<Arc<Block>>> {
|
||||
let custom_commands: Vec<_> = self
|
||||
.frames
|
||||
.lock()
|
||||
@ -307,7 +307,7 @@ impl ParserScope for Scope {
|
||||
self.get_command(name).is_some()
|
||||
}
|
||||
|
||||
fn add_definition(&self, block: Block) {
|
||||
fn add_definition(&self, block: Arc<Block>) {
|
||||
if let Some(frame) = self.frames.lock().last_mut() {
|
||||
let name = block.params.name.clone();
|
||||
frame.custom_commands.insert(name.clone(), block.clone());
|
||||
@ -315,7 +315,7 @@ impl ParserScope for Scope {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_definitions(&self) -> Vec<Block> {
|
||||
fn get_definitions(&self) -> Vec<Arc<Block>> {
|
||||
let mut blocks = vec![];
|
||||
if let Some(frame) = self.frames.lock().last() {
|
||||
for (_, custom_command) in &frame.custom_commands {
|
||||
@ -356,7 +356,7 @@ pub struct ScopeFrame {
|
||||
pub vars: IndexMap<String, Value>,
|
||||
pub env: IndexMap<String, String>,
|
||||
pub commands: IndexMap<String, Command>,
|
||||
pub custom_commands: IndexMap<String, Block>,
|
||||
pub custom_commands: IndexMap<String, Arc<Block>>,
|
||||
pub aliases: IndexMap<String, Vec<Spanned<String>>>,
|
||||
///Optional tag to better identify this scope frame later
|
||||
pub tag: Option<String>,
|
||||
|
@ -44,7 +44,7 @@ pub trait WholeStreamCommand: Send + Sync {
|
||||
// implement a WholeStreamCommand
|
||||
#[allow(clippy::suspicious_else_formatting)]
|
||||
|
||||
impl WholeStreamCommand for Block {
|
||||
impl WholeStreamCommand for Arc<Block> {
|
||||
fn name(&self) -> &str {
|
||||
&self.params.name
|
||||
}
|
||||
@ -61,7 +61,10 @@ impl WholeStreamCommand for Block {
|
||||
let call_info = args.call_info.clone();
|
||||
|
||||
let mut block = self.clone();
|
||||
block.set_redirect(call_info.args.external_redirection);
|
||||
|
||||
if let Some(block) = std::sync::Arc::<nu_protocol::hir::Block>::get_mut(&mut block) {
|
||||
block.set_redirect(call_info.args.external_redirection);
|
||||
}
|
||||
|
||||
let ctx = EvaluationContext::from_args(&args);
|
||||
let evaluated = call_info.evaluate(&ctx)?;
|
||||
|
Reference in New Issue
Block a user