mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 12:55:11 +00:00
Add simple support for completion item details
This commit is contained in:
parent
ea416175d5
commit
d17a5ef8e1
3 changed files with 38 additions and 11 deletions
|
@ -1,16 +1,16 @@
|
||||||
//! Advertises the capabilities of the LSP Server.
|
//! Advertises the capabilities of the LSP Server.
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
CallHierarchyServerCapability, ClientCapabilities, CodeActionKind, CodeActionOptions,
|
CallHierarchyServerCapability, ClientCapabilities, CodeActionKind, CodeActionOptions,
|
||||||
CodeActionProviderCapability, CodeLensOptions, CompletionOptions, DeclarationCapability,
|
CodeActionProviderCapability, CodeLensOptions, CompletionOptions,
|
||||||
DocumentOnTypeFormattingOptions, FileOperationFilter, FileOperationPattern,
|
CompletionOptionsCompletionItem, DeclarationCapability, DocumentOnTypeFormattingOptions,
|
||||||
FileOperationPatternKind, FileOperationRegistrationOptions, FoldingRangeProviderCapability,
|
FileOperationFilter, FileOperationPattern, FileOperationPatternKind,
|
||||||
HoverProviderCapability, ImplementationProviderCapability, InlayHintOptions,
|
FileOperationRegistrationOptions, FoldingRangeProviderCapability, HoverProviderCapability,
|
||||||
InlayHintServerCapabilities, OneOf, RenameOptions, SaveOptions,
|
ImplementationProviderCapability, InlayHintOptions, InlayHintServerCapabilities, OneOf,
|
||||||
SelectionRangeProviderCapability, SemanticTokensFullOptions, SemanticTokensLegend,
|
RenameOptions, SaveOptions, SelectionRangeProviderCapability, SemanticTokensFullOptions,
|
||||||
SemanticTokensOptions, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability,
|
SemanticTokensLegend, SemanticTokensOptions, ServerCapabilities, SignatureHelpOptions,
|
||||||
TextDocumentSyncKind, TextDocumentSyncOptions, TypeDefinitionProviderCapability,
|
TextDocumentSyncCapability, TextDocumentSyncKind, TextDocumentSyncOptions,
|
||||||
WorkDoneProgressOptions, WorkspaceFileOperationsServerCapabilities,
|
TypeDefinitionProviderCapability, WorkDoneProgressOptions,
|
||||||
WorkspaceServerCapabilities,
|
WorkspaceFileOperationsServerCapabilities, WorkspaceServerCapabilities,
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
|
||||||
"(".to_string(),
|
"(".to_string(),
|
||||||
]),
|
]),
|
||||||
all_commit_characters: None,
|
all_commit_characters: None,
|
||||||
completion_item: None,
|
completion_item: completion_item(&config),
|
||||||
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
|
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
|
||||||
}),
|
}),
|
||||||
signature_help_provider: Some(SignatureHelpOptions {
|
signature_help_provider: Some(SignatureHelpOptions {
|
||||||
|
@ -170,6 +170,12 @@ pub(crate) fn completion_item_edit_resolve(caps: &ClientCapabilities) -> bool {
|
||||||
})() == Some(true)
|
})() == 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 {
|
fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProviderCapability {
|
||||||
client_caps
|
client_caps
|
||||||
.text_document
|
.text_document
|
||||||
|
|
|
@ -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 {
|
pub fn offset_encoding(&self) -> OffsetEncoding {
|
||||||
if supports_utf8(&self.caps) {
|
if supports_utf8(&self.caps) {
|
||||||
OffsetEncoding::Utf8
|
OffsetEncoding::Utf8
|
||||||
|
|
|
@ -277,6 +277,13 @@ fn completion_item(
|
||||||
..Default::default()
|
..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());
|
set_score(&mut lsp_item, max_relevance, item.relevance());
|
||||||
|
|
||||||
if config.completion().enable_imports_on_the_fly {
|
if config.completion().enable_imports_on_the_fly {
|
||||||
|
|
Loading…
Reference in a new issue