diff options
author | Aleksey Kladov <[email protected]> | 2021-06-14 11:18:03 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-14 15:45:17 +0100 |
commit | 2e8dab631b4ab429eeade7f5302e8de9dcd0b398 (patch) | |
tree | 0f75dd26d6c1b370dcb53da5bb868f1799e2203c | |
parent | 1d2772c2c7dc0a42d8a9429d24ea41412add61b3 (diff) |
internal: prepare to move assist definitions
-rw-r--r-- | crates/ide/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ide_assists/src/lib.rs | 30 | ||||
-rw-r--r-- | crates/ide_assists/src/tests.rs | 26 | ||||
-rw-r--r-- | crates/ide_diagnostics/src/lib.rs | 3 |
4 files changed, 30 insertions, 33 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 0019b7ba5..98d01f0ce 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -535,7 +535,7 @@ impl Analysis { | |||
535 | ) -> Cancellable<Vec<Assist>> { | 535 | ) -> Cancellable<Vec<Assist>> { |
536 | self.with_db(|db| { | 536 | self.with_db(|db| { |
537 | let ssr_assists = ssr::ssr_assists(db, &resolve, frange); | 537 | let ssr_assists = ssr::ssr_assists(db, &resolve, frange); |
538 | let mut acc = Assist::get(db, config, resolve, frange); | 538 | let mut acc = ide_assists::assists(db, config, resolve, frange); |
539 | acc.extend(ssr_assists.into_iter()); | 539 | acc.extend(ssr_assists.into_iter()); |
540 | acc | 540 | acc |
541 | }) | 541 | }) |
@@ -576,7 +576,7 @@ impl Analysis { | |||
576 | Vec::new() | 576 | Vec::new() |
577 | }; | 577 | }; |
578 | 578 | ||
579 | let mut res = Assist::get(db, assist_config, resolve, frange); | 579 | let mut res = ide_assists::assists(db, assist_config, resolve, frange); |
580 | res.extend(ssr_assists.into_iter()); | 580 | res.extend(ssr_assists.into_iter()); |
581 | res.extend(diagnostic_assists.into_iter()); | 581 | res.extend(diagnostic_assists.into_iter()); |
582 | 582 | ||
diff --git a/crates/ide_assists/src/lib.rs b/crates/ide_assists/src/lib.rs index 331a6df2b..804918284 100644 --- a/crates/ide_assists/src/lib.rs +++ b/crates/ide_assists/src/lib.rs | |||
@@ -151,22 +151,20 @@ pub struct Assist { | |||
151 | pub source_change: Option<SourceChange>, | 151 | pub source_change: Option<SourceChange>, |
152 | } | 152 | } |
153 | 153 | ||
154 | impl Assist { | 154 | /// Return all the assists applicable at the given position. |
155 | /// Return all the assists applicable at the given position. | 155 | pub fn assists( |
156 | pub fn get( | 156 | db: &RootDatabase, |
157 | db: &RootDatabase, | 157 | config: &AssistConfig, |
158 | config: &AssistConfig, | 158 | resolve: AssistResolveStrategy, |
159 | resolve: AssistResolveStrategy, | 159 | range: FileRange, |
160 | range: FileRange, | 160 | ) -> Vec<Assist> { |
161 | ) -> Vec<Assist> { | 161 | let sema = Semantics::new(db); |
162 | let sema = Semantics::new(db); | 162 | let ctx = AssistContext::new(sema, config, range); |
163 | let ctx = AssistContext::new(sema, config, range); | 163 | let mut acc = Assists::new(&ctx, resolve); |
164 | let mut acc = Assists::new(&ctx, resolve); | 164 | handlers::all().iter().for_each(|handler| { |
165 | handlers::all().iter().for_each(|handler| { | 165 | handler(&mut acc, &ctx); |
166 | handler(&mut acc, &ctx); | 166 | }); |
167 | }); | 167 | acc.finish() |
168 | acc.finish() | ||
169 | } | ||
170 | } | 168 | } |
171 | 169 | ||
172 | mod handlers { | 170 | mod handlers { |
diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs index bdf9cb71c..60cecd94c 100644 --- a/crates/ide_assists/src/tests.rs +++ b/crates/ide_assists/src/tests.rs | |||
@@ -16,8 +16,8 @@ use syntax::TextRange; | |||
16 | use test_utils::{assert_eq_text, extract_offset}; | 16 | use test_utils::{assert_eq_text, extract_offset}; |
17 | 17 | ||
18 | use crate::{ | 18 | use crate::{ |
19 | handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, AssistResolveStrategy, | 19 | assists, handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, |
20 | Assists, SingleResolve, | 20 | AssistResolveStrategy, Assists, SingleResolve, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig { | 23 | pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig { |
@@ -78,14 +78,14 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) { | |||
78 | let before = db.file_text(file_id).to_string(); | 78 | let before = db.file_text(file_id).to_string(); |
79 | let frange = FileRange { file_id, range: selection.into() }; | 79 | let frange = FileRange { file_id, range: selection.into() }; |
80 | 80 | ||
81 | let assist = Assist::get(&db, &TEST_CONFIG, AssistResolveStrategy::All, frange) | 81 | let assist = assists(&db, &TEST_CONFIG, AssistResolveStrategy::All, frange) |
82 | .into_iter() | 82 | .into_iter() |
83 | .find(|assist| assist.id.0 == assist_id) | 83 | .find(|assist| assist.id.0 == assist_id) |
84 | .unwrap_or_else(|| { | 84 | .unwrap_or_else(|| { |
85 | panic!( | 85 | panic!( |
86 | "\n\nAssist is not applicable: {}\nAvailable assists: {}", | 86 | "\n\nAssist is not applicable: {}\nAvailable assists: {}", |
87 | assist_id, | 87 | assist_id, |
88 | Assist::get(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange) | 88 | assists(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange) |
89 | .into_iter() | 89 | .into_iter() |
90 | .map(|assist| assist.id.0) | 90 | .map(|assist| assist.id.0) |
91 | .collect::<Vec<_>>() | 91 | .collect::<Vec<_>>() |
@@ -210,7 +210,7 @@ fn assist_order_field_struct() { | |||
210 | let (before_cursor_pos, before) = extract_offset(before); | 210 | let (before_cursor_pos, before) = extract_offset(before); |
211 | let (db, file_id) = with_single_file(&before); | 211 | let (db, file_id) = with_single_file(&before); |
212 | let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; | 212 | let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; |
213 | let assists = Assist::get(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange); | 213 | let assists = assists(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange); |
214 | let mut assists = assists.iter(); | 214 | let mut assists = assists.iter(); |
215 | 215 | ||
216 | assert_eq!(assists.next().expect("expected assist").label, "Change visibility to pub(crate)"); | 216 | assert_eq!(assists.next().expect("expected assist").label, "Change visibility to pub(crate)"); |
@@ -235,7 +235,7 @@ pub fn test_some_range(a: int) -> bool { | |||
235 | "#, | 235 | "#, |
236 | ); | 236 | ); |
237 | 237 | ||
238 | let assists = Assist::get(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange); | 238 | let assists = assists(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange); |
239 | let expected = labels(&assists); | 239 | let expected = labels(&assists); |
240 | 240 | ||
241 | expect![[r#" | 241 | expect![[r#" |
@@ -264,7 +264,7 @@ pub fn test_some_range(a: int) -> bool { | |||
264 | let mut cfg = TEST_CONFIG; | 264 | let mut cfg = TEST_CONFIG; |
265 | cfg.allowed = Some(vec![AssistKind::Refactor]); | 265 | cfg.allowed = Some(vec![AssistKind::Refactor]); |
266 | 266 | ||
267 | let assists = Assist::get(&db, &cfg, AssistResolveStrategy::None, frange); | 267 | let assists = assists(&db, &cfg, AssistResolveStrategy::None, frange); |
268 | let expected = labels(&assists); | 268 | let expected = labels(&assists); |
269 | 269 | ||
270 | expect![[r#" | 270 | expect![[r#" |
@@ -279,7 +279,7 @@ pub fn test_some_range(a: int) -> bool { | |||
279 | { | 279 | { |
280 | let mut cfg = TEST_CONFIG; | 280 | let mut cfg = TEST_CONFIG; |
281 | cfg.allowed = Some(vec![AssistKind::RefactorExtract]); | 281 | cfg.allowed = Some(vec![AssistKind::RefactorExtract]); |
282 | let assists = Assist::get(&db, &cfg, AssistResolveStrategy::None, frange); | 282 | let assists = assists(&db, &cfg, AssistResolveStrategy::None, frange); |
283 | let expected = labels(&assists); | 283 | let expected = labels(&assists); |
284 | 284 | ||
285 | expect![[r#" | 285 | expect![[r#" |
@@ -292,7 +292,7 @@ pub fn test_some_range(a: int) -> bool { | |||
292 | { | 292 | { |
293 | let mut cfg = TEST_CONFIG; | 293 | let mut cfg = TEST_CONFIG; |
294 | cfg.allowed = Some(vec![AssistKind::QuickFix]); | 294 | cfg.allowed = Some(vec![AssistKind::QuickFix]); |
295 | let assists = Assist::get(&db, &cfg, AssistResolveStrategy::None, frange); | 295 | let assists = assists(&db, &cfg, AssistResolveStrategy::None, frange); |
296 | let expected = labels(&assists); | 296 | let expected = labels(&assists); |
297 | 297 | ||
298 | expect![[r#""#]].assert_eq(&expected); | 298 | expect![[r#""#]].assert_eq(&expected); |
@@ -317,7 +317,7 @@ pub fn test_some_range(a: int) -> bool { | |||
317 | cfg.allowed = Some(vec![AssistKind::RefactorExtract]); | 317 | cfg.allowed = Some(vec![AssistKind::RefactorExtract]); |
318 | 318 | ||
319 | { | 319 | { |
320 | let assists = Assist::get(&db, &cfg, AssistResolveStrategy::None, frange); | 320 | let assists = assists(&db, &cfg, AssistResolveStrategy::None, frange); |
321 | assert_eq!(2, assists.len()); | 321 | assert_eq!(2, assists.len()); |
322 | let mut assists = assists.into_iter(); | 322 | let mut assists = assists.into_iter(); |
323 | 323 | ||
@@ -353,7 +353,7 @@ pub fn test_some_range(a: int) -> bool { | |||
353 | } | 353 | } |
354 | 354 | ||
355 | { | 355 | { |
356 | let assists = Assist::get( | 356 | let assists = assists( |
357 | &db, | 357 | &db, |
358 | &cfg, | 358 | &cfg, |
359 | AssistResolveStrategy::Single(SingleResolve { | 359 | AssistResolveStrategy::Single(SingleResolve { |
@@ -397,7 +397,7 @@ pub fn test_some_range(a: int) -> bool { | |||
397 | } | 397 | } |
398 | 398 | ||
399 | { | 399 | { |
400 | let assists = Assist::get( | 400 | let assists = assists( |
401 | &db, | 401 | &db, |
402 | &cfg, | 402 | &cfg, |
403 | AssistResolveStrategy::Single(SingleResolve { | 403 | AssistResolveStrategy::Single(SingleResolve { |
@@ -462,7 +462,7 @@ pub fn test_some_range(a: int) -> bool { | |||
462 | } | 462 | } |
463 | 463 | ||
464 | { | 464 | { |
465 | let assists = Assist::get(&db, &cfg, AssistResolveStrategy::All, frange); | 465 | let assists = assists(&db, &cfg, AssistResolveStrategy::All, frange); |
466 | assert_eq!(2, assists.len()); | 466 | assert_eq!(2, assists.len()); |
467 | let mut assists = assists.into_iter(); | 467 | let mut assists = assists.into_iter(); |
468 | 468 | ||
diff --git a/crates/ide_diagnostics/src/lib.rs b/crates/ide_diagnostics/src/lib.rs index a104a702d..0d98307a2 100644 --- a/crates/ide_diagnostics/src/lib.rs +++ b/crates/ide_diagnostics/src/lib.rs | |||
@@ -27,7 +27,6 @@ mod unresolved_proc_macro; | |||
27 | mod field_shorthand; | 27 | mod field_shorthand; |
28 | 28 | ||
29 | use hir::{diagnostics::AnyDiagnostic, Semantics}; | 29 | use hir::{diagnostics::AnyDiagnostic, Semantics}; |
30 | use ide_assists::AssistResolveStrategy; | ||
31 | use ide_db::{ | 30 | use ide_db::{ |
32 | base_db::{FileId, SourceDatabase}, | 31 | base_db::{FileId, SourceDatabase}, |
33 | label::Label, | 32 | label::Label, |
@@ -43,7 +42,7 @@ use syntax::{ | |||
43 | use text_edit::TextEdit; | 42 | use text_edit::TextEdit; |
44 | use unlinked_file::UnlinkedFile; | 43 | use unlinked_file::UnlinkedFile; |
45 | 44 | ||
46 | use ide_assists::{Assist, AssistId, AssistKind}; | 45 | use ide_assists::{Assist, AssistId, AssistKind, AssistResolveStrategy}; |
47 | 46 | ||
48 | #[derive(Copy, Clone, Debug, PartialEq)] | 47 | #[derive(Copy, Clone, Debug, PartialEq)] |
49 | pub struct DiagnosticCode(pub &'static str); | 48 | pub struct DiagnosticCode(pub &'static str); |