Skip to content

Commit af0e54a

Browse files
bors[bot]Veykril
andauthored
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 <lukastw97@gmail.com>
2 parents 69512da + 8699331 commit af0e54a

File tree

7 files changed

+188
-119
lines changed

7 files changed

+188
-119
lines changed

crates/assists/src/assist_config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! module, and we use to statically check that we only produce snippet
55
//! assists if we are allowed to.
66
7+
use hir::PrefixKind;
8+
79
use crate::{utils::MergeBehaviour, AssistKind};
810

911
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -37,10 +39,11 @@ impl Default for AssistConfig {
3739
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3840
pub struct InsertUseConfig {
3941
pub merge: Option<MergeBehaviour>,
42+
pub prefix_kind: PrefixKind,
4043
}
4144

4245
impl Default for InsertUseConfig {
4346
fn default() -> Self {
44-
InsertUseConfig { merge: Some(MergeBehaviour::Full) }
47+
InsertUseConfig { merge: Some(MergeBehaviour::Full), prefix_kind: PrefixKind::Plain }
4548
}
4649
}

crates/assists/src/handlers/auto_import.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,16 @@ impl AutoImportAssets {
191191
_ => Some(candidate),
192192
})
193193
.filter_map(|candidate| match candidate {
194-
Either::Left(module_def) => {
195-
self.module_with_name_to_import.find_use_path_prefixed(db, module_def)
196-
}
197-
Either::Right(macro_def) => {
198-
self.module_with_name_to_import.find_use_path_prefixed(db, macro_def)
199-
}
194+
Either::Left(module_def) => self.module_with_name_to_import.find_use_path_prefixed(
195+
db,
196+
module_def,
197+
ctx.config.insert_use.prefix_kind,
198+
),
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+
),
200204
})
201205
.filter(|use_path| !use_path.segments.is_empty())
202206
.take(20)

crates/hir/src/code_model.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{iter, sync::Arc};
44
use arrayvec::ArrayVec;
55
use base_db::{CrateId, Edition, FileId};
66
use either::Either;
7+
use hir_def::find_path::PrefixKind;
78
use hir_def::{
89
adt::ReprKind,
910
adt::StructKind,
@@ -390,8 +391,9 @@ impl Module {
390391
self,
391392
db: &dyn DefDatabase,
392393
item: impl Into<ItemInNs>,
394+
prefix_kind: PrefixKind,
393395
) -> Option<ModPath> {
394-
hir_def::find_path::find_path_prefixed(db, item.into(), self.into())
396+
hir_def::find_path::find_path_prefixed(db, item.into(), self.into(), prefix_kind)
395397
}
396398
}
397399

crates/hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub use hir_def::{
4848
body::scope::ExprScopes,
4949
builtin_type::BuiltinType,
5050
docs::Documentation,
51+
find_path::PrefixKind,
5152
item_scope::ItemInNs,
5253
nameres::ModuleSource,
5354
path::ModPath,

0 commit comments

Comments
 (0)