Skip to content

Commit f90a8db

Browse files
Provide an option to hide deprecated items from completion
1 parent 0ae42bd commit f90a8db

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ config_data! {
512512
completion_termSearch_enable: bool = false,
513513
/// Term search fuel in "units of work" for autocompletion (Defaults to 1000).
514514
completion_termSearch_fuel: usize = 1000,
515+
/// Whether to omit deprecated items from autocompletion. By default they are marked as deprecated but not hidden.
516+
completions_hideDeprecated: bool = false,
515517

516518
/// Controls file watching implementation.
517519
files_watcher: FilesWatcherDef = FilesWatcherDef::Client,
@@ -1435,6 +1437,10 @@ impl Config {
14351437
}
14361438
}
14371439

1440+
pub fn completion_hide_deprecated(&self) -> bool {
1441+
*self.completions_hideDeprecated()
1442+
}
1443+
14381444
pub fn detached_files(&self) -> &Vec<AbsPathBuf> {
14391445
// FIXME @alibektas : This is the only config that is confusing. If it's a proper configuration
14401446
// why is it not among the others? If it's client only which I doubt it is current state should be alright

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 {

docs/user/generated_config.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ Whether to enable term search based snippets like `Some(foo.bar().baz())`.
358358
--
359359
Term search fuel in "units of work" for autocompletion (Defaults to 1000).
360360
--
361+
[[rust-analyzer.completions.hideDeprecated]]rust-analyzer.completions.hideDeprecated (default: `false`)::
362+
+
363+
--
364+
Whether to omit deprecated items from autocompletion. By default they are marked as deprecated but not hidden.
365+
--
361366
[[rust-analyzer.diagnostics.disabled]]rust-analyzer.diagnostics.disabled (default: `[]`)::
362367
+
363368
--

editors/code/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,16 @@
11821182
}
11831183
}
11841184
},
1185+
{
1186+
"title": "completions",
1187+
"properties": {
1188+
"rust-analyzer.completions.hideDeprecated": {
1189+
"markdownDescription": "Whether to omit deprecated items from autocompletion. By default they are marked as deprecated but not hidden.",
1190+
"default": false,
1191+
"type": "boolean"
1192+
}
1193+
}
1194+
},
11851195
{
11861196
"title": "diagnostics",
11871197
"properties": {

0 commit comments

Comments
 (0)