Skip to content

Commit

Permalink
feat(cli): better header in diagnostics (#4814)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Dec 30, 2024
1 parent 164dc85 commit f342128
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 68 deletions.
44 changes: 42 additions & 2 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,14 @@ similar = "2.6.0"
smallvec = { version = "1.13.2", features = ["union", "const_new", "serde"] }
syn = "1.0.109"
termcolor = "1.4.1"
terminal_size = "0.4.1"
tokio = "1.42.0"
tracing = { version = "0.1.41", default-features = false, features = ["std"] }
tracing-subscriber = "0.3.19"
unicode-bom = "2.0.3"
unicode-width = "0.1.12"


[profile.dev.package.biome_wasm]
debug = true
opt-level = "s"
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
smallvec = { workspace = true }
terminal_size = { workspace = true }
tokio = { workspace = true, features = ["io-std", "io-util", "net", "time", "rt", "sync", "rt-multi-thread", "macros"] }
tracing = { workspace = true }
tracing-appender = "0.2.3"
Expand Down
58 changes: 47 additions & 11 deletions crates/biome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use biome_service::workspace::{client, RageEntry, RageParams};
use biome_service::Workspace;
use camino::Utf8PathBuf;
use std::{env, io, ops::Deref};
use terminal_size::terminal_size;
use tokio::runtime::Runtime;

use crate::commands::daemon::read_most_recent_log_file;
Expand Down Expand Up @@ -63,7 +64,7 @@ pub(crate) fn rage(
.app
.console
.log(markup!("Discovering running Biome servers..."));
session.app.console.log(markup!({ RunningRomeServer }));
session.app.console.log(markup!({ RunningBiomeServer }));
}
}
}
Expand Down Expand Up @@ -105,9 +106,9 @@ impl Display for WorkspaceRage<'_> {
}

/// Prints information about other running biome server instances.
struct RunningRomeServer;
struct RunningBiomeServer;

