summaryrefslogtreecommitdiff
path: root/cli/lsp/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/config.rs')
-rw-r--r--cli/lsp/config.rs66
1 files changed, 21 insertions, 45 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."))
}