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 term_search_borrowck: bool,
28    pub code_action_grouping: bool,
29    pub expr_fill_default: ExprFillDefaultMode,
30    pub prefer_self_ty: bool,
31    pub show_rename_conflicts: bool,
32}
33
34impl AssistConfig {
35    pub fn import_path_config(&self) -> ImportPathConfig {
36        ImportPathConfig {
37            prefer_no_std: self.prefer_no_std,
38            prefer_prelude: self.prefer_prelude,
39            prefer_absolute: self.prefer_absolute,
40        }
41    }
42
43    pub fn find_path_config(&self, allow_unstable: bool) -> FindPathConfig {
44        FindPathConfig {
45            prefer_no_std: self.prefer_no_std,
46            prefer_prelude: self.prefer_prelude,
47            prefer_absolute: self.prefer_absolute,
48            allow_unstable,
49        }
50    }
51
52    pub fn rename_config(&self) -> RenameConfig {
53        RenameConfig { show_conflicts: self.show_rename_conflicts }
54    }
55}