Implement a --show-source setting#698
Conversation
| name = "ruff" | ||
|
|
||
| [dependencies] | ||
| annotate-snippets = { version = "0.9.1", features = ["color"] } |
There was a problem hiding this comment.
rustc also uses this crate: rust-lang/rust#59346 (comment)
There was a problem hiding this comment.
Another option is https://github.com/zkat/miette. SWC uses this crate to show pretty reports.
There was a problem hiding this comment.
It looks like that uses https://crates.io/crates/ariadne under the hood.
|
\cc @squiddy |
|
Wow nice. Is it possible to include the fix annotations / suggestions here too, like Clippy does? |
|
That's what I'm investigating now :) |
|
I do like the look and feel! And I love not implementing this ourselves. |
|
@charliermarsh It looks like clippy relies on |
|
Could we vendor that crate? Or is it too closely coupled to Clippy / rustc to be extracted? |
|
This is As you can see, it depends on other private crates: [package]
name = "rustc_errors"
version = "0.0.0"
edition = "2021"
[lib]
[dependencies]
tracing = "0.1"
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_error_messages = { path = "../rustc_error_messages" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_span = { path = "../rustc_span" }
rustc_macros = { path = "../rustc_macros" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_target = { path = "../rustc_target" }
rustc_hir = { path = "../rustc_hir" }
rustc_lint_defs = { path = "../rustc_lint_defs" }
unicode-width = "0.1.4"
atty = "0.2"
termcolor = "1.0"
annotate-snippets = "0.9"
termize = "0.1.1"
serde = { version = "1.0.125", features = [ "derive" ] }
serde_json = "1.0.59"
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = [ "handleapi", "synchapi", "winbase" ] } |
src/message.rs
Outdated
| ..Default::default() | ||
| }, | ||
| }; | ||
| DisplayList::from(snippet).to_string() |
There was a problem hiding this comment.
I think that if we're going to use this crate for --show-source, we should probably use the same crate and style even when --show-source is false (and just omit the source code). What do you think?
There was a problem hiding this comment.
Sounds good. I think we can set slices to an empty vector when --show-source is false.
|
Updated the screenshot. |
src/cli.rs
Outdated
| pub stdin_filename: Option<String>, | ||
| /// Show violations with source code. | ||
| #[arg(long)] | ||
| pub show_source: bool, |
There was a problem hiding this comment.
I think we should add this to pyproject.toml too, wdyt?
There was a problem hiding this comment.
Looks like I forgot to update user.rs. Updated it.
src/message.rs
Outdated
| location: check.location, | ||
| end_location: check.end_location, | ||
| }) | ||
| .len(); |
There was a problem hiding this comment.
I think this needs to be .chars().len(), or we need to use the Rope in locator to get the start and end character positions.
src/message.rs
Outdated
| ); | ||
| let slices = if self.show_source && self.source.is_some() && self.range.is_some() { | ||
| vec this PR adds support for declarations. closes #698 ## Test Plan Tested against mdtest (specifically attributes). --------- Co-authored-by: David Peter <mail@david-peter.de>

See #525.