mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Hackily filter out UNUSED warnings in repl
This commit is contained in:
parent
b7d3c77b76
commit
aa1dcee709
1 changed files with 39 additions and 5 deletions
|
@ -214,9 +214,34 @@ impl ReplState {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO filter out UNUSED warnings for all past_def_ident entries
|
format_output(output, problems, |warning| {
|
||||||
// TODO allow turning off printing of warnings
|
// Filter out UNUSED warnings for entries in past_def_idents,
|
||||||
format_output(output, problems)
|
// since otherwise those are totally unhelpful and very annoying!
|
||||||
|
//
|
||||||
|
// Obviously doing string matching on the error message itself is a
|
||||||
|
// brittle and hacky way to do this. It would be nice in the future to
|
||||||
|
// thread the authoritative information through here, but that's
|
||||||
|
// too large a change to justify in the first (already very large)
|
||||||
|
// implementation of the "remembered defs" feature!
|
||||||
|
const UNUSED_DEF_SHORT_PREFIX: &str = "\u{1b}[36m── UNUSED DEFINITION ─";
|
||||||
|
const UNUSED_DEF_FULL_PREFIX:&str = "\u{1b}[36m── UNUSED DEFINITION ───────────────────────────────────────────────────────────\u{1b}[0m\n\n\u{1b}[34m";
|
||||||
|
|
||||||
|
if warning.starts_with(UNUSED_DEF_SHORT_PREFIX) {
|
||||||
|
let ident_start = &warning[UNUSED_DEF_FULL_PREFIX.len()..];
|
||||||
|
|
||||||
|
if let Some(ident_len) = ident_start.find("\u{1b}[0m") {
|
||||||
|
let ident = &ident_start[..ident_len];
|
||||||
|
|
||||||
|
// If this is an unused definition warning for an entry
|
||||||
|
// in our past_def_idents, filter it out.
|
||||||
|
if self.past_def_idents.contains(ident) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_auto_ident(&mut self) -> u64 {
|
fn next_auto_ident(&mut self) -> u64 {
|
||||||
|
@ -398,11 +423,20 @@ impl Validator for ReplState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_output(opt_output: Option<ReplOutput>, problems: Problems) -> String {
|
fn format_output<F: FnMut(&&String) -> bool>(
|
||||||
|
opt_output: Option<ReplOutput>,
|
||||||
|
problems: Problems,
|
||||||
|
warning_filter: F,
|
||||||
|
) -> String {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
||||||
// Join all the warnings and errors together with blank lines.
|
// Join all the warnings and errors together with blank lines.
|
||||||
for message in problems.warnings.iter().chain(problems.errors.iter()) {
|
for message in problems
|
||||||
|
.warnings
|
||||||
|
.iter()
|
||||||
|
.filter(warning_filter)
|
||||||
|
.chain(problems.errors.iter())
|
||||||
|
{
|
||||||
if !buf.is_empty() {
|
if !buf.is_empty() {
|
||||||
buf.push_str("\n\n");
|
buf.push_str("\n\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue