[fine] File name in error messages
Going to need to normalize that name though, because right now it really *really* sucks to have a big \\?\ kinda name. Probably normalize it relative to the base directory.
This commit is contained in:
parent
a21f18da6e
commit
1199646e29
16 changed files with 52 additions and 34 deletions
|
|
@ -23,28 +23,36 @@ use std::{
|
|||
// that will have to wait for now
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Error {
|
||||
pub file: Rc<str>,
|
||||
pub start: (usize, usize),
|
||||
pub end: (usize, usize),
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub fn new<T>(line: usize, column: usize, message: T) -> Self
|
||||
pub fn new<T>(file: Rc<str>, line: usize, column: usize, message: T) -> Self
|
||||
where
|
||||
T: ToString,
|
||||
{
|
||||
Error {
|
||||
file,
|
||||
start: (line, column),
|
||||
end: (line, column),
|
||||
message: message.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_spanned<T>(start: (usize, usize), end: (usize, usize), message: T) -> Self
|
||||
pub fn new_spanned<T>(
|
||||
file: Rc<str>,
|
||||
start: (usize, usize),
|
||||
end: (usize, usize),
|
||||
message: T,
|
||||
) -> Self
|
||||
where
|
||||
T: ToString,
|
||||
{
|
||||
Error {
|
||||
file,
|
||||
start,
|
||||
end,
|
||||
message: message.to_string(),
|
||||
|
|
@ -60,7 +68,11 @@ impl fmt::Debug for Error {
|
|||
|
||||
impl fmt::Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}:{}: {}", self.start.0, self.start.1, self.message)
|
||||
write!(
|
||||
f,
|
||||
"{}:{}:{}: {}",
|
||||
self.file, self.start.0, self.start.1, self.message
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -622,6 +634,7 @@ enum Incremental<T> {
|
|||
}
|
||||
|
||||
pub struct Semantics {
|
||||
file: Rc<str>,
|
||||
source: Rc<str>,
|
||||
syntax_tree: Rc<SyntaxTree>,
|
||||
lines: Rc<Lines>,
|
||||
|
|
@ -641,7 +654,7 @@ pub struct Semantics {
|
|||
}
|
||||
|
||||
impl Semantics {
|
||||
pub fn new(source: Rc<str>, tree: Rc<SyntaxTree>, lines: Rc<Lines>) -> Self {
|
||||
pub fn new(file: Rc<str>, source: Rc<str>, tree: Rc<SyntaxTree>, lines: Rc<Lines>) -> Self {
|
||||
let mut logical_parents = vec![None; tree.len()];
|
||||
if let Some(root) = tree.root() {
|
||||
set_logical_parents(&mut logical_parents, &tree, root, None);
|
||||
|
|
@ -650,6 +663,7 @@ impl Semantics {
|
|||
let root_environment = Environment::new(None, Location::Module);
|
||||
|
||||
let mut semantics = Semantics {
|
||||
file,
|
||||
source,
|
||||
syntax_tree: tree.clone(),
|
||||
lines,
|
||||
|
|
@ -730,9 +744,12 @@ impl Semantics {
|
|||
{
|
||||
let start = self.lines.position(start);
|
||||
let end = self.lines.position(end);
|
||||
self.errors
|
||||
.borrow_mut()
|
||||
.push(Error::new_spanned(start, end, error.to_string()));
|
||||
self.errors.borrow_mut().push(Error::new_spanned(
|
||||
self.file.clone(),
|
||||
start,
|
||||
end,
|
||||
error.to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
fn report_error_tree<T>(&self, tree: &Tree, error: T)
|
||||
|
|
@ -2801,7 +2818,7 @@ mod tests {
|
|||
pub fn ice() {
|
||||
let source: Rc<str> = "1+1".into();
|
||||
let (tree, lines) = parse(&source);
|
||||
let semantics = Semantics::new(source, tree.clone(), lines);
|
||||
let semantics = Semantics::new("__test__".into(), source, tree.clone(), lines);
|
||||
semantics.internal_compiler_error(tree.root(), "oh no");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue