aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db
diff options
context:
space:
mode:
authorLukas Tobias Wirth <[email protected]>2021-05-18 19:21:47 +0100
committerLukas Tobias Wirth <[email protected]>2021-05-18 19:21:47 +0100
commit5fd9f6c7b9944638e4781e3d9384638942f84456 (patch)
treeef5a6e2d081e69581fb72b31a1523072c30e7770 /crates/ide_db
parentb8a99692d12189406cad7215530fb5103e6c4b5d (diff)
Add ImportGranularity::Guess
Diffstat (limited to 'crates/ide_db')
-rw-r--r--crates/ide_db/src/helpers/insert_use.rs16
1 files changed, 4 insertions, 12 deletions
diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs
index 4852121a1..1fdd110cc 100644
--- a/crates/ide_db/src/helpers/insert_use.rs
+++ b/crates/ide_db/src/helpers/insert_use.rs
@@ -18,6 +18,8 @@ pub use hir::PrefixKind;
18/// How imports should be grouped into use statements. 18/// How imports should be grouped into use statements.
19#[derive(Copy, Clone, Debug, PartialEq, Eq)] 19#[derive(Copy, Clone, Debug, PartialEq, Eq)]
20pub enum ImportGranularity { 20pub enum ImportGranularity {
21 /// Try to guess the granularity of imports on a per module basis by observing the existing imports.
22 Guess,
21 /// Do not change the granularity of any imports and preserve the original structure written by the developer. 23 /// Do not change the granularity of any imports and preserve the original structure written by the developer.
22 Preserve, 24 Preserve,
23 /// Merge imports from the same crate into a single use statement. 25 /// Merge imports from the same crate into a single use statement.
@@ -28,16 +30,6 @@ pub enum ImportGranularity {
28 Item, 30 Item,
29} 31}
30 32
31impl ImportGranularity {
32 pub fn merge_behavior(self) -> Option<MergeBehavior> {
33 match self {
34 ImportGranularity::Crate => Some(MergeBehavior::Crate),
35 ImportGranularity::Module => Some(MergeBehavior::Module),
36 ImportGranularity::Preserve | ImportGranularity::Item => None,
37 }
38 }
39}
40
41#[derive(Clone, Copy, Debug, PartialEq, Eq)] 33#[derive(Clone, Copy, Debug, PartialEq, Eq)]
42pub struct InsertUseConfig { 34pub struct InsertUseConfig {
43 pub granularity: ImportGranularity, 35 pub granularity: ImportGranularity,
@@ -118,10 +110,10 @@ impl ImportScope {
118pub fn insert_use<'a>(scope: &ImportScope, path: ast::Path, cfg: InsertUseConfig) { 110pub fn insert_use<'a>(scope: &ImportScope, path: ast::Path, cfg: InsertUseConfig) {
119 let _p = profile::span("insert_use"); 111 let _p = profile::span("insert_use");
120 let mb = match cfg.granularity { 112 let mb = match cfg.granularity {
121 ImportGranularity::Preserve => scope.guess_merge_behavior_from_scope(), 113 ImportGranularity::Guess => scope.guess_merge_behavior_from_scope(),
122 ImportGranularity::Crate => Some(MergeBehavior::Crate), 114 ImportGranularity::Crate => Some(MergeBehavior::Crate),
123 ImportGranularity::Module => Some(MergeBehavior::Module), 115 ImportGranularity::Module => Some(MergeBehavior::Module),
124 ImportGranularity::Item => None, 116 ImportGranularity::Item | ImportGranularity::Preserve => None,
125 }; 117 };
126 118
127 let use_item = 119 let use_item =