• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::{imports::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 callable: Option<CallableSnippets>,
18     pub snippet_cap: Option<SnippetCap>,
19     pub insert_use: InsertUseConfig,
20     pub prefer_no_std: bool,
21     pub snippets: Vec<Snippet>,
22     pub limit: Option<usize>,
23 }
24 
25 #[derive(Clone, Debug, PartialEq, Eq)]
26 pub enum CallableSnippets {
27     FillArguments,
28     AddParentheses,
29 }
30 
31 impl CompletionConfig {
postfix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)>32     pub fn postfix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
33         self.snippets
34             .iter()
35             .flat_map(|snip| snip.postfix_triggers.iter().map(move |trigger| (&**trigger, snip)))
36     }
37 
prefix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)>38     pub fn prefix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
39         self.snippets
40             .iter()
41             .flat_map(|snip| snip.prefix_triggers.iter().map(move |trigger| (&**trigger, snip)))
42     }
43 }
44