aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-07 14:53:31 +0000
committerAleksey Kladov <[email protected]>2020-02-07 16:28:02 +0000
commit561b4b11ff1d87ea1ff2477dcba6ae1f396573a3 (patch)
tree0da58d08d5a2ff27f43c3eb6163ba9aced2f5782
parentaa64a84b493aa9c0b22f36b472a445d622cd2172 (diff)
Name assist handlers
-rw-r--r--crates/ra_assists/src/assist_ctx.rs2
-rw-r--r--crates/ra_assists/src/handlers/add_custom_impl.rs (renamed from crates/ra_assists/src/assists/add_custom_impl.rs)0
-rw-r--r--crates/ra_assists/src/handlers/add_derive.rs (renamed from crates/ra_assists/src/assists/add_derive.rs)0
-rw-r--r--crates/ra_assists/src/handlers/add_explicit_type.rs (renamed from crates/ra_assists/src/assists/add_explicit_type.rs)0
-rw-r--r--crates/ra_assists/src/handlers/add_impl.rs (renamed from crates/ra_assists/src/assists/add_impl.rs)0
-rw-r--r--crates/ra_assists/src/handlers/add_import.rs (renamed from crates/ra_assists/src/assists/add_import.rs)0
-rw-r--r--crates/ra_assists/src/handlers/add_missing_impl_members.rs (renamed from crates/ra_assists/src/assists/add_missing_impl_members.rs)0
-rw-r--r--crates/ra_assists/src/handlers/add_new.rs (renamed from crates/ra_assists/src/assists/add_new.rs)0
-rw-r--r--crates/ra_assists/src/handlers/apply_demorgan.rs (renamed from crates/ra_assists/src/assists/apply_demorgan.rs)0
-rw-r--r--crates/ra_assists/src/handlers/auto_import.rs (renamed from crates/ra_assists/src/assists/auto_import.rs)0
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs (renamed from crates/ra_assists/src/assists/change_visibility.rs)0
-rw-r--r--crates/ra_assists/src/handlers/early_return.rs (renamed from crates/ra_assists/src/assists/early_return.rs)2
-rw-r--r--crates/ra_assists/src/handlers/fill_match_arms.rs (renamed from crates/ra_assists/src/assists/fill_match_arms.rs)0
-rw-r--r--crates/ra_assists/src/handlers/flip_binexpr.rs (renamed from crates/ra_assists/src/assists/flip_binexpr.rs)0
-rw-r--r--crates/ra_assists/src/handlers/flip_comma.rs (renamed from crates/ra_assists/src/assists/flip_comma.rs)0
-rw-r--r--crates/ra_assists/src/handlers/flip_trait_bound.rs (renamed from crates/ra_assists/src/assists/flip_trait_bound.rs)0
-rw-r--r--crates/ra_assists/src/handlers/inline_local_variable.rs (renamed from crates/ra_assists/src/assists/inline_local_variable.rs)0
-rw-r--r--crates/ra_assists/src/handlers/introduce_variable.rs (renamed from crates/ra_assists/src/assists/introduce_variable.rs)0
-rw-r--r--crates/ra_assists/src/handlers/invert_if.rs (renamed from crates/ra_assists/src/assists/invert_if.rs)0
-rw-r--r--crates/ra_assists/src/handlers/merge_match_arms.rs (renamed from crates/ra_assists/src/assists/merge_match_arms.rs)0
-rw-r--r--crates/ra_assists/src/handlers/move_bounds.rs (renamed from crates/ra_assists/src/assists/move_bounds.rs)0
-rw-r--r--crates/ra_assists/src/handlers/move_guard.rs (renamed from crates/ra_assists/src/assists/move_guard.rs)0
-rw-r--r--crates/ra_assists/src/handlers/raw_string.rs (renamed from crates/ra_assists/src/assists/raw_string.rs)0
-rw-r--r--crates/ra_assists/src/handlers/remove_dbg.rs (renamed from crates/ra_assists/src/assists/remove_dbg.rs)0
-rw-r--r--crates/ra_assists/src/handlers/replace_if_let_with_match.rs (renamed from crates/ra_assists/src/assists/replace_if_let_with_match.rs)0
-rw-r--r--crates/ra_assists/src/handlers/split_import.rs (renamed from crates/ra_assists/src/assists/split_import.rs)0
-rw-r--r--crates/ra_assists/src/lib.rs46
-rw-r--r--xtask/src/codegen.rs2
-rw-r--r--xtask/tests/tidy-tests/docs.rs2
29 files changed, 19 insertions, 35 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs
index 44d6f6808..81f999090 100644
--- a/crates/ra_assists/src/assist_ctx.rs
+++ b/crates/ra_assists/src/assist_ctx.rs
@@ -19,6 +19,8 @@ pub(crate) enum Assist {
19 Resolved { assist: ResolvedAssist }, 19 Resolved { assist: ResolvedAssist },
20} 20}
21 21
22pub(crate) type AssistHandler = fn(AssistCtx) -> Option<Assist>;
23
22/// `AssistCtx` allows to apply an assist or check if it could be applied. 24/// `AssistCtx` allows to apply an assist or check if it could be applied.
23/// 25///
24/// Assists use a somewhat over-engineered approach, given the current needs. The 26/// Assists use a somewhat over-engineered approach, given the current needs. The
diff --git a/crates/ra_assists/src/assists/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs
index 7fdd816bf..7fdd816bf 100644
--- a/crates/ra_assists/src/assists/add_custom_impl.rs
+++ b/crates/ra_assists/src/handlers/add_custom_impl.rs
diff --git a/crates/ra_assists/src/assists/add_derive.rs b/crates/ra_assists/src/handlers/add_derive.rs
index b0d1a0a80..b0d1a0a80 100644
--- a/crates/ra_assists/src/assists/add_derive.rs
+++ b/crates/ra_assists/src/handlers/add_derive.rs
diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs
index 2cb9d2f48..2cb9d2f48 100644
--- a/crates/ra_assists/src/assists/add_explicit_type.rs
+++ b/crates/ra_assists/src/handlers/add_explicit_type.rs
diff --git a/crates/ra_assists/src/assists/add_impl.rs b/crates/ra_assists/src/handlers/add_impl.rs
index 241b085fd..241b085fd 100644
--- a/crates/ra_assists/src/assists/add_impl.rs
+++ b/crates/ra_assists/src/handlers/add_impl.rs
diff --git a/crates/ra_assists/src/assists/add_import.rs b/crates/ra_assists/src/handlers/add_import.rs
index f03dddac8..f03dddac8 100644
--- a/crates/ra_assists/src/assists/add_import.rs
+++ b/crates/ra_assists/src/handlers/add_import.rs
diff --git a/crates/ra_assists/src/assists/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs
index 448697d31..448697d31 100644
--- a/crates/ra_assists/src/assists/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs
diff --git a/crates/ra_assists/src/assists/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs
index a08639311..a08639311 100644
--- a/crates/ra_assists/src/assists/add_new.rs
+++ b/crates/ra_assists/src/handlers/add_new.rs
diff --git a/crates/ra_assists/src/assists/apply_demorgan.rs b/crates/ra_assists/src/handlers/apply_demorgan.rs
index ba08a8223..ba08a8223 100644
--- a/crates/ra_assists/src/assists/apply_demorgan.rs
+++ b/crates/ra_assists/src/handlers/apply_demorgan.rs
diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs
index 84b5474f9..84b5474f9 100644
--- a/crates/ra_assists/src/assists/auto_import.rs
+++ b/crates/ra_assists/src/handlers/auto_import.rs
diff --git a/crates/ra_assists/src/assists/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs
index f325b6f92..f325b6f92 100644
--- a/crates/ra_assists/src/assists/change_visibility.rs
+++ b/crates/ra_assists/src/handlers/change_visibility.rs
diff --git a/crates/ra_assists/src/assists/early_return.rs b/crates/ra_assists/src/handlers/early_return.rs
index 8f30dc586..8eb3bd473 100644
--- a/crates/ra_assists/src/assists/early_return.rs
+++ b/crates/ra_assists/src/handlers/early_return.rs
@@ -10,7 +10,7 @@ use ra_syntax::{
10 10
11use crate::{ 11use crate::{
12 assist_ctx::{Assist, AssistCtx}, 12 assist_ctx::{Assist, AssistCtx},
13 assists::invert_if::invert_boolean_expression, 13 handlers::invert_if::invert_boolean_expression,
14 AssistId, 14 AssistId,
15}; 15};
16 16
diff --git a/crates/ra_assists/src/assists/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs
index 0908fc246..0908fc246 100644
--- a/crates/ra_assists/src/assists/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
diff --git a/crates/ra_assists/src/assists/flip_binexpr.rs b/crates/ra_assists/src/handlers/flip_binexpr.rs
index bfcc09e90..bfcc09e90 100644
--- a/crates/ra_assists/src/assists/flip_binexpr.rs
+++ b/crates/ra_assists/src/handlers/flip_binexpr.rs
diff --git a/crates/ra_assists/src/assists/flip_comma.rs b/crates/ra_assists/src/handlers/flip_comma.rs
index 1dacf29f8..1dacf29f8 100644
--- a/crates/ra_assists/src/assists/flip_comma.rs
+++ b/crates/ra_assists/src/handlers/flip_comma.rs
diff --git a/crates/ra_assists/src/assists/flip_trait_bound.rs b/crates/ra_assists/src/handlers/flip_trait_bound.rs
index f56769624..f56769624 100644
--- a/crates/ra_assists/src/assists/flip_trait_bound.rs
+++ b/crates/ra_assists/src/handlers/flip_trait_bound.rs
diff --git a/crates/ra_assists/src/assists/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs
index 91b588243..91b588243 100644
--- a/crates/ra_assists/src/assists/inline_local_variable.rs
+++ b/crates/ra_assists/src/handlers/inline_local_variable.rs
diff --git a/crates/ra_assists/src/assists/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs
index 7312ce687..7312ce687 100644
--- a/crates/ra_assists/src/assists/introduce_variable.rs
+++ b/crates/ra_assists/src/handlers/introduce_variable.rs
diff --git a/crates/ra_assists/src/assists/invert_if.rs b/crates/ra_assists/src/handlers/invert_if.rs
index 983392f21..983392f21 100644
--- a/crates/ra_assists/src/assists/invert_if.rs
+++ b/crates/ra_assists/src/handlers/invert_if.rs
diff --git a/crates/ra_assists/src/assists/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs
index 670614dd8..670614dd8 100644
--- a/crates/ra_assists/src/assists/merge_match_arms.rs
+++ b/crates/ra_assists/src/handlers/merge_match_arms.rs
diff --git a/crates/ra_assists/src/assists/move_bounds.rs b/crates/ra_assists/src/handlers/move_bounds.rs
index 90793b5fc..90793b5fc 100644
--- a/crates/ra_assists/src/assists/move_bounds.rs
+++ b/crates/ra_assists/src/handlers/move_bounds.rs
diff --git a/crates/ra_assists/src/assists/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs
index 2b91ce7c4..2b91ce7c4 100644
--- a/crates/ra_assists/src/assists/move_guard.rs
+++ b/crates/ra_assists/src/handlers/move_guard.rs
diff --git a/crates/ra_assists/src/assists/raw_string.rs b/crates/ra_assists/src/handlers/raw_string.rs
index 2c0a1e126..2c0a1e126 100644
--- a/crates/ra_assists/src/assists/raw_string.rs
+++ b/crates/ra_assists/src/handlers/raw_string.rs
diff --git a/crates/ra_assists/src/assists/remove_dbg.rs b/crates/ra_assists/src/handlers/remove_dbg.rs
index 5085649b4..5085649b4 100644
--- a/crates/ra_assists/src/assists/remove_dbg.rs
+++ b/crates/ra_assists/src/handlers/remove_dbg.rs
diff --git a/crates/ra_assists/src/assists/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
index e6cd50bc1..e6cd50bc1 100644
--- a/crates/ra_assists/src/assists/replace_if_let_with_match.rs
+++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs
diff --git a/crates/ra_assists/src/assists/split_import.rs b/crates/ra_assists/src/handlers/split_import.rs
index 2c3f07a79..2c3f07a79 100644
--- a/crates/ra_assists/src/assists/split_import.rs
+++ b/crates/ra_assists/src/handlers/split_import.rs
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index d476088a2..7b08e8fd7 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -19,8 +19,8 @@ use ra_ide_db::RootDatabase;
19use ra_syntax::{TextRange, TextUnit}; 19use ra_syntax::{TextRange, TextUnit};
20use ra_text_edit::TextEdit; 20use ra_text_edit::TextEdit;
21 21
22pub(crate) use crate::assist_ctx::{Assist, AssistCtx}; 22pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler};
23pub use crate::assists::add_import::auto_import_text_edit; 23pub use crate::handlers::add_import::auto_import_text_edit;
24 24
25/// Unique identifier of the assist, should not be shown to the user 25/// Unique identifier of the assist, should not be shown to the user
26/// directly. 26/// directly.
@@ -72,7 +72,7 @@ impl ResolvedAssist {
72/// returned, without actual edits. 72/// returned, without actual edits.
73pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec<AssistLabel> { 73pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec<AssistLabel> {
74 let ctx = AssistCtx::new(db, range, false); 74 let ctx = AssistCtx::new(db, range, false);
75 assists::all() 75 handlers::all()
76 .iter() 76 .iter()
77 .filter_map(|f| f(ctx.clone())) 77 .filter_map(|f| f(ctx.clone()))
78 .map(|a| match a { 78 .map(|a| match a {
@@ -88,7 +88,7 @@ pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec<AssistLabe
88/// computed. 88/// computed.
89pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssist> { 89pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssist> {
90 let ctx = AssistCtx::new(db, range, true); 90 let ctx = AssistCtx::new(db, range, true);
91 let mut a = assists::all() 91 let mut a = handlers::all()
92 .iter() 92 .iter()
93 .filter_map(|f| f(ctx.clone())) 93 .filter_map(|f| f(ctx.clone()))
94 .map(|a| match a { 94 .map(|a| match a {
@@ -109,8 +109,8 @@ fn sort_assists(assists: &mut [ResolvedAssist]) {
109 }); 109 });
110} 110}
111 111
112mod assists { 112mod handlers {
113 use crate::{Assist, AssistCtx}; 113 use crate::AssistHandler;
114 114
115 mod add_derive; 115 mod add_derive;
116 mod add_explicit_type; 116 mod add_explicit_type;
@@ -138,7 +138,7 @@ mod assists {
138 mod move_bounds; 138 mod move_bounds;
139 mod early_return; 139 mod early_return;
140 140
141 pub(crate) fn all() -> &'static [fn(AssistCtx) -> Option<Assist>] { 141 pub(crate) fn all() -> &'static [AssistHandler] {
142 &[ 142 &[
143 add_derive::add_derive, 143 add_derive::add_derive,
144 add_explicit_type::add_explicit_type, 144 add_explicit_type::add_explicit_type,
@@ -183,7 +183,7 @@ mod helpers {
183 use ra_syntax::TextRange; 183 use ra_syntax::TextRange;
184 use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range}; 184 use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range};
185 185
186 use crate::{Assist, AssistCtx}; 186 use crate::{Assist, AssistCtx, AssistHandler};
187 187
188 pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { 188 pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
189 let (mut db, file_id) = RootDatabase::with_single_file(text); 189 let (mut db, file_id) = RootDatabase::with_single_file(text);
@@ -194,7 +194,7 @@ mod helpers {
194 (db, file_id) 194 (db, file_id)
195 } 195 }
196 196
197 pub(crate) fn check_assist(assist: fn(AssistCtx) -> Option<Assist>, before: &str, after: &str) { 197 pub(crate) fn check_assist(assist: AssistHandler, before: &str, after: &str) {
198 let (before_cursor_pos, before) = extract_offset(before); 198 let (before_cursor_pos, before) = extract_offset(before);
199 let (db, file_id) = with_single_file(&before); 199 let (db, file_id) = with_single_file(&before);
200 let frange = 200 let frange =
@@ -218,11 +218,7 @@ mod helpers {
218 assert_eq_text!(after, &actual); 218 assert_eq_text!(after, &actual);
219 } 219 }
220 220
221 pub(crate) fn check_assist_range( 221 pub(crate) fn check_assist_range(assist: AssistHandler, before: &str, after: &str) {
222 assist: fn(AssistCtx) -> Option<Assist>,
223 before: &str,
224 after: &str,
225 ) {
226 let (range, before) = extract_range(before); 222 let (range, before) = extract_range(before);
227 let (db, file_id) = with_single_file(&before); 223 let (db, file_id) = with_single_file(&before);
228 let frange = FileRange { file_id, range }; 224 let frange = FileRange { file_id, range };
@@ -240,11 +236,7 @@ mod helpers {
240 assert_eq_text!(after, &actual); 236 assert_eq_text!(after, &actual);
241 } 237 }
242 238
243 pub(crate) fn check_assist_target( 239 pub(crate) fn check_assist_target(assist: AssistHandler, before: &str, target: &str) {
244 assist: fn(AssistCtx) -> Option<Assist>,
245 before: &str,
246 target: &str,
247 ) {
248 let (before_cursor_pos, before) = extract_offset(before); 240 let (before_cursor_pos, before) = extract_offset(before);
249 let (db, file_id) = with_single_file(&before); 241 let (db, file_id) = with_single_file(&before);
250 let frange = 242 let frange =
@@ -260,11 +252,7 @@ mod helpers {
260 assert_eq_text!(&before[range.start().to_usize()..range.end().to_usize()], target); 252 assert_eq_text!(&before[range.start().to_usize()..range.end().to_usize()], target);
261 } 253 }
262 254
263 pub(crate) fn check_assist_range_target( 255 pub(crate) fn check_assist_range_target(assist: AssistHandler, before: &str, target: &str) {
264 assist: fn(AssistCtx) -> Option<Assist>,
265 before: &str,
266 target: &str,
267 ) {
268 let (range, before) = extract_range(before); 256 let (range, before) = extract_range(before);
269 let (db, file_id) = with_single_file(&before); 257 let (db, file_id) = with_single_file(&before);
270 let frange = FileRange { file_id, range }; 258 let frange = FileRange { file_id, range };
@@ -279,10 +267,7 @@ mod helpers {
279 assert_eq_text!(&before[range.start().to_usize()..range.end().to_usize()], target); 267 assert_eq_text!(&before[range.start().to_usize()..range.end().to_usize()], target);
280 } 268 }
281 269
282 pub(crate) fn check_assist_not_applicable( 270 pub(crate) fn check_assist_not_applicable(assist: AssistHandler, before: &str) {
283 assist: fn(AssistCtx) -> Option<Assist>,
284 before: &str,
285 ) {
286 let (before_cursor_pos, before) = extract_offset(before); 271 let (before_cursor_pos, before) = extract_offset(before);
287 let (db, file_id) = with_single_file(&before); 272 let (db, file_id) = with_single_file(&before);
288 let frange = 273 let frange =
@@ -291,10 +276,7 @@ mod helpers {
291 assert!(assist.is_none()); 276 assert!(assist.is_none());
292 } 277 }
293 278
294 pub(crate) fn check_assist_range_not_applicable( 279 pub(crate) fn check_assist_range_not_applicable(assist: AssistHandler, before: &str) {
295 assist: fn(AssistCtx) -> Option<Assist>,
296 before: &str,
297 ) {
298 let (range, before) = extract_range(before); 280 let (range, before) = extract_range(before);
299 let (db, file_id) = with_single_file(&before); 281 let (db, file_id) = with_single_file(&before);
300 let frange = FileRange { file_id, range }; 282 let frange = FileRange { file_id, range };
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index efa638e06..a53d57335 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -25,7 +25,7 @@ const ERR_INLINE_TESTS_DIR: &str = "crates/ra_syntax/test_data/parser/inline/err
25pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs"; 25pub const SYNTAX_KINDS: &str = "crates/ra_parser/src/syntax_kind/generated.rs";
26pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs"; 26pub const AST: &str = "crates/ra_syntax/src/ast/generated.rs";
27 27
28const ASSISTS_DIR: &str = "crates/ra_assists/src/assists"; 28const ASSISTS_DIR: &str = "crates/ra_assists/src/handlers";
29const ASSISTS_TESTS: &str = "crates/ra_assists/src/doc_tests/generated.rs"; 29const ASSISTS_TESTS: &str = "crates/ra_assists/src/doc_tests/generated.rs";
30const ASSISTS_DOCS: &str = "docs/user/assists.md"; 30const ASSISTS_DOCS: &str = "docs/user/assists.md";
31 31
diff --git a/xtask/tests/tidy-tests/docs.rs b/xtask/tests/tidy-tests/docs.rs
index 8a005d6c4..6a69e7d6a 100644
--- a/xtask/tests/tidy-tests/docs.rs
+++ b/xtask/tests/tidy-tests/docs.rs
@@ -6,7 +6,7 @@ use xtask::project_root;
6fn is_exclude_dir(p: &Path) -> bool { 6fn is_exclude_dir(p: &Path) -> bool {
7 // Test hopefully don't really need comments, and for assists we already 7 // Test hopefully don't really need comments, and for assists we already
8 // have special comments which are source of doc tests and user docs. 8 // have special comments which are source of doc tests and user docs.
9 let exclude_dirs = ["tests", "test_data", "assists"]; 9 let exclude_dirs = ["tests", "test_data", "handlers"];
10 let mut cur_path = p; 10 let mut cur_path = p;
11 while let Some(path) = cur_path.parent() { 11 while let Some(path) = cur_path.parent() {
12 if exclude_dirs.iter().any(|dir| path.ends_with(dir)) { 12 if exclude_dirs.iter().any(|dir| path.ends_with(dir)) {