mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
Merge branch 'main' of github.com:roc-lang/roc into clippy-1.74
This commit is contained in:
commit
cd632fe549
271 changed files with 7741 additions and 7417 deletions
|
@ -1090,7 +1090,7 @@ pub fn can_problem<'b>(
|
|||
title = "OVERAPPLIED CRASH".to_string();
|
||||
}
|
||||
Problem::FileProblem { filename, error } => {
|
||||
let report = to_file_problem_report(alloc, &filename, error);
|
||||
let report = to_file_problem_report(alloc, filename, error);
|
||||
doc = report.doc;
|
||||
title = report.title;
|
||||
}
|
||||
|
|
|
@ -670,6 +670,23 @@ fn to_expr_report<'a>(
|
|||
EExpr::Dbg(e_expect, _position) => {
|
||||
to_dbg_or_expect_report(alloc, lines, filename, context, Node::Dbg, e_expect, start)
|
||||
}
|
||||
EExpr::TrailingOperator(pos) => {
|
||||
let surroundings = Region::new(start, *pos);
|
||||
let region = LineColumnRegion::from_pos(lines.convert_pos(*pos));
|
||||
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I am partway through parsing an expression, but I got stuck here:"),
|
||||
alloc.region_with_subregion(lines.convert_region(surroundings), region),
|
||||
alloc.concat([alloc.reflow("TODO provide more context.")]),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename,
|
||||
doc,
|
||||
title: "TRAILING OPERATOR".to_string(),
|
||||
severity: Severity::RuntimeError,
|
||||
}
|
||||
}
|
||||
_ => todo!("unhandled parse error: {:?}", parse_problem),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1101,7 +1101,11 @@ where
|
|||
}
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
pub fn to_https_problem_report_string(url: &str, https_problem: Problem) -> String {
|
||||
pub fn to_https_problem_report_string(
|
||||
url: &str,
|
||||
https_problem: Problem,
|
||||
filename: PathBuf,
|
||||
) -> String {
|
||||
let src_lines: Vec<&str> = Vec::new();
|
||||
|
||||
let mut module_ids = ModuleIds::default();
|
||||
|
@ -1115,7 +1119,7 @@ pub fn to_https_problem_report_string(url: &str, https_problem: Problem) -> Stri
|
|||
|
||||
let mut buf = String::new();
|
||||
let palette = DEFAULT_PALETTE;
|
||||
let report = to_https_problem_report(&alloc, url, https_problem);
|
||||
let report = to_https_problem_report(&alloc, url, https_problem, filename);
|
||||
report.render_color_terminal(&mut buf, &alloc, &palette);
|
||||
|
||||
buf
|
||||
|
@ -1126,11 +1130,12 @@ pub fn to_https_problem_report<'b>(
|
|||
alloc: &'b RocDocAllocator<'b>,
|
||||
url: &'b str,
|
||||
https_problem: Problem,
|
||||
filename: PathBuf,
|
||||
) -> Report<'b> {
|
||||
match https_problem {
|
||||
Problem::UnsupportedEncoding(not_supported_encoding) => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc.string((&url).to_string()).annotate(Annotation::Url).indent(4),
|
||||
alloc.concat([
|
||||
alloc.reflow(r"But the server replied with a "),
|
||||
|
@ -1154,7 +1159,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "UNSUPPORTED ENCODING".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1162,7 +1167,7 @@ pub fn to_https_problem_report<'b>(
|
|||
}
|
||||
Problem::MultipleEncodings(multiple_encodings) => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc.string((&url).to_string()).annotate(Annotation::Url).indent(4),
|
||||
alloc.concat([
|
||||
alloc.reflow(r"But the server replied with multiple "),
|
||||
|
@ -1189,7 +1194,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "MULTIPLE ENCODINGS".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1224,16 +1229,33 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "INVALID CONTENT HASH".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
}
|
||||
}
|
||||
Problem::NotFound => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
.indent(4),
|
||||
alloc.concat([alloc.reflow(r"But the file was not found (404).")]),
|
||||
alloc.concat([alloc.tip(), alloc.reflow(r"Is the URL correct?")]),
|
||||
]);
|
||||
Report {
|
||||
filename,
|
||||
doc,
|
||||
title: "NOTFOUND".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
}
|
||||
}
|
||||
// TODO: The reporting text for IoErr and FsExtraErr could probably be unified
|
||||
Problem::IoErr(io_error) => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
|
@ -1251,7 +1273,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "IO ERROR".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1260,7 +1282,7 @@ pub fn to_https_problem_report<'b>(
|
|||
// TODO: The reporting text for IoErr and FsExtraErr could probably be unified
|
||||
Problem::FsExtraErr(fs_extra_error) => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
|
@ -1278,7 +1300,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "IO ERROR".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1286,7 +1308,7 @@ pub fn to_https_problem_report<'b>(
|
|||
}
|
||||
Problem::HttpErr(reqwest_error) => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
|
@ -1307,7 +1329,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "HTTP ERROR".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1323,7 +1345,7 @@ pub fn to_https_problem_report<'b>(
|
|||
};
|
||||
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
|
@ -1348,7 +1370,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "INVALID EXTENSION SUFFIX".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1356,7 +1378,7 @@ pub fn to_https_problem_report<'b>(
|
|||
}
|
||||
Problem::InvalidUrl(roc_packaging::https::UrlProblem::MissingTarExt) => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
|
@ -1381,7 +1403,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "INVALID EXTENSION".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1391,7 +1413,7 @@ pub fn to_https_problem_report<'b>(
|
|||
invalid_fragment,
|
||||
)) => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
|
@ -1419,7 +1441,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "INVALID FRAGMENT".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1427,7 +1449,7 @@ pub fn to_https_problem_report<'b>(
|
|||
}
|
||||
Problem::InvalidUrl(roc_packaging::https::UrlProblem::MissingHash) => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
|
@ -1457,7 +1479,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "MISSING PACKAGE HASH".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1465,7 +1487,7 @@ pub fn to_https_problem_report<'b>(
|
|||
}
|
||||
Problem::InvalidUrl(roc_packaging::https::UrlProblem::MissingHttps) => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
|
@ -1483,7 +1505,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "HTTPS MANDATORY".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1491,7 +1513,7 @@ pub fn to_https_problem_report<'b>(
|
|||
}
|
||||
Problem::InvalidUrl(roc_packaging::https::UrlProblem::MisleadingCharacter) => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
|
@ -1526,7 +1548,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "MISLEADING CHARACTERS".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1537,7 +1559,7 @@ pub fn to_https_problem_report<'b>(
|
|||
.get_appropriate_unit(false)
|
||||
.format(3);
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I was trying to download this URL:"),
|
||||
alloc.reflow(r"I tried to download from this URL:"),
|
||||
alloc
|
||||
.string((&url).to_string())
|
||||
.annotate(Annotation::Url)
|
||||
|
@ -1556,7 +1578,7 @@ pub fn to_https_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "FILE TOO LARGE".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1565,13 +1587,10 @@ pub fn to_https_problem_report<'b>(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_file_problem_report_string(filename: &Path, error: io::ErrorKind) -> String {
|
||||
pub fn to_file_problem_report_string(filename: PathBuf, error: io::ErrorKind) -> String {
|
||||
let src_lines: Vec<&str> = Vec::new();
|
||||
|
||||
let mut module_ids = ModuleIds::default();
|
||||
|
||||
let module_id = module_ids.get_or_insert(&"find module name somehow?".into());
|
||||
|
||||
let interns = Interns::default();
|
||||
|
||||
// Report parsing and canonicalization problems
|
||||
|
@ -1587,16 +1606,16 @@ pub fn to_file_problem_report_string(filename: &Path, error: io::ErrorKind) -> S
|
|||
|
||||
pub fn to_file_problem_report<'b>(
|
||||
alloc: &'b RocDocAllocator<'b>,
|
||||
filename: &Path,
|
||||
filename: PathBuf,
|
||||
error: io::ErrorKind,
|
||||
) -> Report<'b> {
|
||||
let filename: String = filename.to_str().unwrap().to_string();
|
||||
let filename_str: String = filename.to_str().unwrap().to_string();
|
||||
match error {
|
||||
io::ErrorKind::NotFound => {
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I am looking for this file, but it's not there:"),
|
||||
alloc
|
||||
.string(filename)
|
||||
.string(filename_str)
|
||||
.annotate(Annotation::ParserSuggestion)
|
||||
.indent(4),
|
||||
alloc.concat([
|
||||
|
@ -1606,7 +1625,7 @@ pub fn to_file_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "FILE NOT FOUND".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1616,7 +1635,7 @@ pub fn to_file_problem_report<'b>(
|
|||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I don't have the required permissions to read this file:"),
|
||||
alloc
|
||||
.string(filename)
|
||||
.string(filename_str)
|
||||
.annotate(Annotation::ParserSuggestion)
|
||||
.indent(4),
|
||||
alloc
|
||||
|
@ -1624,7 +1643,7 @@ pub fn to_file_problem_report<'b>(
|
|||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "FILE PERMISSION DENIED".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
@ -1635,13 +1654,16 @@ pub fn to_file_problem_report<'b>(
|
|||
let formatted = format!("{error}");
|
||||
let doc = alloc.stack([
|
||||
alloc.reflow(r"I tried to read this file:"),
|
||||
alloc.string(filename).annotate(Annotation::Error).indent(4),
|
||||
alloc
|
||||
.string(filename_str)
|
||||
.annotate(Annotation::Error)
|
||||
.indent(4),
|
||||
alloc.reflow(r"But ran into:"),
|
||||
alloc.text(formatted).annotate(Annotation::Error).indent(4),
|
||||
]);
|
||||
|
||||
Report {
|
||||
filename: "UNKNOWN.roc".into(),
|
||||
filename,
|
||||
doc,
|
||||
title: "FILE PROBLEM".to_string(),
|
||||
severity: Severity::Fatal,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue