diff options
author | Philipp Mildenberger | 2023-04-05 16:07:41 +0000 |
---|---|---|
committer | Philipp Mildenberger | 2023-05-18 19:58:17 +0000 |
commit | 56748509bdb6cb16006ccc06eb15a7ee09028afc (patch) | |
tree | 402925930ea3425017d129bad7ead9917f24aaa0 /helix-lsp/src | |
parent | 3e4bac1d964cc29939b396a7e1e9ebd7feda5e0a (diff) |
Reduce boilerplate by 'use lsp::*' in Client::supports_feature, and remove TODO comment
Diffstat (limited to 'helix-lsp/src')
-rw-r--r-- | helix-lsp/src/client.rs | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index b1a73247..a3711317 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -276,65 +276,62 @@ impl Client { .expect("language server not yet initialized!") } - #[inline] // TODO inline? + /// Client has to be initialized otherwise this function panics + #[inline] pub fn supports_feature(&self, feature: LanguageServerFeature) -> bool { - let capabilities = match self.capabilities.get() { - Some(capabilities) => capabilities, - None => return false, // not initialized, TODO unwrap/expect instead? - }; + let capabilities = self.capabilities(); + + use lsp::*; match feature { LanguageServerFeature::Format => matches!( capabilities.document_formatting_provider, - Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) + Some(OneOf::Left(true) | OneOf::Right(_)) ), LanguageServerFeature::GotoDeclaration => matches!( capabilities.declaration_provider, Some( - lsp::DeclarationCapability::Simple(true) - | lsp::DeclarationCapability::RegistrationOptions(_) - | lsp::DeclarationCapability::Options(_), + DeclarationCapability::Simple(true) + | DeclarationCapability::RegistrationOptions(_) + | DeclarationCapability::Options(_), ) ), LanguageServerFeature::GotoDefinition => matches!( capabilities.definition_provider, - Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) + Some(OneOf::Left(true) | OneOf::Right(_)) ), LanguageServerFeature::GotoTypeDefinition => matches!( capabilities.type_definition_provider, Some( - lsp::TypeDefinitionProviderCapability::Simple(true) - | lsp::TypeDefinitionProviderCapability::Options(_), + TypeDefinitionProviderCapability::Simple(true) + | TypeDefinitionProviderCapability::Options(_), ) ), LanguageServerFeature::GotoReference => matches!( capabilities.references_provider, - Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) + Some(OneOf::Left(true) | OneOf::Right(_)) ), LanguageServerFeature::GotoImplementation => matches!( capabilities.implementation_provider, Some( - lsp::ImplementationProviderCapability::Simple(true) - | lsp::ImplementationProviderCapability::Options(_), + ImplementationProviderCapability::Simple(true) + | ImplementationProviderCapability::Options(_), ) ), LanguageServerFeature::SignatureHelp => capabilities.signature_help_provider.is_some(), LanguageServerFeature::Hover => matches!( capabilities.hover_provider, - Some( - lsp::HoverProviderCapability::Simple(true) - | lsp::HoverProviderCapability::Options(_), - ) + Some(HoverProviderCapability::Simple(true) | HoverProviderCapability::Options(_),) ), LanguageServerFeature::DocumentHighlight => matches!( capabilities.document_highlight_provider, - Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) + Some(OneOf::Left(true) | OneOf::Right(_)) ), LanguageServerFeature::Completion => capabilities.completion_provider.is_some(), LanguageServerFeature::CodeAction => matches!( capabilities.code_action_provider, Some( - lsp::CodeActionProviderCapability::Simple(true) - | lsp::CodeActionProviderCapability::Options(_), + CodeActionProviderCapability::Simple(true) + | CodeActionProviderCapability::Options(_), ) ), LanguageServerFeature::WorkspaceCommand => { @@ -342,23 +339,20 @@ impl Client { } LanguageServerFeature::DocumentSymbols => matches!( capabilities.document_symbol_provider, - Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) + Some(OneOf::Left(true) | OneOf::Right(_)) ), LanguageServerFeature::WorkspaceSymbols => matches!( capabilities.workspace_symbol_provider, - Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_)) + Some(OneOf::Left(true) | OneOf::Right(_)) ), LanguageServerFeature::Diagnostics => true, // there's no extra server capability LanguageServerFeature::RenameSymbol => matches!( capabilities.rename_provider, - Some(lsp::OneOf::Left(true)) | Some(lsp::OneOf::Right(_)) + Some(OneOf::Left(true)) | Some(OneOf::Right(_)) ), LanguageServerFeature::InlayHints => matches!( capabilities.inlay_hint_provider, - Some( - lsp::OneOf::Left(true) - | lsp::OneOf::Right(lsp::InlayHintServerCapabilities::Options(_)) - ) + Some(OneOf::Left(true) | OneOf::Right(InlayHintServerCapabilities::Options(_))) ), } } |