difftreelog
feat move trace mapping api to evaluator
in: master
4 files changed
cmds/jrsonnet/src/location.rsdiffbeforeafterbothno changes
cmds/jrsonnet/src/main.rsdiffbeforeafterboth1pub mod location;23use clap::Clap;1use clap::Clap;4use jrsonnet_evaluator::{EvaluationState, LocError, StackTrace, Val};2use jrsonnet_evaluator::{trace::CodeLocation, EvaluationState, LocError, StackTrace, Val};5use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, LocExpr, ParserSettings};3use jrsonnet_parser::{el, Arg, ArgsDesc, Expr, LocExpr, ParserSettings};6use location::{offset_to_location, CodeLocation};7use std::env::current_dir;4use std::env::current_dir;8use std::{collections::HashMap, path::PathBuf, rc::Rc, str::FromStr};5use std::{collections::HashMap, path::PathBuf, rc::Rc, str::FromStr};96252 for item in trace.0.iter() {249 for item in trace.0.iter() {253 let desc = &item.1;250 let desc = &item.1;254 let source = item.0.clone();251 let source = item.0.clone();255 let code = evaluator.get_source(&source.0);256 if code.is_none() {257 continue;258 }259 let code = code.unwrap();260 let start_end = offset_to_location(&code, &[source.1, source.2]);252 let start_end = evaluator.map_source_locations(&source.0, &[source.1, source.2]);261 if opts.trace_format == TraceFormat::Custom {253 if opts.trace_format == TraceFormat::Custom {262 let source_fragment: String = code254 let source_fragment: String = evaluator255 .get_source(&source.0)256 .unwrap()263 .chars()257 .chars()264 .skip(start_end[0].line_start_offset)258 .skip(start_end[0].line_start_offset)265 .take(start_end[1].line_end_offset - start_end[0].line_start_offset)259 .take(start_end[1].line_end_offset - start_end[0].line_start_offset)crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth16mod map;16mod map;17mod obj;17mod obj;18mod val;18mod val;19pub mod trace;192020pub use ctx::*;21pub use ctx::*;21pub use dynamic::*;22pub use dynamic::*;27pub use obj::*;28pub use obj::*;28use std::{cell::{Ref, RefCell, RefMut}, collections::HashMap, fmt::Debug, path::PathBuf, rc::Rc};29use std::{cell::{Ref, RefCell, RefMut}, collections::HashMap, fmt::Debug, path::PathBuf, rc::Rc};29pub use val::*;30pub use val::*;31use trace::{offset_to_location, CodeLocation};303231type BindableFn = dyn Fn(Option<ObjValue>, Option<ObjValue>) -> Result<LazyVal>;33type BindableFn = dyn Fn(Option<ObjValue>, Option<ObjValue>) -> Result<LazyVal>;32#[derive(Clone)]34#[derive(Clone)]187 let ro_map = &self.data().files;189 let ro_map = &self.data().files;188 ro_map.get(name).map(|value| value.0.clone())190 ro_map.get(name).map(|value| value.0.clone())189 }191 }192 pub fn map_source_locations(&self, file: &PathBuf, locs: &[usize]) -> Vec<CodeLocation> {193 offset_to_location(&self.get_source(file).unwrap(), locs)194 }195190 pub fn evaluate_file(&self, name: &PathBuf) -> Result<Val> {196 pub fn evaluate_file(&self, name: &PathBuf) -> Result<Val> {191 self.run_in_state(|| {197 self.run_in_state(|| {crates/jrsonnet-evaluator/src/trace.rsdiffbeforeafterbothno changes