From d17a5ef8e1b689854d34e8fd9d7fac355cfcbcd0 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 18 Jul 2022 19:25:43 +0200 Subject: [PATCH] Add simple support for completion item details --- crates/rust-analyzer/src/caps.rs | 28 +++++++++++++++++----------- crates/rust-analyzer/src/config.rs | 14 ++++++++++++++ crates/rust-analyzer/src/to_proto.rs | 7 +++++++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs index 7bff6a8b0e388..cda95cd8626c9 100644 --- a/crates/rust-analyzer/src/caps.rs +++ b/crates/rust-analyzer/src/caps.rs @@ -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 { + Some(CompletionOptionsCompletionItem { + label_details_support: Some(config.completion_label_details_support()), + }) +} + fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProviderCapability { client_caps .text_document diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 87a15432a4f2c..23305b2615b1a 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -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 diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index cdd152ccf566a..9c8e618b6ed05 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -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 {