Skip to main content

ide_assists/
assist_config.rs

1//! Settings for tweaking assists.
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//! assists if we are allowed to.
6
7use hir::FindPathConfig;
8use ide_db::{
9    SnippetCap,
10    assists::ExprFillDefaultMode,
11    imports::{import_assets::ImportPathConfig, insert_use::InsertUseConfig},
12    rename::RenameConfig,
13};
14
15use crate::AssistKind;
16
17#[derive(Clone, Debug, PartialEq, Eq)]
18pub struct AssistConfig {
19    pub snippet_cap: Option<SnippetCap>,
20    pub allowed: Option<Vec<AssistKind>>,
21    pub insert_use: InsertUseConfig,
22    pub prefer_no_std: bool,
23    pub prefer_prelude: bool,
24    pub prefer_absolute: bool,
25    pub assist_emit_must_use: bool,
26    pub term_search_fuel: u64,
27    pub code_action_grouping: bool,
28    pub expr_fill_default: ExprFillDefaultMode,
29    pub prefer_self_ty: bool,
30    pub show_rename_conflicts: bool,
31}
32
33impl AssistConfig {
34    pub fn import_path_config(&self) -> ImportPathConfig {
35        ImportPathConfig {
36            prefer_no_std: self.prefer_no_std,
37            prefer_prelude: self.prefer_prelude,
38            prefer_absolute: self.prefer_absolute,
39        }
40    }
41
42    pub fn find_path_config(&self, allow_unstable: bool) -> FindPathConfig {
43        FindPathConfig {
44            prefer_no_std: self.prefer_no_std,
45            prefer_prelude: self.prefer_prelude,
46            prefer_absolute: self.prefer_absolute,
47            allow_unstable,
48        }
49    }
50
51    pub fn rename_config(&self) -> RenameConfig {
52        RenameConfig { show_conflicts: self.show_rename_conflicts }
53    }
54}