diff --git a/crates/oxc_language_server/src/backend.rs b/crates/oxc_language_server/src/backend.rs index c1a2f762fce6f..d51cb3f524d12 100644 --- a/crates/oxc_language_server/src/backend.rs +++ b/crates/oxc_language_server/src/backend.rs @@ -86,14 +86,14 @@ impl LanguageServer for Backend { return Some(new_settings); } - let deprecated_settings = value.get("settings"); - // the client has deprecated settings and has a deprecated root uri. // handle all things like the old way - if deprecated_settings.is_some() && params.root_uri.is_some() { + if let (Some(deprecated_settings), Some(root_uri)) = + (value.get("settings"), params.root_uri.as_ref()) + { return Some(vec![WorkspaceOption { - workspace_uri: params.root_uri.clone().unwrap(), - options: deprecated_settings.unwrap().clone(), + workspace_uri: root_uri.clone(), + options: deprecated_settings.clone(), }]); } @@ -129,10 +129,10 @@ impl LanguageServer for Backend { // start the linter. We do not start the linter when the client support the request, // we will init the linter after requesting for the workspace configuration. if !capabilities.workspace_configuration || options.is_some() { + let options = options.unwrap_or_default(); + for worker in &workers { let option = options - .as_deref() - .unwrap_or_default() .iter() .find(|workspace_option| { worker.is_responsible_for_uri(&workspace_option.workspace_uri) @@ -522,7 +522,7 @@ impl LanguageServer for Backend { let content = params.content_changes.first().map(|c| c.text.clone()); if let Some(content) = &content { - self.file_system.write().await.set(&uri, content.clone()); + self.file_system.write().await.set(uri.clone(), content.clone()); } if let Some(diagnostics) = worker.run_diagnostic_on_change(&uri, content.as_deref()).await { @@ -545,7 +545,7 @@ impl LanguageServer for Backend { let content = params.text_document.text; - self.file_system.write().await.set(&uri, content.clone()); + self.file_system.write().await.set(uri.clone(), content.clone()); if let Some(diagnostics) = worker.run_diagnostic(&uri, Some(&content)).await { self.client diff --git a/crates/oxc_language_server/src/capabilities.rs b/crates/oxc_language_server/src/capabilities.rs index e2073d99c2b22..0eff8121169cb 100644 --- a/crates/oxc_language_server/src/capabilities.rs +++ b/crates/oxc_language_server/src/capabilities.rs @@ -4,7 +4,7 @@ use tower_lsp_server::lsp_types::{ WorkspaceFoldersServerCapabilities, WorkspaceServerCapabilities, }; -#[derive(Clone, Default)] +#[derive(Default)] pub struct Capabilities { pub workspace_apply_edit: bool, pub workspace_configuration: bool, diff --git a/crates/oxc_language_server/src/file_system.rs b/crates/oxc_language_server/src/file_system.rs index 66df02cce693d..86d41bc4b8482 100644 --- a/crates/oxc_language_server/src/file_system.rs +++ b/crates/oxc_language_server/src/file_system.rs @@ -12,8 +12,8 @@ impl LSPFileSystem { self.files.pin().clear(); } - pub fn set(&self, uri: &Uri, content: String) { - self.files.pin().insert(uri.clone(), content); + pub fn set(&self, uri: Uri, content: String) { + self.files.pin().insert(uri, content); } pub fn get(&self, uri: &Uri) -> Option { diff --git a/crates/oxc_language_server/src/linter/server_linter.rs b/crates/oxc_language_server/src/linter/server_linter.rs index 23f64e0611144..a1d1df8fc2ddf 100644 --- a/crates/oxc_language_server/src/linter/server_linter.rs +++ b/crates/oxc_language_server/src/linter/server_linter.rs @@ -458,7 +458,7 @@ impl Tool for ServerLinter { &self, uri: &Uri, range: &Range, - only_code_action_kinds: Option>, + only_code_action_kinds: Option<&Vec>, ) -> Vec { let actions = self.get_code_actions_for_uri(uri); diff --git a/crates/oxc_language_server/src/options.rs b/crates/oxc_language_server/src/options.rs index 60ee0c55153b7..08daf9a3042e7 100644 --- a/crates/oxc_language_server/src/options.rs +++ b/crates/oxc_language_server/src/options.rs @@ -1,7 +1,7 @@ use serde::{Deserialize, Serialize}; use tower_lsp_server::lsp_types::Uri; -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct WorkspaceOption { pub workspace_uri: Uri, diff --git a/crates/oxc_language_server/src/tests.rs b/crates/oxc_language_server/src/tests.rs index 338f144199c44..bbbfc18f84b2e 100644 --- a/crates/oxc_language_server/src/tests.rs +++ b/crates/oxc_language_server/src/tests.rs @@ -110,7 +110,7 @@ impl Tool for FakeTool { &self, uri: &Uri, _range: &Range, - _only_code_action_kinds: Option>, + _only_code_action_kinds: Option<&Vec>, ) -> Vec { if uri.as_str().ends_with("code_action.config") { return vec![CodeActionOrCommand::CodeAction(CodeAction { diff --git a/crates/oxc_language_server/src/tool.rs b/crates/oxc_language_server/src/tool.rs index 5667320e4546d..658540cb7e36d 100644 --- a/crates/oxc_language_server/src/tool.rs +++ b/crates/oxc_language_server/src/tool.rs @@ -68,7 +68,7 @@ pub trait Tool: Send + Sync { &self, _uri: &Uri, _range: &Range, - _only_code_action_kinds: Option>, + _only_code_action_kinds: Option<&Vec>, ) -> Vec { Vec::new() } diff --git a/crates/oxc_language_server/src/worker.rs b/crates/oxc_language_server/src/worker.rs index fc9ebaa97d40f..413030653f3e6 100644 --- a/crates/oxc_language_server/src/worker.rs +++ b/crates/oxc_language_server/src/worker.rs @@ -202,7 +202,7 @@ impl WorkspaceWorker { actions.extend(tool.get_code_actions_or_commands( uri, range, - only_code_action_kinds.clone(), + only_code_action_kinds.as_ref(), )); } actions @@ -470,7 +470,7 @@ mod tests { let fs = LSPFileSystem::default(); fs.set( - &Uri::from_str("file:///root/diagnostics.config").unwrap(), + Uri::from_str("file:///root/diagnostics.config").unwrap(), "hello world".to_string(), ); @@ -533,7 +533,7 @@ mod tests { let fs = LSPFileSystem::default(); fs.set( - &Uri::from_str("file:///root/diagnostics.config").unwrap(), + Uri::from_str("file:///root/diagnostics.config").unwrap(), "hello world".to_string(), );