diff options
author | Lukas Wirth <[email protected]> | 2020-10-05 16:41:49 +0100 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-10-05 16:41:49 +0100 |
commit | 86993310143c1347db6308a66c1f31a7a5644f56 (patch) | |
tree | 19154fee7049c1424ee3c043db12b5b6eb335963 /crates/assists | |
parent | 67e71619b95dc674c93bd11fb21b311bfc2fb95a (diff) |
Make ImportPrefix a configuration option
Diffstat (limited to 'crates/assists')
-rw-r--r-- | crates/assists/src/assist_config.rs | 5 | ||||
-rw-r--r-- | crates/assists/src/handlers/auto_import.rs | 16 |
2 files changed, 14 insertions, 7 deletions
diff --git a/crates/assists/src/assist_config.rs b/crates/assists/src/assist_config.rs index adf02edab..b24527ec4 100644 --- a/crates/assists/src/assist_config.rs +++ b/crates/assists/src/assist_config.rs | |||
@@ -4,6 +4,8 @@ | |||
4 | //! module, and we use to statically check that we only produce snippet | 4 | //! module, and we use to statically check that we only produce snippet |
5 | //! assists if we are allowed to. | 5 | //! assists if we are allowed to. |
6 | 6 | ||
7 | use hir::PrefixKind; | ||
8 | |||
7 | use crate::{utils::MergeBehaviour, AssistKind}; | 9 | use crate::{utils::MergeBehaviour, AssistKind}; |
8 | 10 | ||
9 | #[derive(Clone, Debug, PartialEq, Eq)] | 11 | #[derive(Clone, Debug, PartialEq, Eq)] |
@@ -37,10 +39,11 @@ impl Default for AssistConfig { | |||
37 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | 39 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
38 | pub struct InsertUseConfig { | 40 | pub struct InsertUseConfig { |
39 | pub merge: Option<MergeBehaviour>, | 41 | pub merge: Option<MergeBehaviour>, |
42 | pub prefix_kind: PrefixKind, | ||
40 | } | 43 | } |
41 | 44 | ||
42 | impl Default for InsertUseConfig { | 45 | impl Default for InsertUseConfig { |
43 | fn default() -> Self { | 46 | fn default() -> Self { |
44 | InsertUseConfig { merge: Some(MergeBehaviour::Full) } | 47 | InsertUseConfig { merge: Some(MergeBehaviour::Full), prefix_kind: PrefixKind::Plain } |
45 | } | 48 | } |
46 | } | 49 | } |
diff --git a/crates/assists/src/handlers/auto_import.rs b/crates/assists/src/handlers/auto_import.rs index fa524ffd9..357ff6392 100644 --- a/crates/assists/src/handlers/auto_import.rs +++ b/crates/assists/src/handlers/auto_import.rs | |||
@@ -191,12 +191,16 @@ impl AutoImportAssets { | |||
191 | _ => Some(candidate), | 191 | _ => Some(candidate), |
192 | }) | 192 | }) |
193 | .filter_map(|candidate| match candidate { | 193 | .filter_map(|candidate| match candidate { |
194 | Either::Left(module_def) => { | 194 | Either::Left(module_def) => self.module_with_name_to_import.find_use_path_prefixed( |
195 | self.module_with_name_to_import.find_use_path_prefixed(db, module_def) | 195 | db, |
196 | } | 196 | module_def, |
197 | Either::Right(macro_def) => { | 197 | ctx.config.insert_use.prefix_kind, |
198 | self.module_with_name_to_import.find_use_path_prefixed(db, macro_def) | 198 | ), |
199 | } | 199 | Either::Right(macro_def) => self.module_with_name_to_import.find_use_path_prefixed( |
200 | db, | ||
201 | macro_def, | ||
202 | ctx.config.insert_use.prefix_kind, | ||
203 | ), | ||
200 | }) | 204 | }) |
201 | .filter(|use_path| !use_path.segments.is_empty()) | 205 | .filter(|use_path| !use_path.segments.is_empty()) |
202 | .take(20) | 206 | .take(20) |