Skip to content

Commit

Permalink
feat(cli): make file in diagnostic clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Feb 14, 2024
1 parent dca6a7a commit 07e7e05
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
- Add a new command `biome migrate prettier`. The command will read the file `.prettierrc`/`prettier.json` and `.prettierignore` and map its configuration to Biome's one.
Due to the different nature of `.prettierignore` globs and Biome's globs, it's **highly** advised to make sure that those still work under Biome.

- Now the file name printed in the diagnostics is clickable. If you run the CLI from your editor, you can <kbd>Ctrl</kbd>/<kbd title="Cmd">⌘</kbd> + Click on the file name, and the editor will open said file. If row and columns are specified e.g. `file.js:32:7`, the editor will set the cursor right in that position. Contributed by @ematipico

#### Bug fixes

- Don't process files under an ignored directory.
Expand Down
11 changes: 10 additions & 1 deletion crates/biome_diagnostics/src/display.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::Path;
use std::{io, iter};

use biome_console::{fmt, markup, HorizontalLine, Markup, MarkupBuf, MarkupElement, MarkupNode};
Expand Down Expand Up @@ -91,7 +92,15 @@ impl<'fmt, D: Diagnostic + ?Sized> fmt::Display for PrintHeader<'fmt, D> {
};

if let Some(name) = file_name {
fmt.write_str(name)?;
let path_name = Path::new(name);
if path_name.is_absolute() {
let link = format!("file://{}", name);
fmt.write_markup(markup! {
<Hyperlink href={link}>{name}</Hyperlink>" "
})?;
} else {
fmt.write_str(name)?;
}

// Print the line and column position if the location has a span and source code
// (the source code is necessary to convert a byte offset into a line + column)
Expand Down
2 changes: 2 additions & 0 deletions website/src/content/docs/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
- Add a new command `biome migrate prettier`. The command will read the file `.prettierrc`/`prettier.json` and `.prettierignore` and map its configuration to Biome's one.
Due to the different nature of `.prettierignore` globs and Biome's globs, it's **highly** advised to make sure that those still work under Biome.

- Now the file name printed in the diagnostics is clickable. If you run the CLI from your editor, you can <kbd>Ctrl</kbd>/<kbd title="Cmd">⌘</kbd> + Click on the file name, and the editor will open said file. If row and columns are specified e.g. `file.js:32:7`, the editor will set the cursor right in that position. Contributed by @ematipico

#### Bug fixes

- Don't process files under an ignored directory.
Expand Down

0 comments on commit 07e7e05

Please sign in to comment.