mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 10:38:07 +02:00
Allow adding module blocks to engine state
This commit is contained in:
@ -17,6 +17,7 @@ pub struct ScopeFrame {
|
||||
vars: HashMap<Vec<u8>, VarId>,
|
||||
decls: HashMap<Vec<u8>, DeclId>,
|
||||
aliases: HashMap<Vec<u8>, Vec<Span>>,
|
||||
modules: HashMap<Vec<u8>, BlockId>,
|
||||
}
|
||||
|
||||
impl ScopeFrame {
|
||||
@ -25,6 +26,7 @@ impl ScopeFrame {
|
||||
vars: HashMap::new(),
|
||||
decls: HashMap::new(),
|
||||
aliases: HashMap::new(),
|
||||
modules: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,6 +292,23 @@ impl<'a> StateWorkingSet<'a> {
|
||||
self.num_blocks() - 1
|
||||
}
|
||||
|
||||
pub fn add_module(&mut self, name: &str, block: Block) -> BlockId {
|
||||
let name = name.as_bytes().to_vec();
|
||||
|
||||
self.delta.blocks.push(block);
|
||||
let block_id = self.num_blocks() - 1;
|
||||
|
||||
let scope_frame = self
|
||||
.delta
|
||||
.scope
|
||||
.last_mut()
|
||||
.expect("internal error: missing required scope frame");
|
||||
|
||||
scope_frame.modules.insert(name, block_id);
|
||||
|
||||
block_id
|
||||
}
|
||||
|
||||
pub fn next_span_start(&self) -> usize {
|
||||
self.permanent_state.next_span_start() + self.delta.file_contents.len()
|
||||
}
|
||||
|
Reference in New Issue
Block a user