Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions crates/oxc_language_server/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ impl LanguageServer for Backend {
continue;
};

let (diagnostics, registrations, unregistrations) =
worker.did_change_configuration(option.options).await;
let (diagnostics, registrations, unregistrations) = worker
.did_change_configuration(option.options, &*self.file_system.read().await)
.await;

if let Some(diagnostics) = diagnostics {
new_diagnostics.extend(diagnostics);
Expand Down Expand Up @@ -390,7 +391,7 @@ impl LanguageServer for Backend {
continue;
};
let (diagnostics, registrations, unregistrations) =
worker.did_change_watched_files(file_event).await;
worker.did_change_watched_files(file_event, &*self.file_system.read().await).await;

if let Some(diagnostics) = diagnostics {
new_diagnostics.extend(diagnostics);
Expand Down Expand Up @@ -503,9 +504,6 @@ impl LanguageServer for Backend {
return;
};

// saving the file means we can read again from the file system
self.file_system.write().await.remove(uri);

if let Some(diagnostics) = worker.run_diagnostic_on_save(uri, params.text.as_deref()).await
{
self.client.publish_diagnostics(uri.clone(), diagnostics, None).await;
Expand Down
14 changes: 2 additions & 12 deletions crates/oxc_language_server/src/formatter/server_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,13 @@ impl Tool for ServerFormatter {
};

if old_option == new_option {
return ToolRestartChanges {
tool: None,
diagnostic_reports: None,
watch_patterns: None,
};
return ToolRestartChanges { tool: None, watch_patterns: None };
}

let new_formatter = ServerFormatterBuilder::build(root_uri, new_options_json.clone());
let watch_patterns = new_formatter.get_watcher_patterns(new_options_json);
ToolRestartChanges {
tool: Some(Box::new(new_formatter)),
diagnostic_reports: None,
watch_patterns: Some(watch_patterns),
}
}
Expand Down Expand Up @@ -228,11 +223,7 @@ impl Tool for ServerFormatter {
options: serde_json::Value,
) -> ToolRestartChanges {
if !self.should_run {
return ToolRestartChanges {
tool: None,
diagnostic_reports: None,
watch_patterns: None,
};
return ToolRestartChanges { tool: None, watch_patterns: None };
}

// TODO: Check if the changed file is actually a config file
Expand All @@ -241,7 +232,6 @@ impl Tool for ServerFormatter {

ToolRestartChanges {
tool: Some(Box::new(new_formatter)),
diagnostic_reports: None,
// TODO: update watch patterns if config_path changed
watch_patterns: None,
}
Expand Down
29 changes: 2 additions & 27 deletions crates/oxc_language_server/src/linter/server_linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,11 @@ impl Tool for ServerLinter {
};

if !Self::needs_restart(&old_option, &new_options) {
return ToolRestartChanges {
tool: None,
diagnostic_reports: None,
watch_patterns: None,
};
return ToolRestartChanges { tool: None, watch_patterns: None };
}

// get the cached files before refreshing the linter, and revalidate them after
let cached_files = self.get_cached_files_of_diagnostics();
let new_linter = ServerLinterBuilder::build(root_uri, new_options_json.clone());
let diagnostics = Some(new_linter.revalidate_diagnostics(cached_files));

let patterns = {
if old_option.config_path == new_options.config_path
Expand All @@ -367,11 +361,7 @@ impl Tool for ServerLinter {
}
};

ToolRestartChanges {
tool: Some(Box::new(new_linter)),
diagnostic_reports: diagnostics,
watch_patterns: patterns,
}
ToolRestartChanges { tool: Some(Box::new(new_linter)), watch_patterns: patterns }
}

fn get_watcher_patterns(&self, options: serde_json::Value) -> Vec<Pattern> {
Expand Down Expand Up @@ -410,13 +400,8 @@ impl Tool for ServerLinter {
// TODO: Check if the changed file is actually a config file (including extended paths)
let new_linter = ServerLinterBuilder::build(root_uri, options);

// get the cached files before refreshing the linter, and revalidate them after
let cached_files = self.get_cached_files_of_diagnostics();
let diagnostics = Some(new_linter.revalidate_diagnostics(cached_files));

ToolRestartChanges {
tool: Some(Box::new(new_linter)),
diagnostic_reports: diagnostics,
// TODO: update watch patterns if config_path changed, or the extended paths changed
watch_patterns: None,
}
Expand Down Expand Up @@ -591,16 +576,6 @@ impl ServerLinter {
self.diagnostics.pin().keys().filter_map(|s| Uri::from_str(s).ok()).collect()
}

fn revalidate_diagnostics(&self, uris: Vec<Uri>) -> Vec<(String, Vec<Diagnostic>)> {
let mut diagnostics = Vec::with_capacity(uris.len());
for uri in uris {
if let Some(file_diagnostic) = self.run_diagnostic(&uri, None) {
diagnostics.push((uri.to_string(), file_diagnostic));
}
}
diagnostics
}

fn is_ignored(&self, uri: &Uri) -> bool {
let Some(uri_path) = uri.to_file_path() else {
return true;
Expand Down
41 changes: 7 additions & 34 deletions crates/oxc_language_server/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,19 @@ impl Tool for FakeTool {
_old_options_json: &serde_json::Value,
new_options_json: serde_json::Value,
) -> ToolRestartChanges {
if new_options_json.as_u64() == Some(1) {
if new_options_json.as_u64() == Some(1) || new_options_json.as_u64() == Some(3) {
return ToolRestartChanges {
tool: Some(FakeToolBuilder.build_boxed(root_uri, new_options_json)),
diagnostic_reports: None,
watch_patterns: None,
};
}
if new_options_json.as_u64() == Some(2) {
return ToolRestartChanges {
tool: None,
diagnostic_reports: None,
watch_patterns: Some(vec!["**/new_watcher.config".to_string()]),
};
}
if new_options_json.as_u64() == Some(3) {
return ToolRestartChanges {
tool: None,
diagnostic_reports: Some(vec![(
root_uri.to_string(),
vec![Diagnostic {
message: "Fake diagnostic".to_string(),
..Default::default()
}],
)]),
watch_patterns: None,
};
}
ToolRestartChanges { tool: None, diagnostic_reports: None, watch_patterns: None }
ToolRestartChanges { tool: None, watch_patterns: None }
}

fn get_watcher_patterns(
Expand All @@ -101,34 +86,22 @@ impl Tool for FakeTool {
root_uri: &Uri,
options: serde_json::Value,
) -> ToolRestartChanges {
if changed_uri.as_str().ends_with("tool.config") {
if changed_uri.as_str().ends_with("tool.config")
|| changed_uri.as_str().ends_with("diagnostics.config")
{
return ToolRestartChanges {
tool: Some(FakeToolBuilder.build_boxed(root_uri, options)),
diagnostic_reports: None,
watch_patterns: None,
};
}
if changed_uri.as_str().ends_with("watcher.config") {
return ToolRestartChanges {
tool: None,
diagnostic_reports: None,
watch_patterns: Some(vec!["**/new_watcher.config".to_string()]),
};
}
if changed_uri.as_str().ends_with("diagnostics.config") {
return ToolRestartChanges {
tool: None,
diagnostic_reports: Some(vec![(
changed_uri.to_string(),
vec![Diagnostic {
message: "Fake diagnostic".to_string(),
..Default::default()
}],
)]),
watch_patterns: None,
};
}
ToolRestartChanges { tool: None, diagnostic_reports: None, watch_patterns: None }

ToolRestartChanges { tool: None, watch_patterns: None }
}

fn get_code_actions_or_commands(
Expand Down
2 changes: 0 additions & 2 deletions crates/oxc_language_server/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ pub struct ToolRestartChanges {
/// The tool that was restarted (linter, formatter).
/// If None, no tool was restarted.
pub tool: Option<Box<dyn Tool>>,
/// The diagnostic reports that need to be revalidated after the tool restart
pub diagnostic_reports: Option<Vec<(String, Vec<Diagnostic>)>>,
/// The patterns that were added during the tool restart
/// Old patterns will be automatically unregistered
pub watch_patterns: Option<Vec<Pattern>>,
Expand Down
Loading
Loading