diff options
-rw-r--r-- | crates/assists/src/assist_config.rs | 20 | ||||
-rw-r--r-- | crates/assists/src/handlers/auto_import.rs | 7 | ||||
-rw-r--r-- | crates/assists/src/handlers/extract_struct_from_enum_variant.rs | 6 | ||||
-rw-r--r-- | crates/assists/src/handlers/replace_qualified_name_with_use.rs | 4 | ||||
-rw-r--r-- | crates/assists/src/utils.rs | 3 | ||||
-rw-r--r-- | crates/assists/src/utils/insert_use.rs | 2 | ||||
-rw-r--r-- | crates/ide/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 21 | ||||
-rw-r--r-- | editors/code/package.json | 15 |
9 files changed, 65 insertions, 17 deletions
diff --git a/crates/assists/src/assist_config.rs b/crates/assists/src/assist_config.rs index cda2abfb9..adf02edab 100644 --- a/crates/assists/src/assist_config.rs +++ b/crates/assists/src/assist_config.rs | |||
@@ -4,12 +4,13 @@ | |||
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 | ||
7 | use crate::AssistKind; | 7 | use crate::{utils::MergeBehaviour, AssistKind}; |
8 | 8 | ||
9 | #[derive(Clone, Debug, PartialEq, Eq)] | 9 | #[derive(Clone, Debug, PartialEq, Eq)] |
10 | pub struct AssistConfig { | 10 | pub struct AssistConfig { |
11 | pub snippet_cap: Option<SnippetCap>, | 11 | pub snippet_cap: Option<SnippetCap>, |
12 | pub allowed: Option<Vec<AssistKind>>, | 12 | pub allowed: Option<Vec<AssistKind>>, |
13 | pub insert_use: InsertUseConfig, | ||
13 | } | 14 | } |
14 | 15 | ||
15 | impl AssistConfig { | 16 | impl AssistConfig { |
@@ -25,6 +26,21 @@ pub struct SnippetCap { | |||
25 | 26 | ||
26 | impl Default for AssistConfig { | 27 | impl Default for AssistConfig { |
27 | fn default() -> Self { | 28 | fn default() -> Self { |
28 | AssistConfig { snippet_cap: Some(SnippetCap { _private: () }), allowed: None } | 29 | AssistConfig { |
30 | snippet_cap: Some(SnippetCap { _private: () }), | ||
31 | allowed: None, | ||
32 | insert_use: InsertUseConfig::default(), | ||
33 | } | ||
34 | } | ||
35 | } | ||
36 | |||
37 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
38 | pub struct InsertUseConfig { | ||
39 | pub merge: Option<MergeBehaviour>, | ||
40 | } | ||
41 | |||
42 | impl Default for InsertUseConfig { | ||
43 | fn default() -> Self { | ||
44 | InsertUseConfig { merge: Some(MergeBehaviour::Full) } | ||
29 | } | 45 | } |
30 | } | 46 | } |
diff --git a/crates/assists/src/handlers/auto_import.rs b/crates/assists/src/handlers/auto_import.rs index 66e819154..b5eb2c722 100644 --- a/crates/assists/src/handlers/auto_import.rs +++ b/crates/assists/src/handlers/auto_import.rs | |||
@@ -14,10 +14,7 @@ use syntax::{ | |||
14 | SyntaxNode, | 14 | SyntaxNode, |
15 | }; | 15 | }; |
16 | 16 | ||
17 | use crate::{ | 17 | use crate::{utils::insert_use, AssistContext, AssistId, AssistKind, Assists, GroupLabel}; |
18 | utils::{insert_use, MergeBehaviour}, | ||
19 | AssistContext, AssistId, AssistKind, Assists, GroupLabel, | ||
20 | }; | ||
21 | 18 | ||
22 | // Assist: auto_import | 19 | // Assist: auto_import |
23 | // | 20 | // |
@@ -60,7 +57,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
60 | let new_syntax = insert_use( | 57 | let new_syntax = insert_use( |
61 | &scope, | 58 | &scope, |
62 | make::path_from_text(&import.to_string()), | 59 | make::path_from_text(&import.to_string()), |
63 | Some(MergeBehaviour::Full), | 60 | ctx.config.insert_use.merge, |
64 | ); | 61 | ); |
65 | builder.replace(syntax.text_range(), new_syntax.to_string()) | 62 | builder.replace(syntax.text_range(), new_syntax.to_string()) |
66 | }, | 63 | }, |
diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index 80c62d8bb..3ea50f375 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs | |||
@@ -10,9 +10,7 @@ use syntax::{ | |||
10 | }; | 10 | }; |
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | assist_context::AssistBuilder, | 13 | assist_context::AssistBuilder, utils::insert_use, AssistContext, AssistId, AssistKind, Assists, |
14 | utils::{insert_use, MergeBehaviour}, | ||
15 | AssistContext, AssistId, AssistKind, Assists, | ||
16 | }; | 14 | }; |
17 | use ast::make; | 15 | use ast::make; |
18 | use insert_use::ImportScope; | 16 | use insert_use::ImportScope; |
@@ -117,7 +115,7 @@ fn insert_import( | |||
117 | let new_syntax = insert_use( | 115 | let new_syntax = insert_use( |
118 | &scope, | 116 | &scope, |
119 | make::path_from_text(&mod_path.to_string()), | 117 | make::path_from_text(&mod_path.to_string()), |
120 | Some(MergeBehaviour::Full), | 118 | ctx.config.insert_use.merge, |
121 | ); | 119 | ); |
122 | // FIXME: this will currently panic as multiple imports will have overlapping text ranges | 120 | // FIXME: this will currently panic as multiple imports will have overlapping text ranges |
123 | builder.replace(syntax.text_range(), new_syntax.to_string()) | 121 | builder.replace(syntax.text_range(), new_syntax.to_string()) |
diff --git a/crates/assists/src/handlers/replace_qualified_name_with_use.rs b/crates/assists/src/handlers/replace_qualified_name_with_use.rs index 85c70d16b..e48407fcc 100644 --- a/crates/assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/assists/src/handlers/replace_qualified_name_with_use.rs | |||
@@ -2,7 +2,7 @@ use syntax::{algo::SyntaxRewriter, ast, match_ast, AstNode, SyntaxNode, TextRang | |||
2 | use test_utils::mark; | 2 | use test_utils::mark; |
3 | 3 | ||
4 | use crate::{ | 4 | use crate::{ |
5 | utils::{insert_use, ImportScope, MergeBehaviour}, | 5 | utils::{insert_use, ImportScope}, |
6 | AssistContext, AssistId, AssistKind, Assists, | 6 | AssistContext, AssistId, AssistKind, Assists, |
7 | }; | 7 | }; |
8 | use ast::make; | 8 | use ast::make; |
@@ -60,7 +60,7 @@ pub(crate) fn replace_qualified_name_with_use( | |||
60 | let new_syntax = insert_use( | 60 | let new_syntax = insert_use( |
61 | import_scope, | 61 | import_scope, |
62 | make::path_from_text(path_to_import), | 62 | make::path_from_text(path_to_import), |
63 | Some(MergeBehaviour::Full), | 63 | ctx.config.insert_use.merge, |
64 | ); | 64 | ); |
65 | builder.replace(syntax.text_range(), new_syntax.to_string()) | 65 | builder.replace(syntax.text_range(), new_syntax.to_string()) |
66 | } | 66 | } |
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 7559ddd63..b0511ceb6 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs | |||
@@ -16,7 +16,8 @@ use syntax::{ | |||
16 | 16 | ||
17 | use crate::assist_config::SnippetCap; | 17 | use crate::assist_config::SnippetCap; |
18 | 18 | ||
19 | pub(crate) use insert_use::{insert_use, ImportScope, MergeBehaviour}; | 19 | pub use insert_use::MergeBehaviour; |
20 | pub(crate) use insert_use::{insert_use, ImportScope}; | ||
20 | 21 | ||
21 | pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr { | 22 | pub(crate) fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr { |
22 | extract_trivial_expression(&block) | 23 | extract_trivial_expression(&block) |
diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs index 98553b2e0..6d110aaaf 100644 --- a/crates/assists/src/utils/insert_use.rs +++ b/crates/assists/src/utils/insert_use.rs | |||
@@ -236,7 +236,7 @@ fn common_prefix(lhs: &ast::Path, rhs: &ast::Path) -> Option<(ast::Path, ast::Pa | |||
236 | } | 236 | } |
237 | 237 | ||
238 | /// What type of merges are allowed. | 238 | /// What type of merges are allowed. |
239 | #[derive(Copy, Clone, PartialEq, Eq)] | 239 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
240 | pub enum MergeBehaviour { | 240 | pub enum MergeBehaviour { |
241 | /// Merge everything together creating deeply nested imports. | 241 | /// Merge everything together creating deeply nested imports. |
242 | Full, | 242 | Full, |
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 570790384..3b97e087f 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -81,7 +81,9 @@ pub use crate::{ | |||
81 | }, | 81 | }, |
82 | }; | 82 | }; |
83 | 83 | ||
84 | pub use assists::{Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist}; | 84 | pub use assists::{ |
85 | utils::MergeBehaviour, Assist, AssistConfig, AssistId, AssistKind, ResolvedAssist, | ||
86 | }; | ||
85 | pub use base_db::{ | 87 | pub use base_db::{ |
86 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, | 88 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRoot, |
87 | SourceRootId, | 89 | SourceRootId, |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 187273bbc..1a74286f5 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -10,7 +10,10 @@ | |||
10 | use std::{ffi::OsString, path::PathBuf}; | 10 | use std::{ffi::OsString, path::PathBuf}; |
11 | 11 | ||
12 | use flycheck::FlycheckConfig; | 12 | use flycheck::FlycheckConfig; |
13 | use ide::{AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig}; | 13 | use ide::{ |
14 | AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig, | ||
15 | MergeBehaviour, | ||
16 | }; | ||
14 | use lsp_types::ClientCapabilities; | 17 | use lsp_types::ClientCapabilities; |
15 | use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest}; | 18 | use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest}; |
16 | use rustc_hash::FxHashSet; | 19 | use rustc_hash::FxHashSet; |
@@ -263,6 +266,12 @@ impl Config { | |||
263 | self.completion.add_call_parenthesis = data.completion_addCallParenthesis; | 266 | self.completion.add_call_parenthesis = data.completion_addCallParenthesis; |
264 | self.completion.add_call_argument_snippets = data.completion_addCallArgumentSnippets; | 267 | self.completion.add_call_argument_snippets = data.completion_addCallArgumentSnippets; |
265 | 268 | ||
269 | self.assist.insert_use.merge = match data.assist_importMergeBehaviour { | ||
270 | MergeBehaviourDef::None => None, | ||
271 | MergeBehaviourDef::Full => Some(MergeBehaviour::Full), | ||
272 | MergeBehaviourDef::Last => Some(MergeBehaviour::Last), | ||
273 | }; | ||
274 | |||
266 | self.call_info_full = data.callInfo_full; | 275 | self.call_info_full = data.callInfo_full; |
267 | 276 | ||
268 | self.lens = LensConfig { | 277 | self.lens = LensConfig { |
@@ -370,6 +379,14 @@ enum ManifestOrProjectJson { | |||
370 | ProjectJson(ProjectJsonData), | 379 | ProjectJson(ProjectJsonData), |
371 | } | 380 | } |
372 | 381 | ||
382 | #[derive(Deserialize)] | ||
383 | #[serde(rename_all = "lowercase")] | ||
384 | enum MergeBehaviourDef { | ||
385 | None, | ||
386 | Full, | ||
387 | Last, | ||
388 | } | ||
389 | |||
373 | macro_rules! config_data { | 390 | macro_rules! config_data { |
374 | (struct $name:ident { $($field:ident: $ty:ty = $default:expr,)*}) => { | 391 | (struct $name:ident { $($field:ident: $ty:ty = $default:expr,)*}) => { |
375 | #[allow(non_snake_case)] | 392 | #[allow(non_snake_case)] |
@@ -393,6 +410,8 @@ macro_rules! config_data { | |||
393 | 410 | ||
394 | config_data! { | 411 | config_data! { |
395 | struct ConfigData { | 412 | struct ConfigData { |
413 | assist_importMergeBehaviour: MergeBehaviourDef = MergeBehaviourDef::None, | ||
414 | |||
396 | callInfo_full: bool = true, | 415 | callInfo_full: bool = true, |
397 | 416 | ||
398 | cargo_autoreload: bool = true, | 417 | cargo_autoreload: bool = true, |
diff --git a/editors/code/package.json b/editors/code/package.json index 6fc4464df..858e4c4f5 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -626,6 +626,21 @@ | |||
626 | }, | 626 | }, |
627 | "description": "List of warnings that should be displayed with hint severity.\nThe warnings will be indicated by faded text or three dots in code and will not show up in the problems panel.", | 627 | "description": "List of warnings that should be displayed with hint severity.\nThe warnings will be indicated by faded text or three dots in code and will not show up in the problems panel.", |
628 | "default": [] | 628 | "default": [] |
629 | }, | ||
630 | "rust-analyzer.assist.importMergeBehaviour": { | ||
631 | "type": "string", | ||
632 | "enum": [ | ||
633 | "none", | ||
634 | "full", | ||
635 | "last" | ||
636 | ], | ||
637 | "enumDescriptions": [ | ||
638 | "No merging", | ||
639 | "Merge all layers of the import trees", | ||
640 | "Only merge the last layer of the import trees" | ||
641 | ], | ||
642 | "default": "full", | ||
643 | "description": "The strategy to use when inserting new imports or merging imports." | ||
629 | } | 644 | } |
630 | } | 645 | } |
631 | }, | 646 | }, |