From 6bbccb72d7153f95688b63391672f2e2b979eeed Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 10 Oct 2023 05:53:41 +0100 Subject: [PATCH] refactor(lsp): add "deno.reloadImportRegistries" as a command (#20823) --- cli/lsp/capabilities.rs | 5 ++++- cli/lsp/language_server.rs | 9 ++++++--- cli/lsp/mod.rs | 3 +++ cli/tests/integration/lsp_tests.rs | 12 ++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cli/lsp/capabilities.rs b/cli/lsp/capabilities.rs index 8b624eafc1..c17a8360f2 100644 --- a/cli/lsp/capabilities.rs +++ b/cli/lsp/capabilities.rs @@ -121,7 +121,10 @@ pub fn server_capabilities( color_provider: None, execute_command_provider: Some(ExecuteCommandOptions { commands: if enable_builtin_commands { - vec!["deno.cache".into()] + vec![ + "deno.cache".to_string(), + "deno.reloadImportRegistries".to_string(), + ] } else { vec![] }, diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 9e553b8b9c..b19b00b4aa 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -3035,7 +3035,7 @@ impl tower_lsp::LanguageServer for LanguageServer { let referrer = serde_json::to_value(arguments.next()).unwrap(); let referrer: Url = serde_json::from_value(referrer) .map_err(|err| LspError::invalid_params(err.to_string()))?; - return self + self .cache_request(Some( serde_json::to_value(lsp_custom::CacheParams { referrer: TextDocumentIdentifier { uri: referrer }, @@ -3046,9 +3046,12 @@ impl tower_lsp::LanguageServer for LanguageServer { }) .expect("well formed json"), )) - .await; + .await + } else if params.command == "deno.reloadImportRegistries" { + self.0.write().await.reload_import_registries().await + } else { + Ok(None) } - Ok(None) } async fn initialize( diff --git a/cli/lsp/mod.rs b/cli/lsp/mod.rs index 3ef19173b4..c2f3eda717 100644 --- a/cli/lsp/mod.rs +++ b/cli/lsp/mod.rs @@ -49,6 +49,9 @@ pub async fn start() -> Result<(), AnyError> { lsp_custom::PERFORMANCE_REQUEST, LanguageServer::performance_request, ) + // TODO(nayeemrmn): The extension has replaced this with the + // `deno.reloadImportRegistries` command as of vscode_deno + // 3.26.0 / 2023.10.10. Remove this eventually. .custom_method( lsp_custom::RELOAD_IMPORT_REGISTRIES_REQUEST, LanguageServer::reload_import_registries_request, diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index 1fb1e0bc27..c13053db89 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -872,6 +872,18 @@ fn lsp_deno_task() { ); } +#[test] +fn lsp_reload_import_registries_command() { + let context = TestContextBuilder::new().use_temp_cwd().build(); + let mut client = context.new_lsp_command().build(); + client.initialize_default(); + let res = client.write_request( + "workspace/executeCommand", + json!({ "command": "deno.reloadImportRegistries" }), + ); + assert_eq!(res, json!(true)); +} + #[test] fn lsp_import_attributes() { let context = TestContextBuilder::new().use_temp_cwd().build();