mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 04:45:04 +02:00
Allow viewing the source code of blocks (#894)
* Add spans to blocks and view command * Better description; Cleanup * Rename "view" command to "view-source"
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
use crate::{Signature, VarId};
|
||||
use crate::{Signature, Span, VarId};
|
||||
|
||||
use super::Statement;
|
||||
|
||||
@ -10,6 +10,7 @@ pub struct Block {
|
||||
pub stmts: Vec<Statement>,
|
||||
pub captures: Vec<VarId>,
|
||||
pub redirect_env: bool,
|
||||
pub span: Option<Span>, // None option encodes no span to avoid using test_span()
|
||||
}
|
||||
|
||||
impl Block {
|
||||
@ -49,6 +50,7 @@ impl Block {
|
||||
stmts: vec![],
|
||||
captures: vec![],
|
||||
redirect_env: false,
|
||||
span: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -63,6 +65,7 @@ where
|
||||
stmts: stmts.collect(),
|
||||
captures: vec![],
|
||||
redirect_env: false,
|
||||
span: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{BlockId, DeclId};
|
||||
use crate::{BlockId, DeclId, Span};
|
||||
|
||||
use indexmap::IndexMap;
|
||||
|
||||
@ -10,6 +10,7 @@ use indexmap::IndexMap;
|
||||
pub struct Overlay {
|
||||
pub decls: IndexMap<Vec<u8>, DeclId>,
|
||||
pub env_vars: IndexMap<Vec<u8>, BlockId>,
|
||||
pub span: Option<Span>,
|
||||
}
|
||||
|
||||
impl Overlay {
|
||||
@ -17,6 +18,15 @@ impl Overlay {
|
||||
Overlay {
|
||||
decls: IndexMap::new(),
|
||||
env_vars: IndexMap::new(),
|
||||
span: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_span(span: Span) -> Self {
|
||||
Overlay {
|
||||
decls: IndexMap::new(),
|
||||
env_vars: IndexMap::new(),
|
||||
span: Some(span),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user