diff options
| author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-11-14 22:10:51 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-14 22:10:51 +0000 |
| commit | 4913274a6508a5e5ad6c8babf2e90a4a84bf98ec (patch) | |
| tree | 687e2b6846a8288b4bc9c2896a947b68007731f3 /cli/lsp | |
| parent | ab0c637425c3219c2a5f59c25ae8ea593018568b (diff) | |
feat(lsp): upgrade check on init and notification (#21105)
Diffstat (limited to 'cli/lsp')
| -rw-r--r-- | cli/lsp/client.rs | 31 | ||||
| -rw-r--r-- | cli/lsp/language_server.rs | 21 | ||||
| -rw-r--r-- | cli/lsp/logging.rs | 12 | ||||
| -rw-r--r-- | cli/lsp/lsp_custom.rs | 21 |
4 files changed, 80 insertions, 5 deletions
diff --git a/cli/lsp/client.rs b/cli/lsp/client.rs index 84953c4d4..915af6831 100644 --- a/cli/lsp/client.rs +++ b/cli/lsp/client.rs @@ -96,6 +96,17 @@ impl Client { }); } + pub fn send_did_upgrade_check_notification( + &self, + params: lsp_custom::DidUpgradeCheckNotificationParams, + ) { + // do on a task in case the caller currently is in the lsp lock + let client = self.0.clone(); + spawn(async move { + client.send_did_upgrade_check_notification(params).await; + }); + } + pub fn show_message( &self, message_type: lsp::MessageType, @@ -165,6 +176,10 @@ trait ClientTrait: Send + Sync { &self, params: lsp_custom::DidChangeDenoConfigurationNotificationParams, ); + async fn send_did_upgrade_check_notification( + &self, + params: lsp_custom::DidUpgradeCheckNotificationParams, + ); async fn workspace_configuration( &self, scopes: Vec<Option<lsp::Url>>, @@ -249,6 +264,16 @@ impl ClientTrait for TowerClient { .await } + async fn send_did_upgrade_check_notification( + &self, + params: lsp_custom::DidUpgradeCheckNotificationParams, + ) { + self + .0 + .send_notification::<lsp_custom::DidUpgradeCheckNotification>(params) + .await + } + async fn workspace_configuration( &self, scopes: Vec<Option<lsp::Url>>, @@ -350,6 +375,12 @@ impl ClientTrait for ReplClient { ) { } + async fn send_did_upgrade_check_notification( + &self, + _params: lsp_custom::DidUpgradeCheckNotificationParams, + ) { + } + async fn workspace_configuration( &self, scopes: Vec<Option<lsp::Url>>, diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 667df74bb..6f0c96746 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -112,6 +112,8 @@ use crate::npm::CliNpmResolverManagedPackageJsonInstallerOption; use crate::npm::CliNpmResolverManagedSnapshotOption; use crate::tools::fmt::format_file; use crate::tools::fmt::format_parsed_source; +use crate::tools::upgrade::check_for_upgrades_for_lsp; +use crate::tools::upgrade::upgrade_check_enabled; use crate::util::fs::remove_dir_all_if_exists; use crate::util::path::is_importable_ext; use crate::util::path::specifier_to_file_path; @@ -3189,6 +3191,25 @@ impl tower_lsp::LanguageServer for LanguageServer { } lsp_log!("Server ready."); + + if upgrade_check_enabled() { + let http_client = self.0.read().await.http_client.clone(); + match check_for_upgrades_for_lsp(http_client).await { + Ok(version_info) => { + client.send_did_upgrade_check_notification( + lsp_custom::DidUpgradeCheckNotificationParams { + upgrade_available: version_info.map( + |(latest_version, is_canary)| lsp_custom::UpgradeAvailable { + latest_version, + is_canary, + }, + ), + }, + ); + } + Err(err) => lsp_warn!("Failed to check for upgrades: {err}"), + } + } } async fn shutdown(&self) -> LspResult<()> { diff --git a/cli/lsp/logging.rs b/cli/lsp/logging.rs index 8b703f2a5..b8c8c99e6 100644 --- a/cli/lsp/logging.rs +++ b/cli/lsp/logging.rs @@ -62,11 +62,13 @@ macro_rules! lsp_log { /// for downgrading these logs to another log level in the REPL. macro_rules! lsp_warn { ($($arg:tt)+) => ( - let lsp_log_level = $crate::lsp::logging::lsp_warn_level(); - if lsp_log_level == log::Level::Debug { - $crate::lsp::logging::lsp_debug!($($arg)+) - } else { - log::log!(lsp_log_level, $($arg)+) + { + let lsp_log_level = $crate::lsp::logging::lsp_warn_level(); + if lsp_log_level == log::Level::Debug { + $crate::lsp::logging::lsp_debug!($($arg)+) + } else { + log::log!(lsp_log_level, $($arg)+) + } } ) } diff --git a/cli/lsp/lsp_custom.rs b/cli/lsp/lsp_custom.rs index 685da6b14..96f7be790 100644 --- a/cli/lsp/lsp_custom.rs +++ b/cli/lsp/lsp_custom.rs @@ -91,6 +91,27 @@ impl lsp::notification::Notification const METHOD: &'static str = "deno/didChangeDenoConfiguration"; } +pub enum DidUpgradeCheckNotification {} + +impl lsp::notification::Notification for DidUpgradeCheckNotification { + type Params = DidUpgradeCheckNotificationParams; + + const METHOD: &'static str = "deno/didUpgradeCheck"; +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct UpgradeAvailable { + pub latest_version: String, + pub is_canary: bool, +} + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct DidUpgradeCheckNotificationParams { + pub upgrade_available: Option<UpgradeAvailable>, +} + /// This notification is only sent for testing purposes /// in order to know what the latest diagnostics are. pub enum DiagnosticBatchNotification {} |
