Skip to content

Commit c1858bc

Browse files
committed
fix(oxc_linter): Make linter file paths clickable within JetBrains terminals
JetBrains terminals don't work reliably with relative paths to hyperlink to the file. Outputting the full file URL instead works consistently.
1 parent ff7111c commit c1858bc

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ tokio = { version = "1.45.1", default-features = false }
228228
tower-lsp-server = "0.21.1"
229229
tracing-subscriber = "0.3.19"
230230
ureq = { version = "3.0.11", default-features = false }
231+
url = "2.5.4"
231232
walkdir = "2.5.0"
232233

233234
[workspace.metadata.cargo-shear]

crates/oxc_diagnostics/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ doctest = false
2121
[dependencies]
2222
cow-utils = { workspace = true }
2323
miette = { workspace = true }
24+
url = { workspace = true }

crates/oxc_diagnostics/src/service.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::{
44
sync::{Arc, mpsc},
55
};
66

7-
use cow_utils::CowUtils;
87
use miette::LabeledSpan;
8+
use url::Url;
99

1010
use crate::{
1111
Error, NamedSource, OxcDiagnostic, Severity,
@@ -128,17 +128,27 @@ impl DiagnosticService {
128128
/// Wrap [diagnostics] with the source code and path, converting them into [Error]s.
129129
///
130130
/// [diagnostics]: OxcDiagnostic
131-
pub fn wrap_diagnostics<P: AsRef<Path>>(
131+
pub fn wrap_diagnostics<C: AsRef<Path>, P: AsRef<Path>>(
132+
cwd: C,
132133
path: P,
133134
source_text: &str,
134135
source_start: u32,
135136
diagnostics: Vec<OxcDiagnostic>,
136-
) -> (PathBuf, Vec<Error>) {
137-
let path = path.as_ref();
138-
let path_display = path.to_string_lossy();
139-
// replace windows \ path separator with posix style one
140-
// reflects what eslint is outputting
141-
let path_display = path_display.cow_replace('\\', "/");
137+
) -> Vec<Error> {
138+
#[cfg(test)]
139+
let is_jetbrains_terminal = false;
140+
#[cfg(not(test))]
141+
let is_jetbrains_terminal = std::env::var("TERMINAL_EMULATOR").is_ok_and(|x| x.eq("JetBrains-JediTerm"));
142+
143+
let file_url = Url::from_file_path(path.as_ref());
144+
let path_display = if is_jetbrains_terminal && file_url.is_ok() {
145+
file_url.unwrap().to_string()
146+
} else {
147+
let path = path.as_ref().strip_prefix(cwd).unwrap_or(path.as_ref());
148+
// replace windows \ path separator with posix style one
149+
// reflects what eslint is outputting
150+
path.to_string_lossy().replace('\\', "/")
151+
};
142152

143153
let source = Arc::new(NamedSource::new(path_display, source_text.to_owned()));
144154
let diagnostics = diagnostics
@@ -167,7 +177,7 @@ impl DiagnosticService {
167177
}
168178
})
169179
.collect();
170-
(path.to_path_buf(), diagnostics)
180+
diagnostics
171181
}
172182

173183
/// # Panics

crates/oxc_linter/src/service/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,14 @@ impl<'l> Runtime<'l> {
522522

523523
if !messages.is_empty() {
524524
let errors = messages.into_iter().map(Into::into).collect();
525-
let path = path.strip_prefix(&me.cwd).unwrap_or(path);
526525
let diagnostics = DiagnosticService::wrap_diagnostics(
526+
&me.cwd,
527527
path,
528528
&owner.source_text,
529529
section.source.start,
530530
errors,
531531
);
532-
tx_error.send(Some(diagnostics)).unwrap();
532+
tx_error.send(Some((path.to_path_buf(), diagnostics))).unwrap();
533533
}
534534
}
535535
// If the new source text is owned, that means it was modified,

0 commit comments

Comments
 (0)