Skip to content

Commit

Permalink
Auto merge of rust-lang#12807 - Veykril:completion-item-details, r=Ve…
Browse files Browse the repository at this point in the history
…ykril

Add simple support for completion item details

Supercedes rust-lang/rust-analyzer#9891

This doesn't yet really implement anything new, it just adds the scaffolding for the protocol conversion
  • Loading branch information
bors committed Jul 18, 2022
2 parents 530eb27 + d17a5ef commit dc05192
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
28 changes: 17 additions & 11 deletions crates/rust-analyzer/src/caps.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions crates/rust-analyzer/src/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit dc05192

Please sign in to comment.