Provide an option to hide deprecated items from completion

This commit is contained in:
Chayim Refael Friedman 2024-09-01 01:04:21 +03:00
parent 914a1caab5
commit 01cc847158
4 changed files with 26 additions and 1 deletions

View file

@ -429,6 +429,8 @@ config_data! {
completion_callable_snippets: CallableCompletionDef = CallableCompletionDef::FillArguments, completion_callable_snippets: CallableCompletionDef = CallableCompletionDef::FillArguments,
/// Whether to show full function/method signatures in completion docs. /// Whether to show full function/method signatures in completion docs.
completion_fullFunctionSignatures_enable: bool = false, completion_fullFunctionSignatures_enable: bool = false,
/// Whether to omit deprecated items from autocompletion. By default they are marked as deprecated but not hidden.
completion_hideDeprecated: bool = false,
/// Maximum number of completions to return. If `None`, the limit is infinite. /// Maximum number of completions to return. If `None`, the limit is infinite.
completion_limit: Option<usize> = None, completion_limit: Option<usize> = None,
/// Whether to show postfix snippets like `dbg`, `if`, `not`, etc. /// Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
@ -1443,6 +1445,10 @@ impl Config {
} }
} }
pub fn completion_hide_deprecated(&self) -> bool {
*self.completion_hideDeprecated(None)
}
pub fn detached_files(&self) -> &Vec<AbsPathBuf> { pub fn detached_files(&self) -> &Vec<AbsPathBuf> {
// FIXME @alibektas : This is the only config that is confusing. If it's a proper configuration // FIXME @alibektas : This is the only config that is confusing. If it's a proper configuration
// why is it not among the others? If it's client only which I doubt it is current state should be alright // why is it not among the others? If it's client only which I doubt it is current state should be alright

View file

@ -228,8 +228,12 @@ pub(crate) fn completion_items(
line_index: &LineIndex, line_index: &LineIndex,
version: Option<i32>, version: Option<i32>,
tdpp: lsp_types::TextDocumentPositionParams, tdpp: lsp_types::TextDocumentPositionParams,
items: Vec<CompletionItem>, mut items: Vec<CompletionItem>,
) -> Vec<lsp_types::CompletionItem> { ) -> Vec<lsp_types::CompletionItem> {
if config.completion_hide_deprecated() {
items.retain(|item| !item.deprecated);
}
let max_relevance = items.iter().map(|it| it.relevance.score()).max().unwrap_or_default(); let max_relevance = items.iter().map(|it| it.relevance.score()).max().unwrap_or_default();
let mut res = Vec::with_capacity(items.len()); let mut res = Vec::with_capacity(items.len());
for item in items { for item in items {

View file

@ -283,6 +283,11 @@ Whether to add parenthesis and argument snippets when completing function.
-- --
Whether to show full function/method signatures in completion docs. Whether to show full function/method signatures in completion docs.
-- --
[[rust-analyzer.completion.hideDeprecated]]rust-analyzer.completion.hideDeprecated (default: `false`)::
+
--
Whether to omit deprecated items from autocompletion. By default they are marked as deprecated but not hidden.
--
[[rust-analyzer.completion.limit]]rust-analyzer.completion.limit (default: `null`):: [[rust-analyzer.completion.limit]]rust-analyzer.completion.limit (default: `null`)::
+ +
-- --

View file

@ -1077,6 +1077,16 @@
} }
} }
}, },
{
"title": "completion",
"properties": {
"rust-analyzer.completion.hideDeprecated": {
"markdownDescription": "Whether to omit deprecated items from autocompletion. By default they are marked as deprecated but not hidden.",
"default": false,
"type": "boolean"
}
}
},
{ {
"title": "completion", "title": "completion",
"properties": { "properties": {