Reduce boilerplate by 'use lsp::*' in Client::supports_feature, and remove TODO comment
This commit is contained in:
parent
3e4bac1d96
commit
56748509bd
1 changed files with 23 additions and 29 deletions
|
@ -276,65 +276,62 @@ impl Client {
|
||||||
.expect("language server not yet initialized!")
|
.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 {
|
pub fn supports_feature(&self, feature: LanguageServerFeature) -> bool {
|
||||||
let capabilities = match self.capabilities.get() {
|
let capabilities = self.capabilities();
|
||||||
Some(capabilities) => capabilities,
|
|
||||||
None => return false, // not initialized, TODO unwrap/expect instead?
|
use lsp::*;
|
||||||
};
|
|
||||||
match feature {
|
match feature {
|
||||||
LanguageServerFeature::Format => matches!(
|
LanguageServerFeature::Format => matches!(
|
||||||
capabilities.document_formatting_provider,
|
capabilities.document_formatting_provider,
|
||||||
Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_))
|
Some(OneOf::Left(true) | OneOf::Right(_))
|
||||||
),
|
),
|
||||||
LanguageServerFeature::GotoDeclaration => matches!(
|
LanguageServerFeature::GotoDeclaration => matches!(
|
||||||
capabilities.declaration_provider,
|
capabilities.declaration_provider,
|
||||||
Some(
|
Some(
|
||||||
lsp::DeclarationCapability::Simple(true)
|
DeclarationCapability::Simple(true)
|
||||||
| lsp::DeclarationCapability::RegistrationOptions(_)
|
| DeclarationCapability::RegistrationOptions(_)
|
||||||
| lsp::DeclarationCapability::Options(_),
|
| DeclarationCapability::Options(_),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
LanguageServerFeature::GotoDefinition => matches!(
|
LanguageServerFeature::GotoDefinition => matches!(
|
||||||
capabilities.definition_provider,
|
capabilities.definition_provider,
|
||||||
Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_))
|
Some(OneOf::Left(true) | OneOf::Right(_))
|
||||||
),
|
),
|
||||||
LanguageServerFeature::GotoTypeDefinition => matches!(
|
LanguageServerFeature::GotoTypeDefinition => matches!(
|
||||||
capabilities.type_definition_provider,
|
capabilities.type_definition_provider,
|
||||||
Some(
|
Some(
|
||||||
lsp::TypeDefinitionProviderCapability::Simple(true)
|
TypeDefinitionProviderCapability::Simple(true)
|
||||||
| lsp::TypeDefinitionProviderCapability::Options(_),
|
| TypeDefinitionProviderCapability::Options(_),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
LanguageServerFeature::GotoReference => matches!(
|
LanguageServerFeature::GotoReference => matches!(
|
||||||
capabilities.references_provider,
|
capabilities.references_provider,
|
||||||
Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_))
|
Some(OneOf::Left(true) | OneOf::Right(_))
|
||||||
),
|
),
|
||||||
LanguageServerFeature::GotoImplementation => matches!(
|
LanguageServerFeature::GotoImplementation => matches!(
|
||||||
capabilities.implementation_provider,
|
capabilities.implementation_provider,
|
||||||
Some(
|
Some(
|
||||||
lsp::ImplementationProviderCapability::Simple(true)
|
ImplementationProviderCapability::Simple(true)
|
||||||
| lsp::ImplementationProviderCapability::Options(_),
|
| ImplementationProviderCapability::Options(_),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
LanguageServerFeature::SignatureHelp => capabilities.signature_help_provider.is_some(),
|
LanguageServerFeature::SignatureHelp => capabilities.signature_help_provider.is_some(),
|
||||||
LanguageServerFeature::Hover => matches!(
|
LanguageServerFeature::Hover => matches!(
|
||||||
capabilities.hover_provider,
|
capabilities.hover_provider,
|
||||||
Some(
|
Some(HoverProviderCapability::Simple(true) | HoverProviderCapability::Options(_),)
|
||||||
lsp::HoverProviderCapability::Simple(true)
|
|
||||||
| lsp::HoverProviderCapability::Options(_),
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
LanguageServerFeature::DocumentHighlight => matches!(
|
LanguageServerFeature::DocumentHighlight => matches!(
|
||||||
capabilities.document_highlight_provider,
|
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::Completion => capabilities.completion_provider.is_some(),
|
||||||
LanguageServerFeature::CodeAction => matches!(
|
LanguageServerFeature::CodeAction => matches!(
|
||||||
capabilities.code_action_provider,
|
capabilities.code_action_provider,
|
||||||
Some(
|
Some(
|
||||||
lsp::CodeActionProviderCapability::Simple(true)
|
CodeActionProviderCapability::Simple(true)
|
||||||
| lsp::CodeActionProviderCapability::Options(_),
|
| CodeActionProviderCapability::Options(_),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
LanguageServerFeature::WorkspaceCommand => {
|
LanguageServerFeature::WorkspaceCommand => {
|
||||||
|
@ -342,23 +339,20 @@ impl Client {
|
||||||
}
|
}
|
||||||
LanguageServerFeature::DocumentSymbols => matches!(
|
LanguageServerFeature::DocumentSymbols => matches!(
|
||||||
capabilities.document_symbol_provider,
|
capabilities.document_symbol_provider,
|
||||||
Some(lsp::OneOf::Left(true) | lsp::OneOf::Right(_))
|
Some(OneOf::Left(true) | OneOf::Right(_))
|
||||||
),
|
),
|
||||||
LanguageServerFeature::WorkspaceSymbols => matches!(
|
LanguageServerFeature::WorkspaceSymbols => matches!(
|
||||||
capabilities.workspace_symbol_provider,
|
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::Diagnostics => true, // there's no extra server capability
|
||||||
LanguageServerFeature::RenameSymbol => matches!(
|
LanguageServerFeature::RenameSymbol => matches!(
|
||||||
capabilities.rename_provider,
|
capabilities.rename_provider,
|
||||||
Some(lsp::OneOf::Left(true)) | Some(lsp::OneOf::Right(_))
|
Some(OneOf::Left(true)) | Some(OneOf::Right(_))
|
||||||
),
|
),
|
||||||
LanguageServerFeature::InlayHints => matches!(
|
LanguageServerFeature::InlayHints => matches!(
|
||||||
capabilities.inlay_hint_provider,
|
capabilities.inlay_hint_provider,
|
||||||
Some(
|
Some(OneOf::Left(true) | OneOf::Right(InlayHintServerCapabilities::Options(_)))
|
||||||
lsp::OneOf::Left(true)
|
|
||||||
| lsp::OneOf::Right(lsp::InlayHintServerCapabilities::Options(_))
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue