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>
This commit is contained in:
bors[bot] 2020-10-06 11:43:08 +00:00 committed by GitHub
commit af0e54a566
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 188 additions and 119 deletions

View file

@ -4,6 +4,8 @@
//! module, and we use to statically check that we only produce snippet
//! assists if we are allowed to.
use hir::PrefixKind;
use crate::{utils::MergeBehaviour, AssistKind};
#[derive(Clone, Debug, PartialEq, Eq)]
@ -37,10 +39,11 @@ impl Default for AssistConfig {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct InsertUseConfig {
pub merge: Option<MergeBehaviour>,
pub prefix_kind: PrefixKind,
}
impl Default for InsertUseConfig {
fn default() -> Self {
InsertUseConfig { merge: Some(MergeBehaviour::Full) }
InsertUseConfig { merge: Some(MergeBehaviour::Full), prefix_kind: PrefixKind::Plain }
}
}

View file

@ -191,12 +191,16 @@ impl AutoImportAssets {
_ => Some(candidate),
})
.filter_map(|candidate| match candidate {
Either::Left(module_def) => {
self.module_with_name_to_import.find_use_path_prefixed(db, module_def)
}
Either::Right(macro_def) => {
self.module_with_name_to_import.find_use_path_prefixed(db, macro_def)
}
Either::Left(module_def) => self.module_with_name_to_import.find_use_path_prefixed(
db,
module_def,
ctx.config.insert_use.prefix_kind,
),
Either::Right(macro_def) => self.module_with_name_to_import.find_use_path_prefixed(
db,
macro_def,
ctx.config.insert_use.prefix_kind,
),
})
.filter(|use_path| !use_path.segments.is_empty())
.take(20)