Bring the implementation closer to VSCode snippet definitions

This commit is contained in:
Lukas Wirth 2021-10-05 17:18:40 +02:00
parent 2b17da60db
commit 77cbf4adbc
9 changed files with 163 additions and 182 deletions

View file

@ -6,7 +6,7 @@
use ide_db::helpers::{insert_use::InsertUseConfig, SnippetCap};
use crate::snippet::{PostfixSnippet, Snippet};
use crate::snippet::Snippet;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CompletionConfig {
@ -17,6 +17,18 @@ pub struct CompletionConfig {
pub add_call_argument_snippets: bool,
pub snippet_cap: Option<SnippetCap>,
pub insert_use: InsertUseConfig,
pub postfix_snippets: Vec<PostfixSnippet>,
pub snippets: Vec<Snippet>,
}
impl CompletionConfig {
pub fn postfix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
self.snippets.iter().flat_map(|snip| {
snip.postfix_triggers.iter().map(move |trigger| (trigger.as_str(), snip))
})
}
pub fn prefix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
self.snippets.iter().flat_map(|snip| {
snip.prefix_triggers.iter().map(move |trigger| (trigger.as_str(), snip))
})
}
}