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:
Jakub Žádník
2022-01-31 00:05:25 +02:00
committed by GitHub
parent 67cb720f24
commit 2fbd182993
7 changed files with 122 additions and 3 deletions

View File

@ -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,
}
}
}

View File

@ -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),
}
}