Skip to content

Commit

Permalink
Use name instead of absolute path for diagnostics.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Feb 20, 2024
1 parent ac3d37e commit c3536a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
22 changes: 12 additions & 10 deletions bindgen/codegen/mod.rs
Expand Up @@ -4385,12 +4385,13 @@ fn unsupported_abi_diagnostic(
..
}) = location.cloned()
{
let file_path = file.path();
if let Ok(Some(source)) = get_line(&file_path, line) {
if let Ok(Some(source)) = get_line(file.path(), line) {
let mut slice = Slice::default();
slice
.with_source(source)
.with_location(file_path, line, column);
slice.with_source(source).with_location(
file.name(),
line,
column,
);
diag.add_slice(slice);
}
}
Expand Down Expand Up @@ -4427,12 +4428,13 @@ fn variadic_fn_diagnostic(
..
}) = location.cloned()
{
let file_path = file.path();
if let Ok(Some(source)) = get_line(&file_path, line) {
if let Ok(Some(source)) = get_line(file.path(), line) {
let mut slice = Slice::default();
slice
.with_source(source)
.with_location(file_path, line, column);
slice.with_source(source).with_location(
file.name(),
line,
column,
);
diag.add_slice(slice);
}
}
Expand Down
15 changes: 7 additions & 8 deletions bindgen/diagnostics.rs
Expand Up @@ -110,7 +110,7 @@ impl<'a> Diagnostic<'a> {
slices.push(ExtSlice {
source: source.as_ref(),
line_start: slice.line.unwrap_or_default(),
origin: slice.filename.as_deref(),
origin: slice.origin.as_deref(),
annotations: vec![],
fold: false,
})
Expand Down Expand Up @@ -146,9 +146,9 @@ impl<'a> Diagnostic<'a> {
/// A slice of source code.
#[derive(Default)]
pub(crate) struct Slice<'a> {
source: Option<Cow<'a, str>>,
filename: Option<String>,
line: Option<usize>,
origin: Option<String>,
source: Option<Cow<'a, str>>,
}

impl<'a> Slice<'a> {
Expand All @@ -162,15 +162,14 @@ impl<'a> Slice<'a> {
}

/// Set the file, line and column.
pub(crate) fn with_location<P: AsRef<Path>>(
pub(crate) fn with_location(
&mut self,
path: P,
file_name: &str,
line: usize,
col: usize,
column: usize,
) -> &mut Self {
self.filename =
Some(format!("{}:{}:{}", path.as_ref().display(), line, col));
self.line = Some(line);
self.origin = Some(format!("{file_name}:{line}:{column}"));
self
}
}
Expand Down
5 changes: 2 additions & 3 deletions bindgen/ir/var.rs
Expand Up @@ -474,11 +474,10 @@ fn duplicated_macro_diagnostic(
file, line, column, ..
} = location
{
let file_path = file.path();
if let Ok(Some(code)) = get_line(&file_path, line) {
if let Ok(Some(code)) = get_line(file.path(), line) {
source = code.into();
}
slice.with_location(file_path, line, column);
slice.with_location(file.name(), line, column);
}

slice.with_source(source);
Expand Down

0 comments on commit c3536a5

Please sign in to comment.