mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
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>
This commit is contained in:
commit
af0e54a566
7 changed files with 188 additions and 119 deletions
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue