mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 00:54:56 +02:00
Allow adding definitions from module into scope
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
use crate::Signature;
|
||||
use crate::{Signature, DeclId};
|
||||
|
||||
use super::Statement;
|
||||
|
||||
@ -8,7 +8,7 @@ use super::Statement;
|
||||
pub struct Block {
|
||||
pub signature: Box<Signature>,
|
||||
pub stmts: Vec<Statement>,
|
||||
pub exports: Vec<Vec<u8>>, // Assuming just defs for now
|
||||
pub exports: Vec<(Vec<u8>, DeclId)>, // Assuming just defs for now
|
||||
}
|
||||
|
||||
impl Block {
|
||||
@ -50,7 +50,7 @@ impl Block {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_exports(self, exports: Vec<Vec<u8>>) -> Self {
|
||||
pub fn with_exports(self, exports: Vec<(Vec<u8>, DeclId)>) -> Self {
|
||||
Self {
|
||||
signature: self.signature,
|
||||
stmts: self.stmts,
|
||||
|
@ -312,6 +312,20 @@ impl<'a> StateWorkingSet<'a> {
|
||||
block_id
|
||||
}
|
||||
|
||||
pub fn activate_overlay(&mut self, overlay: Vec<(Vec<u8>, DeclId)>) {
|
||||
// TODO: This will overwrite all existing definitions in a scope. When we add deactivate,
|
||||
// we need to re-think how make it recoverable.
|
||||
let scope_frame = self
|
||||
.delta
|
||||
.scope
|
||||
.last_mut()
|
||||
.expect("internal error: missing required scope frame");
|
||||
|
||||
for (name, decl_id) in overlay {
|
||||
scope_frame.decls.insert(name, decl_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