From 76ce1a8f50665a5f48cac578808dd3a1d273d4fb Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Thu, 18 Jul 2024 14:38:27 +0200 Subject: [PATCH] lsp: Use `LspCommand.check_capabilities` consistently (#14733) This is a follow-up to #14666 in which I noticed that we don't need that additional check, since each request will check whether it's supported via the call to `check_capabilities` before sending the request. Release Notes: - N/A --- crates/project/src/lsp_command.rs | 19 ++++++++----------- crates/project/src/project.rs | 20 +------------------- 2 files changed, 9 insertions(+), 30 deletions(-) diff --git a/crates/project/src/lsp_command.rs b/crates/project/src/lsp_command.rs index ac4aadc568..6d6f787507 100644 --- a/crates/project/src/lsp_command.rs +++ b/crates/project/src/lsp_command.rs @@ -1354,6 +1354,14 @@ impl LspCommand for GetHover { type LspRequest = lsp::request::HoverRequest; type ProtoRequest = proto::GetHover; + fn check_capabilities(&self, capabilities: AdapterServerCapabilities) -> bool { + match capabilities.server_capabilities.hover_provider { + Some(lsp::HoverProviderCapability::Simple(enabled)) => enabled, + Some(lsp::HoverProviderCapability::Options(_)) => true, + None => false, + } + } + fn to_lsp( &self, path: &Path, @@ -2062,17 +2070,6 @@ impl GetCodeActions { }) .unwrap_or(false) } - - pub fn supports_code_actions(capabilities: &ServerCapabilities) -> bool { - capabilities - .code_action_provider - .as_ref() - .map(|options| match options { - lsp::CodeActionProviderCapability::Simple(is_supported) => *is_supported, - lsp::CodeActionProviderCapability::Options(_) => true, - }) - .unwrap_or(false) - } } #[async_trait(?Send)] diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index e5c223aa38..3022a2f097 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -61,7 +61,7 @@ use lsp::{ CompletionContext, DiagnosticSeverity, DiagnosticTag, DidChangeWatchedFilesRegistrationOptions, DocumentHighlightKind, Edit, FileSystemWatcher, InsertTextFormat, LanguageServer, LanguageServerBinary, LanguageServerId, LspRequestFuture, MessageActionItem, OneOf, - ServerCapabilities, ServerHealthStatus, ServerStatus, TextEdit, WorkDoneProgressCancelParams, + ServerHealthStatus, ServerStatus, TextEdit, WorkDoneProgressCancelParams, }; use lsp_command::*; use node_runtime::NodeRuntime; @@ -5621,7 +5621,6 @@ impl Project { let all_actions_task = self.request_multiple_lsp_locally( buffer, Some(position), - |server_capabilities| server_capabilities.signature_help_provider.is_some(), GetSignatureHelp { position }, cx, ); @@ -5696,11 +5695,6 @@ impl Project { let all_actions_task = self.request_multiple_lsp_locally( &buffer, Some(position), - |server_capabilities| match server_capabilities.hover_provider { - Some(lsp::HoverProviderCapability::Simple(enabled)) => enabled, - Some(lsp::HoverProviderCapability::Options(_)) => true, - None => false, - }, GetHover { position }, cx, ); @@ -6286,7 +6280,6 @@ impl Project { let all_actions_task = self.request_multiple_lsp_locally( &buffer_handle, Some(range.start), - GetCodeActions::supports_code_actions, GetCodeActions { range: range.clone(), kinds: None, @@ -7431,7 +7424,6 @@ impl Project { &self, buffer: &Model, position: Option

, - server_capabilities_check: fn(&ServerCapabilities) -> bool, request: R, cx: &mut ModelContext<'_, Self>, ) -> Task> @@ -7449,7 +7441,6 @@ impl Project { let scope = position.and_then(|position| snapshot.language_scope_at(position)); let mut response_results = self .language_servers_for_buffer(buffer.read(cx), cx) - .filter(|(_, server)| server_capabilities_check(&server.capabilities())) .filter(|(adapter, _)| { scope .as_ref() @@ -8575,11 +8566,6 @@ impl Project { project.request_multiple_lsp_locally( &buffer, Some(get_hover.position), - |server_capabilities| match server_capabilities.hover_provider { - Some(lsp::HoverProviderCapability::Simple(enabled)) => enabled, - Some(lsp::HoverProviderCapability::Options(_)) => true, - None => false, - }, get_hover, cx, ) @@ -8617,7 +8603,6 @@ impl Project { project.request_multiple_lsp_locally( &buffer, Some(get_code_actions.range.start), - GetCodeActions::supports_code_actions, get_code_actions, cx, ) @@ -8655,9 +8640,6 @@ impl Project { project.request_multiple_lsp_locally( &buffer, Some(get_signature_help.position), - |server_capabilities| { - server_capabilities.signature_help_provider.is_some() - }, get_signature_help, cx, )