2020-04-23 19:06:12 -05:00
|
|
|
//! Settings for tweaking completion.
|
|
|
|
//!
|
|
|
|
//! The fun thing here is `SnippetCap` -- this type can only be created in this
|
|
|
|
//! module, and we use to statically check that we only produce snippet
|
|
|
|
//! completions if we are allowed to.
|
|
|
|
|
2022-03-06 12:01:30 -06:00
|
|
|
use ide_db::{imports::insert_use::InsertUseConfig, SnippetCap};
|
2021-10-04 12:22:41 -05:00
|
|
|
|
2021-10-05 10:18:40 -05:00
|
|
|
use crate::snippet::Snippet;
|
2020-11-10 15:40:07 -06:00
|
|
|
|
2020-04-23 19:01:23 -05:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub struct CompletionConfig {
|
|
|
|
pub enable_postfix_completions: bool,
|
2021-01-05 02:34:03 -06:00
|
|
|
pub enable_imports_on_the_fly: bool,
|
2021-05-30 09:41:33 -05:00
|
|
|
pub enable_self_on_the_fly: bool,
|
2022-02-23 09:02:54 -06:00
|
|
|
pub enable_private_editable: bool,
|
2024-01-22 12:34:17 -06:00
|
|
|
pub enable_term_search: bool,
|
2023-09-03 20:42:56 -05:00
|
|
|
pub full_function_signatures: bool,
|
2022-05-13 12:52:44 -05:00
|
|
|
pub callable: Option<CallableSnippets>,
|
2020-04-23 19:06:12 -05:00
|
|
|
pub snippet_cap: Option<SnippetCap>,
|
2021-01-16 11:33:36 -06:00
|
|
|
pub insert_use: InsertUseConfig,
|
2022-09-13 08:09:40 -05:00
|
|
|
pub prefer_no_std: bool,
|
2023-11-11 07:52:11 -06:00
|
|
|
pub prefer_prelude: bool,
|
2021-10-04 12:22:41 -05:00
|
|
|
pub snippets: Vec<Snippet>,
|
2023-01-19 20:33:47 -06:00
|
|
|
pub limit: Option<usize>,
|
2020-04-23 19:06:12 -05:00
|
|
|
}
|
2021-10-05 10:18:40 -05:00
|
|
|
|
2022-05-13 12:52:44 -05:00
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
|
|
pub enum CallableSnippets {
|
|
|
|
FillArguments,
|
|
|
|
AddParentheses,
|
|
|
|
}
|
|
|
|
|
2021-10-05 10:18:40 -05:00
|
|
|
impl CompletionConfig {
|
|
|
|
pub fn postfix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
|
2021-10-11 14:49:39 -05:00
|
|
|
self.snippets
|
|
|
|
.iter()
|
|
|
|
.flat_map(|snip| snip.postfix_triggers.iter().map(move |trigger| (&**trigger, snip)))
|
2021-10-05 10:18:40 -05:00
|
|
|
}
|
2021-10-11 14:49:39 -05:00
|
|
|
|
2021-10-05 10:18:40 -05:00
|
|
|
pub fn prefix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
|
2021-10-11 14:49:39 -05:00
|
|
|
self.snippets
|
|
|
|
.iter()
|
|
|
|
.flat_map(|snip| snip.prefix_triggers.iter().map(move |trigger| (&**trigger, snip)))
|
2021-10-05 10:18:40 -05:00
|
|
|
}
|
|
|
|
}
|