From 2141543105dd9aabc0aca0534abc837f114e5bac Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 17 Jan 2024 20:22:28 +0000 Subject: feat(lsp): send "deno/didChangeDenoConfiguration" on init (#21965) --- cli/lsp/language_server.rs | 34 ++++++++++++++++++++++++++++++++-- cli/lsp/lsp_custom.rs | 24 ++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) (limited to 'cli/lsp') diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index a3c817526..921e34bcd 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -1629,7 +1629,10 @@ impl Inner { .iter() .filter(|e| files_to_check.contains(&e.uri)) .map(|e| lsp_custom::DenoConfigurationChangeEvent { - file_event: e.clone(), + uri: e.uri.clone(), + typ: lsp_custom::DenoConfigurationChangeType::from_file_change_type( + e.typ, + ), configuration_type: lsp_custom::DenoConfigurationType::DenoJson, }), ); @@ -1660,7 +1663,10 @@ impl Inner { .iter() .filter(|e| files_to_check.contains(&e.uri)) .map(|e| lsp_custom::DenoConfigurationChangeEvent { - file_event: e.clone(), + uri: e.uri.clone(), + typ: lsp_custom::DenoConfigurationChangeType::from_file_change_type( + e.typ, + ), configuration_type: lsp_custom::DenoConfigurationType::PackageJson, }), ); @@ -3303,6 +3309,30 @@ impl tower_lsp::LanguageServer for LanguageServer { ); ls.maybe_testing_server = Some(test_server); } + + let mut config_events = vec![]; + if let Some(config_file) = ls.config.maybe_config_file() { + config_events.push(lsp_custom::DenoConfigurationChangeEvent { + uri: config_file.specifier.clone(), + typ: lsp_custom::DenoConfigurationChangeType::Added, + configuration_type: lsp_custom::DenoConfigurationType::DenoJson, + }); + } + if let Some(package_json) = &ls.maybe_package_json { + config_events.push(lsp_custom::DenoConfigurationChangeEvent { + uri: package_json.specifier(), + typ: lsp_custom::DenoConfigurationChangeType::Added, + configuration_type: lsp_custom::DenoConfigurationType::PackageJson, + }); + } + if !config_events.is_empty() { + ls.client.send_did_change_deno_configuration_notification( + lsp_custom::DidChangeDenoConfigurationNotificationParams { + changes: config_events, + }, + ); + } + (ls.client.clone(), ls.http_client.clone()) }; diff --git a/cli/lsp/lsp_custom.rs b/cli/lsp/lsp_custom.rs index 7abe56125..63f50d39f 100644 --- a/cli/lsp/lsp_custom.rs +++ b/cli/lsp/lsp_custom.rs @@ -60,6 +60,25 @@ pub struct DiagnosticBatchNotificationParams { pub messages_len: usize, } +#[derive(Debug, Eq, Hash, PartialEq, Copy, Clone, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub enum DenoConfigurationChangeType { + Added, + Changed, + Removed, +} + +impl DenoConfigurationChangeType { + pub fn from_file_change_type(file_event: lsp::FileChangeType) -> Self { + match file_event { + lsp::FileChangeType::CREATED => Self::Added, + lsp::FileChangeType::CHANGED => Self::Changed, + lsp::FileChangeType::DELETED => Self::Removed, + _ => Self::Changed, // non-exhaustable enum + } + } +} + #[derive(Debug, Eq, Hash, PartialEq, Copy, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub enum DenoConfigurationType { @@ -70,8 +89,9 @@ pub enum DenoConfigurationType { #[derive(Debug, Eq, Hash, PartialEq, Clone, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct DenoConfigurationChangeEvent { - #[serde(flatten)] - pub file_event: lsp::FileEvent, + pub uri: lsp::Url, + #[serde(rename = "type")] + pub typ: DenoConfigurationChangeType, pub configuration_type: DenoConfigurationType, } -- cgit v1.2.3