Skip to content

Commit bb999a3

Browse files
authored
refactor(language_server): avoid cloning linter by taking reference in LintService (#10907)
1 parent 6de0bc2 commit bb999a3

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

apps/oxlint/src/lint.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,18 +293,16 @@ impl Runner for LintRunner {
293293
}
294294
}
295295

296-
let mut lint_service = LintService::new(linter, options);
297296
let mut diagnostic_service =
298297
Self::get_diagnostic_service(&output_formatter, &warning_options, &misc_options);
298+
let tx_error = diagnostic_service.sender().clone();
299299

300-
let number_of_rules = lint_service.linter().number_of_rules();
300+
let number_of_rules = linter.number_of_rules();
301301

302302
// Spawn linting in another thread so diagnostics can be printed immediately from diagnostic_service.run.
303-
rayon::spawn({
304-
let tx_error = diagnostic_service.sender().clone();
305-
move || {
306-
lint_service.run(&tx_error);
307-
}
303+
rayon::spawn(move || {
304+
let mut lint_service = LintService::new(&linter, options);
305+
lint_service.run(&tx_error);
308306
});
309307

310308
let diagnostic_result = diagnostic_service.run(stdout);

crates/oxc_language_server/src/linter/isolated_lint_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ impl IsolatedLintHandler {
137137
vec![Arc::from(path.as_os_str())],
138138
)
139139
.with_cross_module(self.options.use_cross_module);
140-
// ToDo: do not clone the linter
140+
141141
let mut lint_service =
142-
LintService::new(self.linter.clone(), lint_service_options).with_file_system(Box::new(
142+
LintService::new(&self.linter, lint_service_options).with_file_system(Box::new(
143143
IsolatedLintHandlerFileSystem::new(path.to_path_buf(), source_text),
144144
));
145145
let result = lint_service.run_source(allocator);

crates/oxc_linter/src/service/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ impl LintServiceOptions {
6565
}
6666
}
6767

68-
pub struct LintService {
69-
runtime: Runtime,
68+
pub struct LintService<'l> {
69+
runtime: Runtime<'l>,
7070
}
7171

72-
impl LintService {
73-
pub fn new(linter: Linter, options: LintServiceOptions) -> Self {
72+
impl<'l> LintService<'l> {
73+
pub fn new(linter: &'l Linter, options: LintServiceOptions) -> Self {
7474
let runtime = Runtime::new(linter, options);
7575
Self { runtime }
7676
}
@@ -84,10 +84,6 @@ impl LintService {
8484
self
8585
}
8686

87-
pub fn linter(&self) -> &Linter {
88-
&self.runtime.linter
89-
}
90-
9187
/// # Panics
9288
pub fn run(&mut self, tx_error: &DiagnosticSender) {
9389
self.runtime.run(tx_error);

crates/oxc_linter/src/service/runtime.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ use crate::fixer::{FixWithPosition, MessageWithPosition};
3838
#[cfg(feature = "language_server")]
3939
use crate::service::offset_to_position::{SpanPositionMessage, offset_to_position};
4040

41-
pub struct Runtime {
41+
pub struct Runtime<'l> {
4242
cwd: Box<Path>,
4343
/// All paths to lint
4444
paths: IndexSet<Arc<OsStr>, FxBuildHasher>,
45-
pub(super) linter: Linter,
45+
pub(super) linter: &'l Linter,
4646
resolver: Option<Resolver>,
4747

4848
pub(super) file_system: Box<dyn RuntimeFileSystem + Sync + Send>,
@@ -163,8 +163,8 @@ impl RuntimeFileSystem for OsFileSystem {
163163
}
164164
}
165165

166-
impl Runtime {
167-
pub(super) fn new(linter: Linter, options: LintServiceOptions) -> Self {
166+
impl<'l> Runtime<'l> {
167+
pub(super) fn new(linter: &'l Linter, options: LintServiceOptions) -> Self {
168168
let resolver = options.cross_module.then(|| {
169169
Self::get_resolver(options.tsconfig.or_else(|| Some(options.cwd.join("tsconfig.json"))))
170170
});

crates/oxc_linter/src/tester.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ impl Tester {
515515
let paths = vec![Arc::<OsStr>::from(path_to_lint.as_os_str())];
516516
let options =
517517
LintServiceOptions::new(cwd, paths).with_cross_module(self.plugins.has_import());
518-
let mut lint_service = LintService::new(linter, options).with_file_system(Box::new(
518+
let mut lint_service = LintService::new(&linter, options).with_file_system(Box::new(
519519
TesterFileSystem::new(path_to_lint, source_text.to_string()),
520520
));
521521

0 commit comments

Comments
 (0)