diff options
Diffstat (limited to 'cli/lsp')
-rw-r--r-- | cli/lsp/config.rs | 66 | ||||
-rw-r--r-- | cli/lsp/language_server.rs | 42 |
2 files changed, 51 insertions, 57 deletions
diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index 3e1b9fe85..33f9122da 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -165,8 +165,8 @@ impl ConfigSnapshot { } enum ConfigRequest { + All, Specifier(ModuleSpecifier, ModuleSpecifier), - Workspace, } #[derive(Debug, Default, Clone)] @@ -197,12 +197,8 @@ impl Config { loop { match rx.recv().await { None => break, - Some(ConfigRequest::Workspace) => { - let mut items = vec![lsp::ConfigurationItem { - scope_uri: None, - section: Some(SETTINGS_SECTION.to_string()), - }]; - let (specifier_uri_map, mut specifier_items): ( + Some(ConfigRequest::All) => { + let (specifier_uri_map, items): ( Vec<(ModuleSpecifier, ModuleSpecifier)>, Vec<lsp::ConfigurationItem>, ) = { @@ -223,40 +219,18 @@ impl Config { .collect(), ) }; - items.append(&mut specifier_items); if let Ok(configs) = client.configuration(items).await { let mut settings = settings_ref.write().unwrap(); for (i, value) in configs.into_iter().enumerate() { - match i { - 0 => { - match serde_json::from_value::<WorkspaceSettings>(value) { - Ok(workspace_settings) => { - settings.workspace = workspace_settings; - } - Err(err) => { - error!( - "Error converting workspace settings: {}", - err - ); - } - } + match serde_json::from_value::<SpecifierSettings>(value) { + Ok(specifier_settings) => { + let (specifier, uri) = specifier_uri_map[i].clone(); + settings + .specifiers + .insert(specifier, (uri, specifier_settings)); } - _ => { - match serde_json::from_value::<SpecifierSettings>(value) { - Ok(specifier_settings) => { - let (specifier, uri) = - specifier_uri_map[i - 1].clone(); - settings - .specifiers - .insert(specifier, (uri, specifier_settings)); - } - Err(err) => { - error!( - "Error converting specifier settings: {}", - err - ); - } - } + Err(err) => { + error!("Error converting specifier settings: {}", err); } } } @@ -376,22 +350,24 @@ impl Config { } } - pub async fn update_specifier_settings( - &self, - specifier: &ModuleSpecifier, - uri: &ModuleSpecifier, - ) -> Result<(), AnyError> { + /// Update all currently cached specifier settings + pub async fn update_all_settings(&self) -> Result<(), AnyError> { self .tx - .send(ConfigRequest::Specifier(specifier.clone(), uri.clone())) + .send(ConfigRequest::All) .await .map_err(|_| anyhow!("Error sending config update task.")) } - pub async fn update_workspace_settings(&self) -> Result<(), AnyError> { + /// Update a specific specifiers settings from the client. + pub async fn update_specifier_settings( + &self, + specifier: &ModuleSpecifier, + uri: &ModuleSpecifier, + ) -> Result<(), AnyError> { self .tx - .send(ConfigRequest::Workspace) + .send(ConfigRequest::Specifier(specifier.clone(), uri.clone())) .await .map_err(|_| anyhow!("Error sending config update task.")) } diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index ebcb6b9e3..c8b959596 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -677,18 +677,36 @@ impl Inner { .performance .mark("did_change_configuration", Some(¶ms)); - if self.config.client_capabilities.workspace_configuration { - if let Err(err) = self.config.update_workspace_settings().await { - error!("Error updating workspace settings: {}", err); - } - } else if let Some(config) = params - .settings - .as_object() - .map(|settings| settings.get(SETTINGS_SECTION)) - .flatten() - .cloned() - { - if let Err(err) = self.config.set_workspace_settings(config) { + let maybe_config = + if self.config.client_capabilities.workspace_configuration { + let config_response = self + .client + .configuration(vec![ConfigurationItem { + scope_uri: None, + section: Some(SETTINGS_SECTION.to_string()), + }]) + .await; + if let Err(err) = self.config.update_all_settings().await { + error!("Cannot request updating all settings: {}", err); + } + match config_response { + Ok(value_vec) => value_vec.get(0).cloned(), + Err(err) => { + error!("Error getting workspace configuration: {}", err); + None + } + } + } else { + params + .settings + .as_object() + .map(|settings| settings.get(SETTINGS_SECTION)) + .flatten() + .cloned() + }; + + if let Some(value) = maybe_config { + if let Err(err) = self.config.set_workspace_settings(value) { error!("failed to update settings: {}", err); } } |