From 07e7e055950dee4aceb73d7ba775eb3d43af5a5d Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Wed, 14 Feb 2024 09:11:13 +0000 Subject: [PATCH] feat(cli): make file in diagnostic clickable --- CHANGELOG.md | 2 ++ crates/biome_diagnostics/src/display.rs | 11 ++++++++++- website/src/content/docs/internals/changelog.mdx | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d8321c5a948..18e63d82a785 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 Ctrl/ + 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. diff --git a/crates/biome_diagnostics/src/display.rs b/crates/biome_diagnostics/src/display.rs index f5f7d9d4d9ae..eb54f5e1fe5a 100644 --- a/crates/biome_diagnostics/src/display.rs +++ b/crates/biome_diagnostics/src/display.rs @@ -1,3 +1,4 @@ +use std::path::Path; use std::{io, iter}; use biome_console::{fmt, markup, HorizontalLine, Markup, MarkupBuf, MarkupElement, MarkupNode}; @@ -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! { + {name}" " + })?; + } 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) diff --git a/website/src/content/docs/internals/changelog.mdx b/website/src/content/docs/internals/changelog.mdx index 1a770bb923e6..8218c788339e 100644 --- a/website/src/content/docs/internals/changelog.mdx +++ b/website/src/content/docs/internals/changelog.mdx @@ -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 Ctrl/ + 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.