Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_service): internal errors as diagnostics #3921

Merged
merged 4 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ tracing = { version = "0.1.31", default-features = false, features = ["std"] }
dashmap = "5.4.0"
rustc-hash = "1.1.0"
countme = "3.0.1"
tokio = { version = "1.15.0" }
tokio = { version = "1.15.0" }
insta = "1.21.2"
2 changes: 1 addition & 1 deletion crates/rome_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ mimalloc = "0.1.29"
tikv-jemallocator = "0.5.0"

[dev-dependencies]
insta = "1.18.2"
insta = { workspace = true }
tokio = { workspace = true, features = ["io-util"] }
25 changes: 25 additions & 0 deletions crates/rome_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub use crate::error::{Error, Result};
pub use crate::location::{
FileId, FilePath, LineIndex, LineIndexBuf, Location, Resource, SourceCode,
};
use rome_console::fmt::{Formatter, Termcolor};
use rome_console::markup;
use std::fmt::Write;

pub mod prelude {
//! Anonymously re-exports all the traits declared by this module, this is
Expand Down Expand Up @@ -67,3 +70,25 @@ impl DiagnosticTag {
}

pub const MAXIMUM_DISPLAYABLE_DIAGNOSTICS: u16 = 200;

/// Utility function for testing purpose. The function will print an [Error]
/// to a string, which is then returned by the function.
pub fn print_diagnostic_to_string(diagnostic: Error) -> String {
let mut buffer = termcolor::Buffer::no_color();

Formatter::new(&mut Termcolor(&mut buffer))
.write_markup(markup! {
{PrintDiagnostic::verbose(&diagnostic)}
})
.expect("failed to emit diagnostic");

let mut content = String::new();
writeln!(
content,
"{}",
std::str::from_utf8(buffer.as_slice()).expect("non utf8 in error buffer")
)
.unwrap();

content
}
2 changes: 2 additions & 0 deletions crates/rome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ define_dategories! {
"suppressions/unused",
"suppressions/deprecatedSyntax",

"configuration",

// Used in tests and examples
"args/fileNotFound",
"flags/invalid",
Expand Down
4 changes: 3 additions & 1 deletion crates/rome_formatter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ countme = { workspace = true }
drop_bomb = "0.1.5"
indexmap = { workspace = true }
unicode-width = "0.1.9"
rome_diagnostics = { path = "../rome_diagnostics" }
rome_console = { path = "../rome_console" }

[dev-dependencies]
rome_js_parser = { path = "../rome_js_parser"}
rome_js_syntax = { path = "../rome_js_syntax" }
rome_diagnostics = { path = "../rome_diagnostics" }
insta = { workspace = true }

[features]
serde = ["dep:serde", "schemars", "rome_rowan/serde"]
Loading