Skip to content

Commit 20ed8ce

Browse files
committed
Auto merge of rust-lang#18006 - ChayimFriedman2:hide-deprecated, r=Veykril
Provide an option to hide deprecated items from completion Fixes rust-lang#17989. I wonder if this should be instead done in the editor, that will do it in a language-agnostic way. Can't hurt to do it in rust-analyzer, I guess.
2 parents 7b01343 + 8116b62 commit 20ed8ce

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,8 @@ config_data! {
429429
completion_callable_snippets: CallableCompletionDef = CallableCompletionDef::FillArguments,
430430
/// Whether to show full function/method signatures in completion docs.
431431
completion_fullFunctionSignatures_enable: bool = false,
432+
/// Whether to omit deprecated items from autocompletion. By default they are marked as deprecated but not hidden.
433+
completion_hideDeprecated: bool = false,
432434
/// Maximum number of completions to return. If `None`, the limit is infinite.
433435
completion_limit: Option<usize> = None,
434436
/// Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
@@ -1443,6 +1445,10 @@ impl Config {
14431445
}
14441446
}
14451447

1448+
pub fn completion_hide_deprecated(&self) -> bool {
1449+
*self.completion_hideDeprecated(None)
1450+
}
1451+
14461452
pub fn detached_files(&self) -> &Vec<AbsPathBuf> {
14471453
// FIXME @alibektas : This is the only config that is confusing. If it's a proper configuration
14481454
// why is it not among the others? If it's client only which I doubt it is current state should be alright

src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,12 @@ pub(crate) fn completion_items(
228228
line_index: &LineIndex,
229229
version: Option<i32>,
230230
tdpp: lsp_types::TextDocumentPositionParams,
231-
items: Vec<CompletionItem>,
231+
mut items: Vec<CompletionItem>,
232232
) -> Vec<lsp_types::CompletionItem> {
233+
if config.completion_hide_deprecated() {
234+
items.retain(|item| !item.deprecated);
235+
}
236+
233237
let max_relevance = items.iter().map(|it| it.relevance.score()).max().unwrap_or_default();
234238
let mut res = Vec::with_capacity(items.len());
235239
for item in items {

src/tools/rust-analyzer/docs/user/generated_config.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ Whether to add parenthesis and argument snippets when completing function.
283283
--
284284
Whether to show full function/method signatures in completion docs.
285285
--
286+
[[rust-analyzer.completion.hideDeprecated]]rust-analyzer.completion.hideDeprecated (default: `false`)::
287+
+
288+
--
289+
Whether to omit deprecated items from autocompletion. By default they are marked as deprecated but not hidden.
290+
--
286291
[[rust-analyzer.completion.limit]]rust-analyzer.completion.limit (default: `null`)::
287292
+
288293
--

src/tools/rust-analyzer/editors/code/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,16 @@
10771077
}
10781078
}
10791079
},
1080+
{
1081+
"title": "completion",
1082+
"properties": {
1083+
"rust-analyzer.completion.hideDeprecated": {
1084+
"markdownDescription": "Whether to omit deprecated items from autocompletion. By default they are marked as deprecated but not hidden.",
1085+
"default": false,
1086+
"type": "boolean"
1087+
}
1088+
}
1089+
},
10801090
{
10811091
"title": "completion",
10821092
"properties": {

0 commit comments

Comments
 (0)