aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/assists/src/assist_config.rs5
-rw-r--r--crates/assists/src/handlers/auto_import.rs16
-rw-r--r--crates/hir/src/code_model.rs3
-rw-r--r--crates/hir/src/lib.rs1
-rw-r--r--crates/rust-analyzer/src/config.rs17
-rw-r--r--editors/code/package.json17
6 files changed, 49 insertions, 10 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)
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs
index 5f35d9d3c..a445a97b3 100644
--- a/crates/hir/src/code_model.rs
+++ b/crates/hir/src/code_model.rs
@@ -391,8 +391,9 @@ impl Module {
391 self, 391 self,
392 db: &dyn DefDatabase, 392 db: &dyn DefDatabase,
393 item: impl Into<ItemInNs>, 393 item: impl Into<ItemInNs>,
394 prefix_kind: PrefixKind,
394 ) -> Option<ModPath> { 395 ) -> Option<ModPath> {
395 hir_def::find_path::find_path_prefixed(db, item.into(), self.into(), PrefixKind::Plain) 396 hir_def::find_path::find_path_prefixed(db, item.into(), self.into(), prefix_kind)
396 } 397 }
397} 398}
398 399
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index b9d9c7e25..87084fa13 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -48,6 +48,7 @@ pub use hir_def::{
48 body::scope::ExprScopes, 48 body::scope::ExprScopes,
49 builtin_type::BuiltinType, 49 builtin_type::BuiltinType,
50 docs::Documentation, 50 docs::Documentation,
51 find_path::PrefixKind,
51 item_scope::ItemInNs, 52 item_scope::ItemInNs,
52 nameres::ModuleSource, 53 nameres::ModuleSource,
53 path::ModPath, 54 path::ModPath,
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 0ab4c37bf..dcbc11c14 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -10,6 +10,7 @@
10use std::{ffi::OsString, path::PathBuf}; 10use std::{ffi::OsString, path::PathBuf};
11 11
12use flycheck::FlycheckConfig; 12use flycheck::FlycheckConfig;
13use hir::PrefixKind;
13use ide::{ 14use ide::{
14 AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig, 15 AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig,
15 MergeBehaviour, 16 MergeBehaviour,
@@ -289,6 +290,11 @@ impl Config {
289 MergeBehaviourDef::Full => Some(MergeBehaviour::Full), 290 MergeBehaviourDef::Full => Some(MergeBehaviour::Full),
290 MergeBehaviourDef::Last => Some(MergeBehaviour::Last), 291 MergeBehaviourDef::Last => Some(MergeBehaviour::Last),
291 }; 292 };
293 self.assist.insert_use.prefix_kind = match data.assist_importPrefix {
294 ImportPrefixDef::Plain => PrefixKind::Plain,
295 ImportPrefixDef::ByCrate => PrefixKind::ByCrate,
296 ImportPrefixDef::BySelf => PrefixKind::BySelf,
297 };
292 298
293 self.call_info_full = data.callInfo_full; 299 self.call_info_full = data.callInfo_full;
294 300
@@ -403,13 +409,21 @@ enum ManifestOrProjectJson {
403} 409}
404 410
405#[derive(Deserialize)] 411#[derive(Deserialize)]
406#[serde(rename_all = "lowercase")] 412#[serde(rename_all = "snake_case")]
407enum MergeBehaviourDef { 413enum MergeBehaviourDef {
408 None, 414 None,
409 Full, 415 Full,
410 Last, 416 Last,
411} 417}
412 418
419#[derive(Deserialize)]
420#[serde(rename_all = "snake_case")]
421enum ImportPrefixDef {
422 Plain,
423 BySelf,
424 ByCrate,
425}
426
413macro_rules! config_data { 427macro_rules! config_data {
414 (struct $name:ident { $($field:ident: $ty:ty = $default:expr,)*}) => { 428 (struct $name:ident { $($field:ident: $ty:ty = $default:expr,)*}) => {
415 #[allow(non_snake_case)] 429 #[allow(non_snake_case)]
@@ -434,6 +448,7 @@ macro_rules! config_data {
434config_data! { 448config_data! {
435 struct ConfigData { 449 struct ConfigData {
436 assist_importMergeBehaviour: MergeBehaviourDef = MergeBehaviourDef::None, 450 assist_importMergeBehaviour: MergeBehaviourDef = MergeBehaviourDef::None,
451 assist_importPrefix: ImportPrefixDef = ImportPrefixDef::Plain,
437 452
438 callInfo_full: bool = true, 453 callInfo_full: bool = true,
439 454
diff --git a/editors/code/package.json b/editors/code/package.json
index cc2ac3bd2..1f0e7550b 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -652,6 +652,21 @@
652 "default": "full", 652 "default": "full",
653 "description": "The strategy to use when inserting new imports or merging imports." 653 "description": "The strategy to use when inserting new imports or merging imports."
654 }, 654 },
655 "rust-analyzer.assist.importPrefix": {
656 "type": "string",
657 "enum": [
658 "plain",
659 "by_self",
660 "by_crate"
661 ],
662 "enumDescriptions": [
663 "Insert import paths relative to the current module, using up to one `super` prefix if the parent module contains the requested item.",
664 "Prefix all import paths with `self` if they don't begin with `self`, `super`, `crate` or a crate name",
665 "Force import paths to be absolute by always starting them with `crate` or the crate name they refer to."
666 ],
667 "default": "plain",
668 "description": "The path structure for newly inserted paths to use."
669 },
655 "rust-analyzer.runnables.overrideCargo": { 670 "rust-analyzer.runnables.overrideCargo": {
656 "type": [ 671 "type": [
657 "null", 672 "null",
@@ -1033,4 +1048,4 @@
1033 ] 1048 ]
1034 } 1049 }
1035 } 1050 }
1036} 1051} \ No newline at end of file