aboutsummaryrefslogtreecommitdiff
path: root/crates/assists
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-10-06 12:43:08 +0100
committerGitHub <[email protected]>2020-10-06 12:43:08 +0100
commitaf0e54a566ab8c8be9b39a628aaa4992f161695c (patch)
tree6b12b51c50d64cd5412271101692d9e39282988f /crates/assists
parent69512dae26278f06b5ac96a7b6093abb69cdd040 (diff)
parent86993310143c1347db6308a66c1f31a7a5644f56 (diff)
Merge #6139
6139: Make find_path_prefixed configurable r=matklad a=Veykril This makes `find_path_prefixed` more configurable allowing one to choose whether it always returns absolute paths, self-prefixed paths or to ignore local imports when building the path. The config names are just thrown in here, taking better names if they exist :) This should fix #6131 as well? Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/assists')
-rw-r--r--crates/assists/src/assist_config.rs5
-rw-r--r--crates/assists/src/handlers/auto_import.rs16
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
7use hir::PrefixKind;
8
7use crate::{utils::MergeBehaviour, AssistKind}; 9use 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)]
38pub struct InsertUseConfig { 40pub struct InsertUseConfig {
39 pub merge: Option<MergeBehaviour>, 41 pub merge: Option<MergeBehaviour>,
42 pub prefix_kind: PrefixKind,
40} 43}
41 44
42impl Default for InsertUseConfig { 45impl 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)