]> git.lizzy.rs Git - rust.git/blob - crates/ide_completion/src/config.rs
feat: Make private editable completions configurable, disable by default
[rust.git] / crates / ide_completion / src / config.rs
1 //! Settings for tweaking completion.
2 //!
3 //! The fun thing here is `SnippetCap` -- this type can only be created in this
4 //! module, and we use to statically check that we only produce snippet
5 //! completions if we are allowed to.
6
7 use ide_db::helpers::{insert_use::InsertUseConfig, SnippetCap};
8
9 use crate::snippet::Snippet;
10
11 #[derive(Clone, Debug, PartialEq, Eq)]
12 pub struct CompletionConfig {
13     pub enable_postfix_completions: bool,
14     pub enable_imports_on_the_fly: bool,
15     pub enable_self_on_the_fly: bool,
16     pub enable_private_editable: bool,
17     pub add_call_parenthesis: bool,
18     pub add_call_argument_snippets: bool,
19     pub snippet_cap: Option<SnippetCap>,
20     pub insert_use: InsertUseConfig,
21     pub snippets: Vec<Snippet>,
22 }
23
24 impl CompletionConfig {
25     pub fn postfix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
26         self.snippets
27             .iter()
28             .flat_map(|snip| snip.postfix_triggers.iter().map(move |trigger| (&**trigger, snip)))
29     }
30
31     pub fn prefix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
32         self.snippets
33             .iter()
34             .flat_map(|snip| snip.prefix_triggers.iter().map(move |trigger| (&**trigger, snip)))
35     }
36 }