From 2e8dab631b4ab429eeade7f5302e8de9dcd0b398 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 14 Jun 2021 13:18:03 +0300 Subject: internal: prepare to move assist definitions --- crates/ide_assists/src/lib.rs | 30 ++++++++++++++---------------- crates/ide_assists/src/tests.rs | 26 +++++++++++++------------- 2 files changed, 27 insertions(+), 29 deletions(-) (limited to 'crates/ide_assists') 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 { pub source_change: Option, } -impl Assist { - /// Return all the assists applicable at the given position. - pub fn get( - db: &RootDatabase, - config: &AssistConfig, - resolve: AssistResolveStrategy, - range: FileRange, - ) -> Vec { - let sema = Semantics::new(db); - let ctx = AssistContext::new(sema, config, range); - let mut acc = Assists::new(&ctx, resolve); - handlers::all().iter().for_each(|handler| { - handler(&mut acc, &ctx); - }); - acc.finish() - } +/// Return all the assists applicable at the given position. +pub fn assists( + db: &RootDatabase, + config: &AssistConfig, + resolve: AssistResolveStrategy, + range: FileRange, +) -> Vec { + let sema = Semantics::new(db); + let ctx = AssistContext::new(sema, config, range); + let mut acc = Assists::new(&ctx, resolve); + handlers::all().iter().for_each(|handler| { + handler(&mut acc, &ctx); + }); + acc.finish() } 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; use test_utils::{assert_eq_text, extract_offset}; use crate::{ - handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, AssistResolveStrategy, - Assists, SingleResolve, + assists, handlers::Handler, Assist, AssistConfig, AssistContext, AssistKind, + AssistResolveStrategy, Assists, SingleResolve, }; pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig { @@ -78,14 +78,14 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) { let before = db.file_text(file_id).to_string(); let frange = FileRange { file_id, range: selection.into() }; - let assist = Assist::get(&db, &TEST_CONFIG, AssistResolveStrategy::All, frange) + let assist = assists(&db, &TEST_CONFIG, AssistResolveStrategy::All, frange) .into_iter() .find(|assist| assist.id.0 == assist_id) .unwrap_or_else(|| { panic!( "\n\nAssist is not applicable: {}\nAvailable assists: {}", assist_id, - Assist::get(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange) + assists(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange) .into_iter() .map(|assist| assist.id.0) .collect::>() @@ -210,7 +210,7 @@ fn assist_order_field_struct() { let (before_cursor_pos, before) = extract_offset(before); let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; - let assists = Assist::get(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange); + let assists = assists(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange); let mut assists = assists.iter(); 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 { "#, ); - let assists = Assist::get(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange); + let assists = assists(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange); let expected = labels(&assists); expect![[r#" @@ -264,7 +264,7 @@ pub fn test_some_range(a: int) -> bool { let mut cfg = TEST_CONFIG; cfg.allowed = Some(vec![AssistKind::Refactor]); - let assists = Assist::get(&db, &cfg, AssistResolveStrategy::None, frange); + let assists = assists(&db, &cfg, AssistResolveStrategy::None, frange); let expected = labels(&assists); expect![[r#" @@ -279,7 +279,7 @@ pub fn test_some_range(a: int) -> bool { { let mut cfg = TEST_CONFIG; cfg.allowed = Some(vec![AssistKind::RefactorExtract]); - let assists = Assist::get(&db, &cfg, AssistResolveStrategy::None, frange); + let assists = assists(&db, &cfg, AssistResolveStrategy::None, frange); let expected = labels(&assists); expect![[r#" @@ -292,7 +292,7 @@ pub fn test_some_range(a: int) -> bool { { let mut cfg = TEST_CONFIG; cfg.allowed = Some(vec![AssistKind::QuickFix]); - let assists = Assist::get(&db, &cfg, AssistResolveStrategy::None, frange); + let assists = assists(&db, &cfg, AssistResolveStrategy::None, frange); let expected = labels(&assists); expect![[r#""#]].assert_eq(&expected); @@ -317,7 +317,7 @@ pub fn test_some_range(a: int) -> bool { cfg.allowed = Some(vec![AssistKind::RefactorExtract]); { - let assists = Assist::get(&db, &cfg, AssistResolveStrategy::None, frange); + let assists = assists(&db, &cfg, AssistResolveStrategy::None, frange); assert_eq!(2, assists.len()); let mut assists = assists.into_iter(); @@ -353,7 +353,7 @@ pub fn test_some_range(a: int) -> bool { } { - let assists = Assist::get( + let assists = assists( &db, &cfg, AssistResolveStrategy::Single(SingleResolve { @@ -397,7 +397,7 @@ pub fn test_some_range(a: int) -> bool { } { - let assists = Assist::get( + let assists = assists( &db, &cfg, AssistResolveStrategy::Single(SingleResolve { @@ -462,7 +462,7 @@ pub fn test_some_range(a: int) -> bool { } { - let assists = Assist::get(&db, &cfg, AssistResolveStrategy::All, frange); + let assists = assists(&db, &cfg, AssistResolveStrategy::All, frange); assert_eq!(2, assists.len()); let mut assists = assists.into_iter(); -- cgit v1.2.3