Skip to content

Commit ecf2f7b

Browse files
committed
fix(language_server): fail gracefully when tsgolint executable not found (#15436)
fixes #15421
1 parent e6d0cd7 commit ecf2f7b

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

crates/oxc_language_server/src/linter/isolated_lint_handler.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
sync::{Arc, OnceLock},
44
};
55

6-
use log::debug;
6+
use log::{debug, warn};
77
use oxc_data_structures::rope::Rope;
88
use rustc_hash::FxHashSet;
99
use tower_lsp_server::{UriExt, lsp_types::Uri};
@@ -69,6 +69,8 @@ impl IsolatedLintHandler {
6969
config_store: ConfigStore,
7070
options: &IsolatedLintHandlerOptions,
7171
) -> Self {
72+
let config_store_clone = config_store.clone();
73+
7274
let linter = Linter::new(lint_options, config_store, None);
7375
let mut lint_service_options = LintServiceOptions::new(options.root_path.clone())
7476
.with_cross_module(options.use_cross_module);
@@ -80,14 +82,24 @@ impl IsolatedLintHandler {
8082
lint_service_options = lint_service_options.with_tsconfig(tsconfig_path);
8183
}
8284

83-
Self {
84-
runner: LintRunnerBuilder::new(lint_service_options, linter)
85-
.with_type_aware(options.type_aware)
86-
.with_fix_kind(options.fix_kind)
87-
.build()
88-
.unwrap(),
89-
unused_directives_severity: lint_options.report_unused_directive,
90-
}
85+
let runner = match LintRunnerBuilder::new(lint_service_options.clone(), linter)
86+
.with_type_aware(options.type_aware)
87+
.with_fix_kind(options.fix_kind)
88+
.build()
89+
{
90+
Ok(runner) => runner,
91+
Err(e) => {
92+
warn!("Failed to initialize type-aware linting: {e}");
93+
let linter = Linter::new(lint_options, config_store_clone, None);
94+
LintRunnerBuilder::new(lint_service_options, linter)
95+
.with_type_aware(false)
96+
.with_fix_kind(options.fix_kind)
97+
.build()
98+
.expect("Failed to build LintRunner without type-aware linting")
99+
}
100+
};
101+
102+
Self { runner, unused_directives_severity: lint_options.report_unused_directive }
91103
}
92104

93105
pub fn run_single(

0 commit comments

Comments
 (0)