Skip to content

Completion item details #9891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/ide_completion/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ pub struct CompletionConfig {
pub add_call_argument_snippets: bool,
pub snippet_cap: Option<SnippetCap>,
pub insert_use: InsertUseConfig,
pub label_details: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like this is strictly LSP-specific, and affects only how we convert ide::CompletionItem to lsp_types::CompletionItem. So, this setting should only exist in the rust-analyzer crate.

Copy link
Contributor Author

@kjeremy kjeremy Aug 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure. For instance: if the client supports label details and we have on the fly imports enabled it may make sense to move the (use import::path) out of the label and render it as part of the CompletionItemLabelDetails. We would do something similar for (as Trait)

}
1 change: 1 addition & 0 deletions crates/ide_completion/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
group: true,
skip_glob_imports: true,
},
label_details: false,
};

pub(crate) fn completion_list(code: &str) -> String {
Expand Down
3 changes: 2 additions & 1 deletion crates/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ env_logger = { version = "0.9", default-features = false }
itertools = "0.10.0"
jod-thread = "0.1.0"
log = "0.4.8"
lsp-types = { version = "0.89.0", features = ["proposed"] }
#lsp-types = { version = "0.89.0", features = ["proposed"] }
lsp-types = { git = "https://github.com/kjeremy/languageserver-types", branch = "completion-item-label-details", features = ["proposed"] }
parking_lot = "0.11.0"
xflags = "0.2.1"
oorandom = "11.1.2"
Expand Down
24 changes: 19 additions & 5 deletions crates/rust-analyzer/src/caps.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! 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, OneOf, RenameOptions, SaveOptions,
CodeActionProviderCapability, CodeLensOptions, CompletionOptions,
CompletionOptionsCompletionItem, DeclarationCapability, DocumentOnTypeFormattingOptions,
FileOperationFilter, FileOperationPattern, FileOperationPatternKind,
FileOperationRegistrationOptions, FoldingRangeProviderCapability, HoverProviderCapability,
ImplementationProviderCapability, OneOf, RenameOptions, SaveOptions,
SelectionRangeProviderCapability, SemanticTokensFullOptions, SemanticTokensLegend,
SemanticTokensOptions, ServerCapabilities, SignatureHelpOptions, TextDocumentSyncCapability,
TextDocumentSyncKind, TextDocumentSyncOptions, TypeDefinitionProviderCapability,
Expand All @@ -30,7 +31,7 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
resolve_provider: completions_resolve_provider(&config.caps),
trigger_characters: Some(vec![":".to_string(), ".".to_string(), "'".to_string()]),
all_commit_characters: None,
completion_item: None,
completion_item: completion_item(&config.caps),
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
}),
signature_help_provider: Some(SignatureHelpOptions {
Expand Down Expand Up @@ -127,6 +128,19 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
}
}

pub(crate) fn completion_item(
caps: &ClientCapabilities,
) -> Option<CompletionOptionsCompletionItem> {
let label_details_support = caps
.text_document
.as_ref()
.and_then(|it| it.completion.as_ref())
.and_then(|it| it.completion_item.as_ref())
.and_then(|it| it.label_details_support)?;

Some(CompletionOptionsCompletionItem { label_details_support: Some(label_details_support) })
}

fn completions_resolve_provider(client_caps: &ClientCapabilities) -> Option<bool> {
if completion_item_edit_resolve(client_caps) {
Some(true)
Expand Down
6 changes: 5 additions & 1 deletion crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use serde::{de::DeserializeOwned, Deserialize};
use vfs::AbsPathBuf;

use crate::{
caps::completion_item_edit_resolve,
caps::{completion_item, completion_item_edit_resolve},
diagnostics::DiagnosticsMapConfig,
line_index::OffsetEncoding,
lsp_ext::supports_utf8,
Expand Down Expand Up @@ -772,6 +772,10 @@ impl Config {
.snippet_support?,
false
)),
label_details: match completion_item(&self.caps) {
Some(it) => it.label_details_support.unwrap_or(false),
_ => false,
},
}
}
pub fn assist(&self) -> AssistConfig {
Expand Down
2 changes: 2 additions & 0 deletions crates/rust-analyzer/src/integrated_benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ fn integrated_completion_benchmark() {
group: true,
skip_glob_imports: true,
},
label_details: false,
};
let position =
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
Expand Down Expand Up @@ -180,6 +181,7 @@ fn integrated_completion_benchmark() {
group: true,
skip_glob_imports: true,
},
label_details: false,
};
let position =
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
Expand Down
6 changes: 6 additions & 0 deletions crates/rust-analyzer/src/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use ide::{
SourceChange, StructureNodeKind, SymbolKind, TextEdit, TextRange, TextSize,
};
use itertools::Itertools;
use lsp_types::CompletionItemLabelDetails;
use serde_json::to_value;
use vfs::AbsPath;

Expand Down Expand Up @@ -254,6 +255,11 @@ fn completion_item(
..Default::default()
};

if config.completion().label_details {
lsp_item.label_details =
Some(CompletionItemLabelDetails { detail: None, description: lsp_item.detail.clone() });
}

set_score(&mut lsp_item, max_relevance, item.relevance());

if item.deprecated() {
Expand Down
64 changes: 32 additions & 32 deletions editors/code/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"https-proxy-agent": "^5.0.0",
"node-fetch": "^2.6.1",
"vscode-languageclient": "^7.1.0-next.5",
"vscode-languageclient": "^8.0.0-next.2",
"d3": "^7.0.0",
"d3-graphviz": "^4.0.0"
},
Expand Down