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
This commit is contained in:
Thorsten Ball 2024-07-18 14:38:27 +02:00 committed by GitHub
parent 80558a3986
commit 76ce1a8f50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 30 deletions

View File

@ -1354,6 +1354,14 @@ impl LspCommand for GetHover {
type LspRequest = lsp::request::HoverRequest; type LspRequest = lsp::request::HoverRequest;
type ProtoRequest = proto::GetHover; 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( fn to_lsp(
&self, &self,
path: &Path, path: &Path,
@ -2062,17 +2070,6 @@ impl GetCodeActions {
}) })
.unwrap_or(false) .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)] #[async_trait(?Send)]

View File

@ -61,7 +61,7 @@ use lsp::{
CompletionContext, DiagnosticSeverity, DiagnosticTag, DidChangeWatchedFilesRegistrationOptions, CompletionContext, DiagnosticSeverity, DiagnosticTag, DidChangeWatchedFilesRegistrationOptions,
DocumentHighlightKind, Edit, FileSystemWatcher, InsertTextFormat, LanguageServer, DocumentHighlightKind, Edit, FileSystemWatcher, InsertTextFormat, LanguageServer,
LanguageServerBinary, LanguageServerId, LspRequestFuture, MessageActionItem, OneOf, LanguageServerBinary, LanguageServerId, LspRequestFuture, MessageActionItem, OneOf,
ServerCapabilities, ServerHealthStatus, ServerStatus, TextEdit, WorkDoneProgressCancelParams, ServerHealthStatus, ServerStatus, TextEdit, WorkDoneProgressCancelParams,
}; };
use lsp_command::*; use lsp_command::*;
use node_runtime::NodeRuntime; use node_runtime::NodeRuntime;
@ -5621,7 +5621,6 @@ impl Project {
let all_actions_task = self.request_multiple_lsp_locally( let all_actions_task = self.request_multiple_lsp_locally(
buffer, buffer,
Some(position), Some(position),
|server_capabilities| server_capabilities.signature_help_provider.is_some(),
GetSignatureHelp { position }, GetSignatureHelp { position },
cx, cx,
); );
@ -5696,11 +5695,6 @@ impl Project {
let all_actions_task = self.request_multiple_lsp_locally( let all_actions_task = self.request_multiple_lsp_locally(
&buffer, &buffer,
Some(position), Some(position),
|server_capabilities| match server_capabilities.hover_provider {
Some(lsp::HoverProviderCapability::Simple(enabled)) => enabled,
Some(lsp::HoverProviderCapability::Options(_)) => true,
None => false,
},
GetHover { position }, GetHover { position },
cx, cx,
); );
@ -6286,7 +6280,6 @@ impl Project {
let all_actions_task = self.request_multiple_lsp_locally( let all_actions_task = self.request_multiple_lsp_locally(
&buffer_handle, &buffer_handle,
Some(range.start), Some(range.start),
GetCodeActions::supports_code_actions,
GetCodeActions { GetCodeActions {
range: range.clone(), range: range.clone(),
kinds: None, kinds: None,
@ -7431,7 +7424,6 @@ impl Project {
&self, &self,
buffer: &Model<Buffer>, buffer: &Model<Buffer>,
position: Option<P>, position: Option<P>,
server_capabilities_check: fn(&ServerCapabilities) -> bool,
request: R, request: R,
cx: &mut ModelContext<'_, Self>, cx: &mut ModelContext<'_, Self>,
) -> Task<Vec<R::Response>> ) -> Task<Vec<R::Response>>
@ -7449,7 +7441,6 @@ impl Project {
let scope = position.and_then(|position| snapshot.language_scope_at(position)); let scope = position.and_then(|position| snapshot.language_scope_at(position));
let mut response_results = self let mut response_results = self
.language_servers_for_buffer(buffer.read(cx), cx) .language_servers_for_buffer(buffer.read(cx), cx)
.filter(|(_, server)| server_capabilities_check(&server.capabilities()))
.filter(|(adapter, _)| { .filter(|(adapter, _)| {
scope scope
.as_ref() .as_ref()
@ -8575,11 +8566,6 @@ impl Project {
project.request_multiple_lsp_locally( project.request_multiple_lsp_locally(
&buffer, &buffer,
Some(get_hover.position), 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, get_hover,
cx, cx,
) )
@ -8617,7 +8603,6 @@ impl Project {
project.request_multiple_lsp_locally( project.request_multiple_lsp_locally(
&buffer, &buffer,
Some(get_code_actions.range.start), Some(get_code_actions.range.start),
GetCodeActions::supports_code_actions,
get_code_actions, get_code_actions,
cx, cx,
) )
@ -8655,9 +8640,6 @@ impl Project {
project.request_multiple_lsp_locally( project.request_multiple_lsp_locally(
&buffer, &buffer,
Some(get_signature_help.position), Some(get_signature_help.position),
|server_capabilities| {
server_capabilities.signature_help_provider.is_some()
},
get_signature_help, get_signature_help,
cx, cx,
) )