rust-analyzer/crates/ide-completion/src/config.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

60 lines
1.9 KiB
Rust
Raw Normal View History

2020-04-24 00:06:12 +00: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.
use hir::ImportPathConfig;
2022-03-06 18:01:30 +00:00
use ide_db::{imports::insert_use::InsertUseConfig, SnippetCap};
2021-10-04 17:22:41 +00:00
use crate::{snippet::Snippet, CompletionFieldsToResolve};
2020-11-10 21:40:07 +00:00
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CompletionConfig {
pub enable_postfix_completions: bool,
pub enable_imports_on_the_fly: bool,
2021-05-30 14:41:33 +00:00
pub enable_self_on_the_fly: bool,
pub enable_private_editable: bool,
pub enable_term_search: bool,
2024-05-08 15:03:38 +00:00
pub term_search_fuel: u64,
2023-09-04 01:42:56 +00:00
pub full_function_signatures: bool,
pub callable: Option<CallableSnippets>,
pub add_semicolon_to_unit: bool,
2020-04-24 00:06:12 +00:00
pub snippet_cap: Option<SnippetCap>,
pub insert_use: InsertUseConfig,
pub prefer_no_std: bool,
pub prefer_prelude: bool,
2024-07-01 16:52:34 +00:00
pub prefer_absolute: bool,
2021-10-04 17:22:41 +00:00
pub snippets: Vec<Snippet>,
2023-01-20 02:33:47 +00:00
pub limit: Option<usize>,
pub fields_to_resolve: CompletionFieldsToResolve,
2020-04-24 00:06:12 +00:00
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CallableSnippets {
FillArguments,
AddParentheses,
}
impl CompletionConfig {
pub fn postfix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
2021-10-11 19:49:39 +00:00
self.snippets
.iter()
.flat_map(|snip| snip.postfix_triggers.iter().map(move |trigger| (&**trigger, snip)))
}
2021-10-11 19:49:39 +00:00
pub fn prefix_snippets(&self) -> impl Iterator<Item = (&str, &Snippet)> {
2021-10-11 19:49:39 +00:00
self.snippets
.iter()
.flat_map(|snip| snip.prefix_triggers.iter().map(move |trigger| (&**trigger, snip)))
}
pub fn import_path_config(&self) -> ImportPathConfig {
ImportPathConfig {
prefer_no_std: self.prefer_no_std,
prefer_prelude: self.prefer_prelude,
prefer_absolute: self.prefer_absolute,
}
}
}