This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rome_diagnostics): add a new version of diagnostics (#3222)
* feat(rome_diagnostics): add a new version of diagnostics aligned with the features of Rome JS * Apply suggestions from code review Co-authored-by: Micha Reiser <[email protected]> Co-authored-by: Emanuele Stoppa <[email protected]> * address PR review * update snapshots * move "Fatal" from a diagnostic tag to a severity level Co-authored-by: Micha Reiser <[email protected]> Co-authored-by: Emanuele Stoppa <[email protected]>
- Loading branch information
1 parent
38a7286
commit 980184f
Showing
112 changed files
with
5,315 additions
and
238 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# `rome_diagnostics` | ||
|
||
This crate contains the types and utility functions used to implement errors | ||
and diagnostics in the Rome codebase | ||
|
||
## Acknowledgement | ||
|
||
This crate was initially forked from [rslint_errors](https://github.com/rslint/rslint/tree/master/crates/rslint_errors). The design of the new `Diagnostic` trait, `Error` struct, `Context` trait, and the `Diagnostic` derive macro in `rome_diagnostics_macros` are inspired by various fantastic crates in the Rust error handling space: [miette](https://github.com/zkat/miette), [anyhow](https://github.com/dtolnay/anyhow) and [thiserror](https://github.com/dtolnay/thiserror) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use std::io; | ||
|
||
use rome_console::{markup, ConsoleExt, EnvConsole}; | ||
use rome_diagnostics::v2::{Advices, Diagnostic, LogCategory, PrintDiagnostic, Resource, Visit}; | ||
use rome_rowan::{TextRange, TextSize}; | ||
|
||
#[derive(Debug, Diagnostic)] | ||
#[diagnostic( | ||
category = "flags/invalid", | ||
message( | ||
description = "Unknown command {command_name}", | ||
message("Unknown command "<Emphasis>{self.command_name}</Emphasis>) | ||
), | ||
tags(FIXABLE), | ||
)] | ||
struct CliDiagnostic { | ||
command_name: String, | ||
#[location(resource)] | ||
path: Resource<&'static str>, | ||
#[location(span)] | ||
span: TextRange, | ||
#[location(source_code)] | ||
source_code: String, | ||
#[advice] | ||
advices: CliAdvices, | ||
} | ||
|
||
#[derive(Debug)] | ||
struct CliAdvices { | ||
suggested_name: String, | ||
suggested_command: String, | ||
} | ||
|
||
impl Advices for CliAdvices { | ||
fn record(&self, visitor: &mut dyn Visit) -> io::Result<()> { | ||
visitor.record_log( | ||
LogCategory::Info, | ||
&markup! { | ||
"Did you mean "<Emphasis>{self.suggested_name}</Emphasis>" instead?" | ||
}, | ||
)?; | ||
|
||
visitor.record_command(&self.suggested_command)?; | ||
|
||
visitor.record_log(LogCategory::Info, &"To see all available commands run")?; | ||
visitor.record_command("rome --help") | ||
} | ||
} | ||
|
||
pub fn main() { | ||
let diag = CliDiagnostic { | ||
command_name: String::from("formqt"), | ||
path: Resource::Argv, | ||
span: TextRange::new(TextSize::from(5), TextSize::from(11)), | ||
source_code: String::from("rome formqt file.js"), | ||
advices: CliAdvices { | ||
suggested_name: String::from("format"), | ||
suggested_command: String::from("rome format file.js"), | ||
}, | ||
}; | ||
|
||
EnvConsole::default().error(markup!({ PrintDiagnostic(&diag) })); | ||
} |
Oops, something went wrong.