Add simple support for completion item details

This commit is contained in:
Lukas Wirth 2022-07-18 19:25:43 +02:00
parent ea416175d5
commit d17a5ef8e1
3 changed files with 38 additions and 11 deletions

View file

@ -1,16 +1,16 @@
//! Advertises the capabilities of the LSP Server.
use lsp_types::{
CallHierarchyServerCapability, ClientCapabilities, CodeActionKind, CodeActionOptions,
CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DeclarationCapability,
DocumentOnTypeFormattingOptions, FileOperationFilter, FileOperationPattern,
FileOperationPatternKind, FileOperationRegistrationOptions, FoldingRangeProviderCapability,
HoverProviderCapability, ImplementationProviderCapability, InlayHintOptions,
InlayHintServerCapabilities, OneOf, RenameOptions, SaveOptions,
SelectionRangeProviderCapability, SemanticTokensFullOptions, SemanticTokensLegend,
SemanticTokensOptions, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability,
TextDocumentSyncKind, TextDocumentSyncOptions, TypeDefinitionProviderCapability,
WorkDoneProgressOptions, WorkspaceFileOperationsServerCapabilities,
WorkspaceServerCapabilities,
CodeActionProviderCapability, CodeLensOptions, CompletionOptions,
CompletionOptionsCompletionItem, DeclarationCapability, DocumentOnTypeFormattingOptions,
FileOperationFilter, FileOperationPattern, FileOperationPatternKind,
FileOperationRegistrationOptions, FoldingRangeProviderCapability, HoverProviderCapability,
ImplementationProviderCapability, InlayHintOptions, InlayHintServerCapabilities, OneOf,
RenameOptions, SaveOptions, SelectionRangeProviderCapability, SemanticTokensFullOptions,
SemanticTokensLegend, SemanticTokensOptions, ServerCapabilities, SignatureHelpOptions,
TextDocumentSyncCapability, TextDocumentSyncKind, TextDocumentSyncOptions,
TypeDefinitionProviderCapability, WorkDoneProgressOptions,
WorkspaceFileOperationsServerCapabilities, WorkspaceServerCapabilities,
};
use serde_json::json;
@ -36,7 +36,7 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
"(".to_string(),
]),
all_commit_characters: None,
completion_item: None,
completion_item: completion_item(&config),
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
}),
signature_help_provider: Some(SignatureHelpOptions {
@ -170,6 +170,12 @@ pub(crate) fn completion_item_edit_resolve(caps: &ClientCapabilities) -> bool {
})() == Some(true)
}
fn completion_item(config: &Config) -> Option<CompletionOptionsCompletionItem> {
Some(CompletionOptionsCompletionItem {
label_details_support: Some(config.completion_label_details_support()),
})
}
fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProviderCapability {
client_caps
.text_document

View file

@ -833,6 +833,20 @@ impl Config {
)
}
pub fn completion_label_details_support(&self) -> bool {
try_!(self
.caps
.text_document
.as_ref()?
.completion
.as_ref()?
.completion_item
.as_ref()?
.label_details_support
.as_ref()?)
.is_some()
}
pub fn offset_encoding(&self) -> OffsetEncoding {
if supports_utf8(&self.caps) {
OffsetEncoding::Utf8

View file

@ -277,6 +277,13 @@ fn completion_item(
..Default::default()
};
if config.completion_label_details_support() {
lsp_item.label_details = Some(lsp_types::CompletionItemLabelDetails {
detail: None,
description: lsp_item.detail.clone(),
});
}
set_score(&mut lsp_item, max_relevance, item.relevance());
if config.completion().enable_imports_on_the_fly {