difftreelog
feat(ir) source url
in: master
7 files changed
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth353536pub use ctx::*;36pub use ctx::*;37pub use dynamic::*;37pub use dynamic::*;38pub use error::{Error, ErrorKind::*, Result, ResultExt};38pub use error::{Error, ErrorKind::*, Result, ResultExt, StackTraceElement};39pub use evaluate::ensure_sufficient_stack;39pub use evaluate::ensure_sufficient_stack;40use function::CallLocation;40use function::CallLocation;41pub use import::*;41pub use import::*;42use jrsonnet_gcmodule::{Cc, Trace, cc_dyn};42use jrsonnet_gcmodule::{Cc, Trace, cc_dyn};43pub use jrsonnet_interner::{IBytes, IStr};43pub use jrsonnet_interner::{IBytes, IStr};44use jrsonnet_ir::Expr;44use jrsonnet_ir::Expr;45pub use jrsonnet_ir::{NumValue, Source, SourcePath, Span};45pub use jrsonnet_ir::{NumValue, Source, SourcePath, SourceUrl, SourceVirtual, Span};46#[doc(hidden)]46#[doc(hidden)]47pub use jrsonnet_macros;47pub use jrsonnet_macros;4848396 file.parsed = Some(396 file.parsed = Some(397 parse_jsonnet(&code, file_name.clone())397 parse_jsonnet(&code, file_name.clone())398 .map(Rc::new)398 .map(Rc::new)399 .map_err(|e| ImportSyntaxError {399 .map_err(|e| {400 let span = e.location.clone();401 let mut err = Error::from(ImportSyntaxError {400 path: file_name.clone(),402 path: file_name.clone(),401 error: Box::new(e),403 error: Box::new(e),402 })?,404 });405 err.trace_mut().0.push(StackTraceElement {406 location: Some(span),407 desc: "parse imported".to_string(),408 });409 err410 })?,403 );411 );404 }412 }405 let parsed = file.parsed.as_ref().expect("just set").clone();413 let parsed = file.parsed.as_ref().expect("just set").clone();crates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -82,18 +82,24 @@
) -> Result<(), std::fmt::Error> {
if start.line == end.line {
if start.column == end.column {
- write!(out, "{}:{}", start.line, end.column.saturating_sub(1))?;
+ write!(out, "{}:{}", start.line, start.column)?;
} else {
- write!(out, "{}:{}-{}", start.line, start.column - 1, end.column)?;
+ write!(
+ out,
+ "{}:{}-{}",
+ start.line,
+ start.column,
+ end.column.saturating_sub(1)
+ )?;
}
} else {
write!(
out,
"{}:{}-{}:{}",
- start.line,
- end.column.saturating_sub(1),
start.line,
- end.column
+ start.column,
+ end.line,
+ end.column.saturating_sub(1)
)?;
}
Ok(())
@@ -131,22 +137,13 @@
|| path.source_path().to_string(),
|r| self.resolver.resolve(r),
);
- let mut offset = error.location.1 as usize;
- let is_eof = if offset >= path.code().len() {
- offset = path.code().len().saturating_sub(1);
- true
- } else {
- false
- };
+ let offset = (error.location.1 as usize).min(path.code().len());
#[expect(clippy::cast_possible_truncation, reason = "code is limited by 4gb")]
- let mut location = path
+ let location = path
.map_source_locations(&[offset as u32])
.into_iter()
.next()
.unwrap();
- if is_eof {
- location.column += 1;
- }
write!(n, ":").unwrap();
print_code_location(&mut n, &location, &location).unwrap();
crates/jrsonnet-formatter/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-formatter/src/lib.rs
+++ b/crates/jrsonnet-formatter/src/lib.rs
@@ -895,10 +895,16 @@
}
}
+#[derive(Default)]
pub struct FormatOptions {
// 0 for hard tabs, otherwise number of spaces
pub indent: u8,
}
+impl FormatOptions {
+ pub fn new() -> Self {
+ Self::default()
+ }
+}
#[allow(
clippy::result_large_err,
crates/jrsonnet-ir-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir-parser/src/lib.rs
+++ b/crates/jrsonnet-ir-parser/src/lib.rs
@@ -220,10 +220,7 @@
fn ident(p: &mut Parser<'_>) -> Result<IStr> {
if !p.at(SyntaxKind::IDENT) {
- return Err(p.error(format!(
- "expected identifier, got {}",
- p.current_desc()
- )));
+ return Err(p.error(format!("expected identifier, got {}", p.current_desc())));
}
let text = p.text();
p.eat_any();
crates/jrsonnet-ir/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir/src/lib.rs
+++ b/crates/jrsonnet-ir/src/lib.rs
@@ -15,7 +15,7 @@
pub use location::CodeLocation;
pub use source::{
Source, SourceDefaultIgnoreJpath, SourceDirectory, SourceFifo, SourceFile, SourcePath,
- SourcePathT, SourceVirtual,
+ SourcePathT, SourceUrl, SourceVirtual,
};
// It seels to be a wrong place for this kind of stuff, but as it would also be used for static analysis and
crates/jrsonnet-ir/src/location.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir/src/location.rs
+++ b/crates/jrsonnet-ir/src/location.rs
@@ -29,7 +29,7 @@
return [CodeLocation::default(); S];
}
let mut line = 1;
- let mut column = 1;
+ let mut column = 0;
let max_offset = *offsets.iter().max().expect("offsets is not empty");
let mut offset_map = offsets
@@ -63,7 +63,7 @@
}
if ch == '\n' {
line += 1;
- column = 1;
+ column = 0;
for idx in with_no_known_line_ending.drain(..) {
out[idx].line_end_offset = pos;
@@ -98,14 +98,14 @@
CodeLocation {
offset: 0,
line: 1,
- column: 2,
+ column: 1,
line_start_offset: 0,
line_end_offset: 11,
},
CodeLocation {
offset: 14,
line: 2,
- column: 4,
+ column: 3,
line_start_offset: 12,
line_end_offset: 67
}
crates/jrsonnet-ir/src/source.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir/src/source.rs
+++ b/crates/jrsonnet-ir/src/source.rs
@@ -8,6 +8,7 @@
use jrsonnet_gcmodule::Acyclic;
use jrsonnet_interner::{IBytes, IStr};
+use url::Url;
use crate::location::{CodeLocation, location_to_offset, offset_to_location};
@@ -186,6 +187,28 @@
any_ext_impl!(SourcePathT);
}
+#[derive(Acyclic, Hash, PartialEq, Eq, Debug)]
+pub struct SourceUrl(Url);
+impl SourceUrl {
+ pub fn new(url: Url) -> Self {
+ Self(url)
+ }
+}
+impl Display for SourceUrl {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{}", self.0)
+ }
+}
+impl SourcePathT for SourceUrl {
+ fn is_default(&self) -> bool {
+ false
+ }
+ fn path(&self) -> Option<&Path> {
+ None
+ }
+ any_ext_impl!(SourcePathT);
+}
+
/// Represents path to the directory on the disk
///
/// See also [`SourceFile`]