git.delta.rocks / jrsonnet / refs/commits / 3738ed2a5354

difftreelog

feat(ir) source url

qkmunwwmYaroslav Bolyukin2026-05-05parent: #ede8518.patch.diff
in: master

7 files changed

modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
3535
36pub 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;
4848
396 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 err
410 })?,
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();
modifiedcrates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth
82) -> Result<(), std::fmt::Error> {82) -> Result<(), std::fmt::Error> {
83 if start.line == end.line {83 if start.line == end.line {
84 if start.column == end.column {84 if start.column == end.column {
85 write!(out, "{}:{}", start.line, end.column.saturating_sub(1))?;85 write!(out, "{}:{}", start.line, start.column)?;
86 } else {86 } else {
87 write!(out, "{}:{}-{}", start.line, start.column - 1, end.column)?;87 write!(
88 out,
89 "{}:{}-{}",
90 start.line,
91 start.column,
92 end.column.saturating_sub(1)
93 )?;
88 }94 }
89 } else {95 } else {
90 write!(96 write!(
91 out,97 out,
92 "{}:{}-{}:{}",98 "{}:{}-{}:{}",
93 start.line,99 start.line,
94 end.column.saturating_sub(1),100 start.column,
95 start.line,101 end.line,
96 end.column102 end.column.saturating_sub(1)
97 )?;103 )?;
98 }104 }
99 Ok(())105 Ok(())
131 || path.source_path().to_string(),137 || path.source_path().to_string(),
132 |r| self.resolver.resolve(r),138 |r| self.resolver.resolve(r),
133 );139 );
134 let mut offset = error.location.1 as usize;140 let offset = (error.location.1 as usize).min(path.code().len());
135 let is_eof = if offset >= path.code().len() {
136 offset = path.code().len().saturating_sub(1);
137 true
138 } else {
139 false
140 };
141 #[expect(clippy::cast_possible_truncation, reason = "code is limited by 4gb")]141 #[expect(clippy::cast_possible_truncation, reason = "code is limited by 4gb")]
142 let mut location = path142 let location = path
143 .map_source_locations(&[offset as u32])143 .map_source_locations(&[offset as u32])
144 .into_iter()144 .into_iter()
145 .next()145 .next()
146 .unwrap();146 .unwrap();
147 if is_eof {
148 location.column += 1;
149 }
150147
151 write!(n, ":").unwrap();148 write!(n, ":").unwrap();
152 print_code_location(&mut n, &location, &location).unwrap();149 print_code_location(&mut n, &location, &location).unwrap();
modifiedcrates/jrsonnet-formatter/src/lib.rsdiffbeforeafterboth
895 }895 }
896}896}
897897
898#[derive(Default)]
898pub struct FormatOptions {899pub struct FormatOptions {
899 // 0 for hard tabs, otherwise number of spaces900 // 0 for hard tabs, otherwise number of spaces
900 pub indent: u8,901 pub indent: u8,
901}902}
903impl FormatOptions {
904 pub fn new() -> Self {
905 Self::default()
906 }
907}
902908
903#[allow(909#[allow(
904 clippy::result_large_err,910 clippy::result_large_err,
modifiedcrates/jrsonnet-ir-parser/src/lib.rsdiffbeforeafterboth
220220
221fn ident(p: &mut Parser<'_>) -> Result<IStr> {221fn ident(p: &mut Parser<'_>) -> Result<IStr> {
222 if !p.at(SyntaxKind::IDENT) {222 if !p.at(SyntaxKind::IDENT) {
223 return Err(p.error(format!(223 return Err(p.error(format!("expected identifier, got {}", p.current_desc())));
224 "expected identifier, got {}",
225 p.current_desc()
226 )));
227 }224 }
228 let text = p.text();225 let text = p.text();
229 p.eat_any();226 p.eat_any();
modifiedcrates/jrsonnet-ir/src/lib.rsdiffbeforeafterboth
15pub use location::CodeLocation;15pub use location::CodeLocation;
16pub use source::{16pub use source::{
17 Source, SourceDefaultIgnoreJpath, SourceDirectory, SourceFifo, SourceFile, SourcePath,17 Source, SourceDefaultIgnoreJpath, SourceDirectory, SourceFifo, SourceFile, SourcePath,
18 SourcePathT, SourceVirtual,18 SourcePathT, SourceUrl, SourceVirtual,
19};19};
2020
21// It seels to be a wrong place for this kind of stuff, but as it would also be used for static analysis and21// It seels to be a wrong place for this kind of stuff, but as it would also be used for static analysis and
modifiedcrates/jrsonnet-ir/src/location.rsdiffbeforeafterboth
29 return [CodeLocation::default(); S];29 return [CodeLocation::default(); S];
30 }30 }
31 let mut line = 1;31 let mut line = 1;
32 let mut column = 1;32 let mut column = 0;
33 let max_offset = *offsets.iter().max().expect("offsets is not empty");33 let max_offset = *offsets.iter().max().expect("offsets is not empty");
3434
35 let mut offset_map = offsets35 let mut offset_map = offsets
63 }63 }
64 if ch == '\n' {64 if ch == '\n' {
65 line += 1;65 line += 1;
66 column = 1;66 column = 0;
6767
68 for idx in with_no_known_line_ending.drain(..) {68 for idx in with_no_known_line_ending.drain(..) {
69 out[idx].line_end_offset = pos;69 out[idx].line_end_offset = pos;
98 CodeLocation {98 CodeLocation {
99 offset: 0,99 offset: 0,
100 line: 1,100 line: 1,
101 column: 2,101 column: 1,
102 line_start_offset: 0,102 line_start_offset: 0,
103 line_end_offset: 11,103 line_end_offset: 11,
104 },104 },
105 CodeLocation {105 CodeLocation {
106 offset: 14,106 offset: 14,
107 line: 2,107 line: 2,
108 column: 4,108 column: 3,
109 line_start_offset: 12,109 line_start_offset: 12,
110 line_end_offset: 67110 line_end_offset: 67
111 }111 }
modifiedcrates/jrsonnet-ir/src/source.rsdiffbeforeafterboth
88
9use jrsonnet_gcmodule::Acyclic;9use jrsonnet_gcmodule::Acyclic;
10use jrsonnet_interner::{IBytes, IStr};10use jrsonnet_interner::{IBytes, IStr};
11use url::Url;
1112
12use crate::location::{CodeLocation, location_to_offset, offset_to_location};13use crate::location::{CodeLocation, location_to_offset, offset_to_location};
1314
186 any_ext_impl!(SourcePathT);187 any_ext_impl!(SourcePathT);
187}188}
189
190#[derive(Acyclic, Hash, PartialEq, Eq, Debug)]
191pub struct SourceUrl(Url);
192impl SourceUrl {
193 pub fn new(url: Url) -> Self {
194 Self(url)
195 }
196}
197impl Display for SourceUrl {
198 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
199 write!(f, "{}", self.0)
200 }
201}
202impl SourcePathT for SourceUrl {
203 fn is_default(&self) -> bool {
204 false
205 }
206 fn path(&self) -> Option<&Path> {
207 None
208 }
209 any_ext_impl!(SourcePathT);
210}
188211
189/// Represents path to the directory on the disk212/// Represents path to the directory on the disk
190///213///