1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

refactor(fmt): rewrite HTML syntax error handling (#25892)

This commit is contained in:
Bartek Iwańczuk 2024-09-27 01:44:36 +01:00 committed by GitHub
parent eff64238b6
commit 09a7cc4723
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 5 additions and 15 deletions

4
Cargo.lock generated
View file

@ -4342,9 +4342,9 @@ dependencies = [
[[package]] [[package]]
name = "markup_fmt" name = "markup_fmt"
version = "0.13.0" version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74fc137a4a591720176339bf7e857586a48ff35c0caee7ad6cf709327901232c" checksum = "9dab5ae899659fbe5c8835b2c8ca8d3e357974a3e454138925b404004973361f"
dependencies = [ dependencies = [
"aho-corasick", "aho-corasick",
"css_dataset", "css_dataset",

View file

@ -124,7 +124,7 @@ libz-sys.workspace = true
log = { workspace = true, features = ["serde"] } log = { workspace = true, features = ["serde"] }
lsp-types.workspace = true lsp-types.workspace = true
malva = "=0.10.1" malva = "=0.10.1"
markup_fmt = "=0.13.0" markup_fmt = "=0.13.1"
memmem.workspace = true memmem.workspace = true
monch.workspace = true monch.workspace = true
notify.workspace = true notify.workspace = true

View file

@ -437,25 +437,15 @@ pub fn format_html(
) )
.map_err(|error| match error { .map_err(|error| match error {
markup_fmt::FormatError::Syntax(error) => { markup_fmt::FormatError::Syntax(error) => {
// TODO(bartlomieju): rework when better error support in `markup_fmt` lands
fn inner( fn inner(
error: &markup_fmt::SyntaxError, error: &markup_fmt::SyntaxError,
file_path: &Path, file_path: &Path,
) -> Option<String> { ) -> Option<String> {
let error_str = format!("{}", error);
let error_str = error_str.strip_prefix("syntax error '")?;
let reason = error_str
.split("' at")
.collect::<Vec<_>>()
.first()
.map(|s| s.to_string())?;
let url = Url::from_file_path(file_path).ok()?; let url = Url::from_file_path(file_path).ok()?;
let error_msg = format!( let error_msg = format!(
"Syntax error ({}) at {}:{}:{}\n", "Syntax error ({}) at {}:{}:{}\n",
reason, error.kind,
url.as_str(), url.as_str(),
error.line, error.line,
error.column error.column

View file

@ -1,4 +1,4 @@
Error formatting: [WILDCARD]broken.html Error formatting: [WILDCARD]broken.html
Syntax error (expect close tag) at file://[WILDCARD]broken.html:3:0 Syntax error (expected close tag) at file://[WILDCARD]broken.html:3:0
Checked 1 file Checked 1 file