impl Display for RunningRomeServer {
impl Display for RunningBiomeServer {
fn fmt(&self, f: &mut Formatter) -> io::Result<()> {
let versions = match enumerate_pipes() {
Ok(iter) => iter,
Expand All @@ -117,7 +118,7 @@ impl Display for RunningRomeServer {
}
};

for version in versions {
for (version, path) in versions {
if version == biome_configuration::VERSION {
let runtime = Runtime::new()?;
match service::open_transport(runtime) {
Expand All @@ -130,7 +131,17 @@ impl Display for RunningRomeServer {
continue;
}
Ok(Some(transport)) => {
markup!("\n"<Emphasis>"Running Biome Server:"</Emphasis>" "{HorizontalLine::new(78)}"
let header = "Running Biome Server: ";
let width = {
if cfg!(debug_assertions) {
78
} else {
terminal_size().map_or(78, |(width, _)| width.0 as usize)
}
};
let width = width.saturating_sub(header.len());

markup!("\n"<Emphasis>{header}</Emphasis>{HorizontalLine::new(width)}"
"<Info>"\u{2139} The client isn't connected to any server but rage discovered this running Biome server."</Info>"
")
Expand All @@ -152,7 +163,16 @@ impl Display for RunningRomeServer {

BiomeServerLog.fmt(f)?;
} else {
markup!("\n"<Emphasis>"Incompatible Biome Server:"</Emphasis>" "{HorizontalLine::new(78)}"
let header = "Incompatible Biome Server: ";
let width = {
if cfg!(debug_assertions) {
78
} else {
terminal_size().map_or(78, |(width, _)| width.0 as usize)
}
};
let width = width.saturating_sub(header.len());
markup!("\n"<Emphasis>{header}</Emphasis>{HorizontalLine::new(width)}"
"<Info>"\u{2139} Rage discovered this running server using an incompatible version of Biome."</Info>"
")
Expand All @@ -161,6 +181,7 @@ impl Display for RunningRomeServer {
markup!(
{Section("Server")}
{KeyValuePair("Version", markup!({version.as_str()}))}
{KeyValuePair("Path", markup!({path.as_str()}))}
)
.fmt(f)?;
}
Expand Down Expand Up @@ -215,6 +236,18 @@ impl Display for RageConfiguration<'_> {
// Print formatter configuration if --formatter option is true
if self.formatter {
let formatter_configuration = configuration.get_formatter_configuration();
let ignore = formatter_configuration
.ignore
.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(", ");
let include = formatter_configuration
.include
.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(", ");
markup! (
{Section("Formatter")}
{KeyValuePair("Format with errors", markup!({DebugDisplay(configuration.get_formatter_configuration().format_with_errors)}))}
Expand All @@ -224,8 +257,8 @@ impl Display for RageConfiguration<'_> {
{KeyValuePair("Line width", markup!({DebugDisplay(formatter_configuration.line_width.value())}))}
{KeyValuePair("Attribute position", markup!({DebugDisplay(formatter_configuration.attribute_position)}))}
{KeyValuePair("Bracket spacing", markup!({DebugDisplay(formatter_configuration.bracket_spacing)}))}
{KeyValuePair("Ignore", markup!({DebugDisplay(formatter_configuration.ignore.iter().collect::<Vec<_>>())}))}
{KeyValuePair("Include", markup!({DebugDisplay(formatter_configuration.include.iter().collect::<Vec<_>>())}))}
{KeyValuePair("Ignore", markup!({DebugDisplay(ignore)}))}
{KeyValuePair("Include", markup!({DebugDisplay(include)}))}
).fmt(fmt)?;

let javascript_formatter_configuration =
Expand All @@ -239,7 +272,7 @@ impl Display for RageConfiguration<'_> {
{KeyValuePair("Semicolons", markup!({DebugDisplay(javascript_formatter_configuration.semicolons)}))}
{KeyValuePair("Arrow parentheses", markup!({DebugDisplay(javascript_formatter_configuration.arrow_parentheses)}))}
{KeyValuePair("Bracket spacing", markup!({DebugDisplayOption(javascript_formatter_configuration.bracket_spacing)}))}
{KeyValuePair("Bracket same line", markup!({DebugDisplay(javascript_formatter_configuration.bracket_same_line)}))}
{KeyValuePair("Bracket same line", markup!({DebugDisplayOption(javascript_formatter_configuration.bracket_same_line)}))}
{KeyValuePair("Quote style", markup!({DebugDisplay(javascript_formatter_configuration.quote_style)}))}
{KeyValuePair("Indent style", markup!({DebugDisplayOption(javascript_formatter_configuration.indent_style)}))}
{KeyValuePair("Indent width", markup!({DebugDisplayOption(javascript_formatter_configuration.indent_width)}))}
Expand Down Expand Up @@ -324,12 +357,13 @@ impl Display for RageConfigurationLintRules<'_> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> io::Result<()> {
let rules_str = self.0;
let padding = Padding::new(2);
let padding_rules = Padding::new(4);
fmt.write_markup(markup! {{padding}{rules_str}":"})?;
fmt.write_markup(markup! {{SOFT_LINE}})?;
let rules = self.1.as_enabled_rules();
let rules = rules.iter().collect::<std::collections::BTreeSet<_>>();
for rule in rules {
fmt.write_markup(markup! {{padding}{rule}})?;
fmt.write_markup(markup! {{padding_rules}{rule}})?;
fmt.write_markup(markup! {{SOFT_LINE}})?;
}

Expand All @@ -344,7 +378,9 @@ impl fmt::Display for EnvVarOs {
let name = self.0;
match env::var_os(name) {
None => KeyValuePair(name, markup! { <Dim>"unset"</Dim> }).fmt(fmt),
Some(value) => KeyValuePair(name, markup! {{DebugDisplay(value)}}).fmt(fmt),
Some(value) => {
KeyValuePair(name, markup! {{DebugDisplayOption(value.to_str())}}).fmt(fmt)
}
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions crates/biome_cli/src/service/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ fn get_socket_name() -> Utf8PathBuf {
biome_fs::ensure_cache_dir().join(format!("biome-socket-{}", biome_configuration::VERSION))
}

pub(crate) fn enumerate_pipes() -> io::Result<impl Iterator<Item = String>> {
pub(crate) fn enumerate_pipes() -> io::Result<impl Iterator<Item = (String, Utf8PathBuf)>> {
fs::read_dir(biome_fs::ensure_cache_dir()).map(|iter| {
iter.filter_map(|entry| {
let entry = entry.ok()?.path();
let entry = Utf8PathBuf::from_path_buf(entry.ok()?.path()).ok()?;
let file_name = entry.file_name()?;
let file_name = file_name.to_str()?;

let version = file_name.strip_prefix("biome-socket")?;
if version.is_empty() {
Some(String::new())
Some((String::new(), entry))
} else {
Some(version.strip_prefix('-')?.to_string())
Some((version.strip_prefix('-')?.to_string(), entry))
}
})
})
Expand Down
9 changes: 4 additions & 5 deletions crates/biome_cli/src/service/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ fn get_pipe_name() -> String {
format!(r"\\.\pipe\biome-service-{}", biome_configuration::VERSION)
}

pub(crate) fn enumerate_pipes() -> io::Result<impl Iterator<Item = String>> {
pub(crate) fn enumerate_pipes() -> io::Result<impl Iterator<Item = (String, Utf8PathBuf)>> {
read_dir(r"\\.\pipe").map(|iter| {
iter.filter_map(|entry| {
let entry = entry.ok()?.path();
let entry = Utf8PathBuf::from_path_buf(entry.ok()?.path()).ok()?;
let file_name = entry.file_name()?;
let file_name = file_name.to_str()?;

let version = file_name.strip_prefix("rome-service")?;
if version.is_empty() {
Some(String::new())
Some((String::new(), entry))
} else {
Some(version.strip_prefix('-')?.to_string())
Some((version.strip_prefix('-')?.to_string(), entry))
}
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,34 +82,34 @@ Formatter:
Format with errors: true
Indent style: Space
Indent width: 2
Line ending: Lf
Line ending: LF
Line width: 120
Attribute position: Multiline
Bracket spacing: BracketSpacing(true)
Ignore: ["configuration-schema.json"]
Include: ["**/*.html", "**/*.css", "**/*.js", "**/*.ts", "**/*.tsx", "**/*.jsx", "**/*.json", "**/*.md"]
Bracket spacing: true
Ignore: configuration-schema.json
Include: **/*.html, **/*.css, **/*.js, **/*.ts, **/*.tsx, **/*.jsx, **/*.json, **/*.md
JavaScript Formatter:
Enabled: true
JSX quote style: Single
Quote properties: AsNeeded
JSX quote style: Single Quotes
Quote properties: As needed
Trailing commas: All
Semicolons: Always
Arrow parentheses: Always
Bracket spacing: unset
Bracket same line: None
Quote style: Double
Bracket same line: unset
Quote style: Double Quotes
Indent style: Tab
Indent width: 2
Line ending: Lf
Line ending: LF
Line width: 100
Attribute position: unset
JSON Formatter:
Enabled: true
Indent style: Space
Indent width: 2
Line ending: Lf
Line ending: LF
Line width: 100
Trailing Commas: unset
Expand All @@ -119,7 +119,7 @@ CSS Formatter:
Indent width: unset
Line ending: unset
Line width: unset
Quote style: Double
Quote style: Double Quotes
GraphQL Formatter:
Enabled: false
Expand Down
Loading

0 comments on commit f342128

Please sign in to comment.