mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Fix error filtering region math
This commit is contained in:
parent
167e8a40de
commit
560c984d30
5 changed files with 53 additions and 69 deletions
|
@ -42,18 +42,16 @@ impl Problems {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn compile_to_mono<'a>(
|
||||
pub fn compile_to_mono<'a, 'i, I: Iterator<Item = &'i str>>(
|
||||
arena: &'a Bump,
|
||||
src: &str,
|
||||
filter_problems_before_offset: usize,
|
||||
defs: I,
|
||||
expr: &str,
|
||||
target_info: TargetInfo,
|
||||
palette: Palette,
|
||||
) -> (Option<MonomorphizedModule<'a>>, Problems) {
|
||||
let filename = PathBuf::from("");
|
||||
let src_dir = PathBuf::from("fake/test/path");
|
||||
|
||||
let module_src = arena.alloc(promote_expr_to_module(src));
|
||||
|
||||
let (bytes_before_expr, module_src) = promote_expr_to_module(arena, defs, expr);
|
||||
let exposed_types = Default::default();
|
||||
let loaded = roc_load::load_and_monomorphize_from_str(
|
||||
arena,
|
||||
|
@ -114,15 +112,12 @@ pub fn compile_to_mono<'a>(
|
|||
// Report parsing and canonicalization problems
|
||||
let alloc = RocDocAllocator::new(&src_lines, *home, interns);
|
||||
|
||||
// Filter out all warnings and errors whose regions end before this,
|
||||
// because they must be part of the defs (excluding the most renently added def,
|
||||
// if that's the one being evaluated) and therefore not things we should show.
|
||||
// This filters out things like shadowing warnings and unused def warnings.
|
||||
let min_region = REPL_MODULE_WRAPPER.len() + INDENT.len() + filter_problems_before_offset;
|
||||
|
||||
for problem in can_probs.into_iter() {
|
||||
// Filter it out of the region end wasn't at least min_region
|
||||
if problem.region().unwrap_or_default().end().offset as usize >= min_region {
|
||||
// Filter out all warnings and errors whose regions end before this,
|
||||
// because they must be part of the defs (excluding the most renently added def,
|
||||
// if that's the one being evaluated) and therefore not things we should show.
|
||||
// This filters out things like shadowing warnings and unused def warnings.
|
||||
if problem.region().unwrap_or_default().end().offset as usize >= bytes_before_expr {
|
||||
let report = can_problem(&alloc, &line_info, module_path.clone(), problem);
|
||||
let severity = report.severity;
|
||||
let mut buf = String::new();
|
||||
|
@ -162,19 +157,33 @@ pub fn compile_to_mono<'a>(
|
|||
(Some(loaded), problems)
|
||||
}
|
||||
|
||||
const REPL_MODULE_WRAPPER: &str =
|
||||
"app \"app\" provides [replOutput] to \"./platform\"\n\nreplOutput =\n";
|
||||
const INDENT: &str = " ";
|
||||
fn promote_expr_to_module<'a, 'i, I: Iterator<Item = &'i str>>(
|
||||
arena: &'a Bump,
|
||||
defs: I,
|
||||
expr: &str,
|
||||
) -> (usize, &'a str) {
|
||||
const REPL_MODULE_HEADER: &str = "app \"app\" provides [replOutput] to \"./platform\"\n\n";
|
||||
const REPL_MODULE_MAIN_DEF: &str = "replOutput =\n";
|
||||
const INDENT: &str = " ";
|
||||
|
||||
fn promote_expr_to_module(src: &str) -> String {
|
||||
let mut buffer = String::from(REPL_MODULE_WRAPPER);
|
||||
let mut buffer = bumpalo::collections::string::String::from_str_in(REPL_MODULE_HEADER, arena);
|
||||
|
||||
for line in src.lines() {
|
||||
// indent the body!
|
||||
for line in defs {
|
||||
// don't indent the defs
|
||||
buffer.push_str(line);
|
||||
buffer.push_str("\n\n");
|
||||
}
|
||||
|
||||
buffer.push_str(REPL_MODULE_MAIN_DEF);
|
||||
|
||||
let bytes_before_expr = buffer.len();
|
||||
|
||||
for line in expr.lines() {
|
||||
// indent the expr!
|
||||
buffer.push_str(INDENT);
|
||||
buffer.push_str(line);
|
||||
buffer.push('\n');
|
||||
}
|
||||
|
||||
buffer
|
||||
(bytes_before_expr, buffer.into_bump_str())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue