Skip to content

Commit 3f7e73e

Browse files
committed
refactor(language_server): WorkerspaceWorker::start_worker consume serde_json::Value (#15345)
not sure if this is really better :)
1 parent 59f3d6a commit 3f7e73e

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

crates/oxc_language_server/src/backend.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl LanguageServer for Backend {
131131
.map(|workspace_options| workspace_options.options.clone())
132132
.unwrap_or_default();
133133

134-
worker.start_worker(option).await;
134+
worker.start_worker(option.clone()).await;
135135
}
136136
}
137137

@@ -191,7 +191,7 @@ impl LanguageServer for Backend {
191191
for (index, worker) in needed_configurations.values().enumerate() {
192192
let configuration = configurations.get(index).unwrap_or(&serde_json::Value::Null);
193193

194-
worker.start_worker(configuration).await;
194+
worker.start_worker(configuration.clone()).await;
195195
}
196196
}
197197

@@ -428,7 +428,7 @@ impl LanguageServer for Backend {
428428
let worker = WorkspaceWorker::new(folder.uri.clone());
429429
// get the configuration from the response and init the linter
430430
let options = configurations.get(index).unwrap_or(&serde_json::Value::Null);
431-
worker.start_worker(options).await;
431+
worker.start_worker(options.clone()).await;
432432

433433
added_registrations.extend(worker.init_watchers().await);
434434
workers.push(worker);
@@ -438,7 +438,7 @@ impl LanguageServer for Backend {
438438
for folder in params.event.added {
439439
let worker = WorkspaceWorker::new(folder.uri);
440440
// use default options
441-
worker.start_worker(&serde_json::Value::Null).await;
441+
worker.start_worker(serde_json::Value::Null).await;
442442
workers.push(worker);
443443
}
444444
}

crates/oxc_language_server/src/formatter/tester.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Tester<'_> {
5959
.join(self.relative_root_dir);
6060
let uri = Uri::from_file_path(absolute_path).expect("could not convert current dir to uri");
6161
let worker = WorkspaceWorker::new(uri);
62-
worker.start_worker(&self.options).await;
62+
worker.start_worker(self.options.clone()).await;
6363

6464
worker
6565
}

crates/oxc_language_server/src/tester.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Tester<'_> {
106106
.join(self.relative_root_dir);
107107
let uri = Uri::from_file_path(absolute_path).expect("could not convert current dir to uri");
108108
let worker = WorkspaceWorker::new(uri);
109-
worker.start_worker(&self.options).await;
109+
worker.start_worker(self.options.clone()).await;
110110

111111
worker
112112
}

crates/oxc_language_server/src/worker.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ impl WorkspaceWorker {
7070

7171
/// Start all programs (linter, formatter) for the worker.
7272
/// This should be called after the client has sent the workspace configuration.
73-
pub async fn start_worker(&self, options: &serde_json::Value) {
73+
pub async fn start_worker(&self, options: serde_json::Value) {
7474
*self.options.lock().await = Some(options.clone());
7575
*self.server_linter.write().await =
7676
Some(ServerLinterBuilder::new(self.root_uri.clone(), options.clone()).build());
7777

7878
*self.server_formatter.write().await =
79-
ServerFormatterBuilder::new(self.root_uri.clone(), options.clone()).build();
79+
ServerFormatterBuilder::new(self.root_uri.clone(), options).build();
8080
}
8181

8282
/// Initialize file system watchers for the workspace.
@@ -551,7 +551,7 @@ mod test_watchers {
551551
}
552552

553553
impl Tester {
554-
pub fn new(relative_root_dir: &'static str, options: &serde_json::Value) -> Self {
554+
pub fn new(relative_root_dir: &'static str, options: serde_json::Value) -> Self {
555555
let absolute_path =
556556
std::env::current_dir().expect("could not get current dir").join(relative_root_dir);
557557
let uri =
@@ -566,7 +566,7 @@ mod test_watchers {
566566

567567
async fn create_workspace_worker(
568568
absolute_path: Uri,
569-
options: &serde_json::Value,
569+
options: serde_json::Value,
570570
) -> WorkspaceWorker {
571571
let worker = WorkspaceWorker::new(absolute_path);
572572
worker.start_worker(options).await;
@@ -628,7 +628,7 @@ mod test_watchers {
628628

629629
#[test]
630630
fn test_default_options() {
631-
let tester = Tester::new("fixtures/watcher/default", &json!({}));
631+
let tester = Tester::new("fixtures/watcher/default", json!({}));
632632
let registrations = tester.init_watchers();
633633

634634
assert_eq!(registrations.len(), 1);
@@ -639,7 +639,7 @@ mod test_watchers {
639639
fn test_custom_config_path() {
640640
let tester = Tester::new(
641641
"fixtures/watcher/default",
642-
&json!({
642+
json!({
643643
"configPath": "configs/lint.json"
644644
}),
645645
);
@@ -651,7 +651,7 @@ mod test_watchers {
651651

652652
#[test]
653653
fn test_linter_extends_configs() {
654-
let tester = Tester::new("fixtures/watcher/linter_extends", &json!({}));
654+
let tester = Tester::new("fixtures/watcher/linter_extends", json!({}));
655655
let registrations = tester.init_watchers();
656656

657657
// The `.oxlintrc.json` extends `./lint.json -> 2 watchers
@@ -667,7 +667,7 @@ mod test_watchers {
667667
fn test_linter_extends_custom_config_path() {
668668
let tester = Tester::new(
669669
"fixtures/watcher/linter_extends",
670-
&json!({
670+
json!({
671671
"configPath": ".oxlintrc.json"
672672
}),
673673
);
@@ -685,7 +685,7 @@ mod test_watchers {
685685
fn test_formatter_experimental_enabled() {
686686
let tester = Tester::new(
687687
"fixtures/watcher/default",
688-
&json!({
688+
json!({
689689
"fmt.experimental": true
690690
}),
691691
);
@@ -704,7 +704,7 @@ mod test_watchers {
704704
fn test_formatter_custom_config_path() {
705705
let tester = Tester::new(
706706
"fixtures/watcher/default",
707-
&json!({
707+
json!({
708708
"fmt.experimental": true,
709709
"fmt.configPath": "configs/formatter.json"
710710
}),
@@ -720,7 +720,7 @@ mod test_watchers {
720720
fn test_linter_and_formatter_custom_config_path() {
721721
let tester = Tester::new(
722722
"fixtures/watcher/default",
723-
&json!({
723+
json!({
724724
"configPath": "configs/lint.json",
725725
"fmt.experimental": true,
726726
"fmt.configPath": "configs/formatter.json"
@@ -742,15 +742,15 @@ mod test_watchers {
742742

743743
#[test]
744744
fn test_no_change() {
745-
let tester = Tester::new("fixtures/watcher/default", &json!({}));
745+
let tester = Tester::new("fixtures/watcher/default", json!({}));
746746
let (registration, unregistrations) = tester.did_change_configuration(json!({}));
747747
assert!(registration.is_empty());
748748
assert!(unregistrations.is_empty());
749749
}
750750

751751
#[test]
752752
fn test_lint_config_path_change() {
753-
let tester = Tester::new("fixtures/watcher/default", &json!({}));
753+
let tester = Tester::new("fixtures/watcher/default", json!({}));
754754
let (registration, unregistrations) = tester.did_change_configuration(json!( {
755755
"configPath": "configs/lint.json"
756756
}));
@@ -770,7 +770,7 @@ mod test_watchers {
770770

771771
#[test]
772772
fn test_lint_other_option_change() {
773-
let tester = Tester::new("fixtures/watcher/default", &json!({}));
773+
let tester = Tester::new("fixtures/watcher/default", json!({}));
774774
let (registration, unregistrations) = tester.did_change_configuration(json!({
775775
// run is the only option that does not require a restart
776776
"run": "onSave"
@@ -783,7 +783,7 @@ mod test_watchers {
783783
fn test_no_changes_with_formatter() {
784784
let tester = Tester::new(
785785
"fixtures/watcher/default",
786-
&json!({
786+
json!({
787787
"fmt.experimental": true,
788788
}),
789789
);
@@ -799,7 +799,7 @@ mod test_watchers {
799799
fn test_lint_config_path_change_with_formatter() {
800800
let tester = Tester::new(
801801
"fixtures/watcher/default",
802-
&json!({
802+
json!({
803803
"fmt.experimental": true
804804
}),
805805
);
@@ -821,7 +821,7 @@ mod test_watchers {
821821

822822
#[test]
823823
fn test_formatter_experimental_enabled() {
824-
let tester = Tester::new("fixtures/watcher/default", &json!({}));
824+
let tester = Tester::new("fixtures/watcher/default", json!({}));
825825
let (registration, unregistrations) = tester.did_change_configuration(json!({
826826
"fmt.experimental": true
827827
}));
@@ -839,7 +839,7 @@ mod test_watchers {
839839
fn test_formatter_custom_config_path() {
840840
let tester = Tester::new(
841841
"fixtures/watcher/default",
842-
&json!({
842+
json!({
843843
"fmt.experimental": true
844844
}),
845845
);
@@ -869,7 +869,7 @@ mod test_watchers {
869869
fn test_formatter_disabling() {
870870
let tester = Tester::new(
871871
"fixtures/watcher/default",
872-
&json!({
872+
json!({
873873
"fmt.experimental": true
874874
}),
875875
);

0 commit comments

Comments
 (0)