Skip to content

Commit 7ef3bc5

Browse files
committed
perf(langage_server): prebuild IsolatedLintHandler
1 parent b3b3054 commit 7ef3bc5

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

crates/oxc_language_server/src/linter/isolated_lint_handler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ pub struct IsolatedLintHandlerOptions {
2929
}
3030

3131
pub struct IsolatedLintHandler {
32-
linter: Arc<Linter>,
33-
options: Arc<IsolatedLintHandlerOptions>,
32+
linter: Linter,
33+
options: IsolatedLintHandlerOptions,
3434
}
3535

3636
impl IsolatedLintHandler {
37-
pub fn new(linter: Arc<Linter>, options: Arc<IsolatedLintHandlerOptions>) -> Self {
37+
pub fn new(linter: Linter, options: IsolatedLintHandlerOptions) -> Self {
3838
Self { linter, options }
3939
}
4040

@@ -121,7 +121,7 @@ impl IsolatedLintHandler {
121121
.with_cross_module(self.options.use_cross_module);
122122
// ToDo: do not clone the linter
123123
let path_arc = Arc::from(path.as_os_str());
124-
let mut lint_service = LintService::new((*self.linter).clone(), lint_service_options);
124+
let mut lint_service = LintService::new(self.linter.clone(), lint_service_options);
125125
let result = lint_service.run_source(allocator, &path_arc, &source_text);
126126

127127
Some(result)

crates/oxc_language_server/src/linter/server_linter.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,28 @@ use super::isolated_lint_handler::IsolatedLintHandlerOptions;
1111

1212
#[derive(Clone)]
1313
pub struct ServerLinter {
14-
linter: Arc<Linter>,
15-
options: Arc<IsolatedLintHandlerOptions>,
14+
isolated_linter: Arc<IsolatedLintHandler>,
1615
}
1716

1817
impl ServerLinter {
1918
pub fn new(options: IsolatedLintHandlerOptions) -> Self {
2019
let config_store =
2120
ConfigStoreBuilder::default().build().expect("Failed to build config store");
2221
let linter = Linter::new(LintOptions::default(), config_store).with_fix(FixKind::SafeFix);
23-
Self { linter: Arc::new(linter), options: Arc::new(options) }
22+
23+
let isolated_linter = Arc::new(IsolatedLintHandler::new(linter, options));
24+
25+
Self { isolated_linter }
2426
}
2527

2628
pub fn new_with_linter(linter: Linter, options: IsolatedLintHandlerOptions) -> Self {
27-
Self { linter: Arc::new(linter), options: Arc::new(options) }
29+
let isolated_linter = Arc::new(IsolatedLintHandler::new(linter, options));
30+
31+
Self { isolated_linter }
2832
}
2933

3034
pub fn run_single(&self, uri: &Uri, content: Option<String>) -> Option<Vec<DiagnosticReport>> {
31-
IsolatedLintHandler::new(Arc::clone(&self.linter), Arc::clone(&self.options))
32-
.run_single(&uri.to_file_path().unwrap(), content)
35+
self.isolated_linter.run_single(&uri.to_file_path().unwrap(), content)
3336
}
3437
}
3538

0 commit comments

Comments
 (0)