Auto merge of #13986 - MariaSolOs:limit-completions, r=Veykril

Add setting for limiting number of completions

For #13911.
This commit is contained in:
bors 2023-02-08 09:31:35 +00:00
commit a05ce5a3e7
7 changed files with 28 additions and 1 deletions

View File

@ -19,6 +19,7 @@ pub struct CompletionConfig {
pub insert_use: InsertUseConfig,
pub prefer_no_std: bool,
pub snippets: Vec<Snippet>,
pub limit: Option<usize>,
}
#[derive(Clone, Debug, PartialEq, Eq)]

View File

@ -75,6 +75,7 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
skip_glob_imports: true,
},
snippets: Vec::new(),
limit: None,
};
pub(crate) fn completion_list(ra_fixture: &str) -> String {

View File

@ -200,6 +200,8 @@ config_data! {
completion_autoself_enable: bool = "true",
/// Whether to add parenthesis and argument snippets when completing function.
completion_callable_snippets: CallableCompletionDef = "\"fill_arguments\"",
/// Maximum number of completions to return. If `None`, the limit is infinite.
completion_limit: Option<usize> = "null",
/// Whether to show postfix snippets like `dbg`, `if`, `not`, etc.
completion_postfix_enable: bool = "true",
/// Enables completions of private items and fields that are defined in the current workspace even if they are not visible at the current position.
@ -1343,6 +1345,7 @@ impl Config {
.snippet_support?
)),
snippets: self.snippets.clone(),
limit: self.data.completion_limit,
}
}

View File

@ -146,6 +146,7 @@ fn integrated_completion_benchmark() {
},
snippets: Vec::new(),
prefer_no_std: false,
limit: None,
};
let position =
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };
@ -184,6 +185,7 @@ fn integrated_completion_benchmark() {
},
snippets: Vec::new(),
prefer_no_std: false,
limit: None,
};
let position =
FilePosition { file_id, offset: TextSize::try_from(completion_offset).unwrap() };

View File

@ -215,8 +215,14 @@ pub(crate) fn completion_items(
let max_relevance = items.iter().map(|it| it.relevance().score()).max().unwrap_or_default();
let mut res = Vec::with_capacity(items.len());
for item in items {
completion_item(&mut res, config, line_index, &tdpp, max_relevance, item)
completion_item(&mut res, config, line_index, &tdpp, max_relevance, item);
}
if let Some(limit) = config.completion().limit {
res.sort_by(|item1, item2| item1.sort_text.cmp(&item2.sort_text));
res.truncate(limit);
}
res
}

View File

@ -227,6 +227,11 @@ with `self` prefixed to them when inside a method.
--
Whether to add parenthesis and argument snippets when completing function.
--
[[rust-analyzer.completion.limit]]rust-analyzer.completion.limit (default: `null`)::
+
--
Maximum number of completions to return. If `None`, the limit is infinite.
--
[[rust-analyzer.completion.postfix.enable]]rust-analyzer.completion.postfix.enable (default: `true`)::
+
--

View File

@ -705,6 +705,15 @@
"Do no snippet completions for callables."
]
},
"rust-analyzer.completion.limit": {
"markdownDescription": "Maximum number of completions to return. If `None`, the limit is infinite.",
"default": null,
"type": [
"null",
"integer"
],
"minimum": 0
},
"rust-analyzer.completion.postfix.enable": {
"markdownDescription": "Whether to show postfix snippets like `dbg`, `if`, `not`, etc.",
"default": true,