From c6b81bc013b5278b917d109b723405e0df413323 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 7 May 2020 17:09:59 +0200 Subject: Rename AssitLabel -> Assist --- crates/ra_assists/src/assist_context.rs | 16 ++++++++-------- crates/ra_assists/src/lib.rs | 12 ++++++------ crates/ra_assists/src/tests.rs | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/assist_context.rs b/crates/ra_assists/src/assist_context.rs index 203ad1273..81052ab49 100644 --- a/crates/ra_assists/src/assist_context.rs +++ b/crates/ra_assists/src/assist_context.rs @@ -15,7 +15,7 @@ use ra_syntax::{ }; use ra_text_edit::TextEditBuilder; -use crate::{AssistId, AssistLabel, GroupLabel, ResolvedAssist}; +use crate::{Assist, AssistId, GroupLabel, ResolvedAssist}; /// `AssistContext` allows to apply an assist or check if it could be applied. /// @@ -91,7 +91,7 @@ impl<'a> AssistContext<'a> { pub(crate) struct Assists { resolve: bool, file: FileId, - buf: Vec<(AssistLabel, Option)>, + buf: Vec<(Assist, Option)>, } impl Assists { @@ -102,7 +102,7 @@ impl Assists { Assists { resolve: false, file: ctx.frange.file_id, buf: Vec::new() } } - pub(crate) fn finish_unresolved(self) -> Vec { + pub(crate) fn finish_unresolved(self) -> Vec { assert!(!self.resolve); self.finish() .into_iter() @@ -117,7 +117,7 @@ impl Assists { assert!(self.resolve); self.finish() .into_iter() - .map(|(label, edit)| ResolvedAssist { label, source_change: edit.unwrap() }) + .map(|(label, edit)| ResolvedAssist { assist: label, source_change: edit.unwrap() }) .collect() } @@ -128,7 +128,7 @@ impl Assists { target: TextRange, f: impl FnOnce(&mut AssistBuilder), ) -> Option<()> { - let label = AssistLabel::new(id, label.into(), None, target); + let label = Assist::new(id, label.into(), None, target); self.add_impl(label, f) } pub(crate) fn add_group( @@ -139,10 +139,10 @@ impl Assists { target: TextRange, f: impl FnOnce(&mut AssistBuilder), ) -> Option<()> { - let label = AssistLabel::new(id, label.into(), Some(group.clone()), target); + let label = Assist::new(id, label.into(), Some(group.clone()), target); self.add_impl(label, f) } - fn add_impl(&mut self, label: AssistLabel, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> { + fn add_impl(&mut self, label: Assist, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> { let change_label = label.label.clone(); let source_change = if self.resolve { let mut builder = AssistBuilder::new(self.file); @@ -156,7 +156,7 @@ impl Assists { Some(()) } - fn finish(mut self) -> Vec<(AssistLabel, Option)> { + fn finish(mut self) -> Vec<(Assist, Option)> { self.buf.sort_by_key(|(label, _edit)| label.target.len()); self.buf } diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 011613762..a91975d8c 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -30,7 +30,7 @@ pub(crate) use crate::assist_context::{AssistContext, Assists}; pub struct AssistId(pub &'static str); #[derive(Debug, Clone)] -pub struct AssistLabel { +pub struct Assist { pub id: AssistId, /// Short description of the assist, as shown in the UI. pub label: String, @@ -43,22 +43,22 @@ pub struct AssistLabel { #[derive(Clone, Debug)] pub struct GroupLabel(pub String); -impl AssistLabel { +impl Assist { pub(crate) fn new( id: AssistId, label: String, group: Option, target: TextRange, - ) -> AssistLabel { + ) -> Assist { // FIXME: make fields private, so that this invariant can't be broken assert!(label.starts_with(|c: char| c.is_uppercase())); - AssistLabel { id, label, group, target } + Assist { id, label, group, target } } } #[derive(Debug, Clone)] pub struct ResolvedAssist { - pub label: AssistLabel, + pub assist: Assist, pub source_change: SourceChange, } @@ -66,7 +66,7 @@ pub struct ResolvedAssist { /// /// Assists are returned in the "unresolved" state, that is only labels are /// returned, without actual edits. -pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec { +pub fn unresolved_assists(db: &RootDatabase, range: FileRange) -> Vec { let sema = Semantics::new(db); let ctx = AssistContext::new(sema, range); let mut acc = Assists::new_unresolved(&ctx); diff --git a/crates/ra_assists/src/tests.rs b/crates/ra_assists/src/tests.rs index 45b2d9733..a81c54d07 100644 --- a/crates/ra_assists/src/tests.rs +++ b/crates/ra_assists/src/tests.rs @@ -43,14 +43,14 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) { let mut assist = resolved_assists(&db, frange) .into_iter() - .find(|assist| assist.label.id.0 == assist_id) + .find(|assist| assist.assist.id.0 == assist_id) .unwrap_or_else(|| { panic!( "\n\nAssist is not applicable: {}\nAvailable assists: {}", assist_id, resolved_assists(&db, frange) .into_iter() - .map(|assist| assist.label.id.0) + .map(|assist| assist.assist.id.0) .collect::>() .join(", ") ) @@ -119,7 +119,7 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult) { assert_eq_text!(after, &actual); } (Some(assist), ExpectedResult::Target(target)) => { - let range = assist.label.target; + let range = assist.assist.target; assert_eq_text!(&text_without_caret[range], target); } (Some(_), ExpectedResult::NotApplicable) => panic!("assist should not be applicable!"), @@ -140,10 +140,10 @@ fn assist_order_field_struct() { let mut assists = assists.iter(); assert_eq!( - assists.next().expect("expected assist").label.label, + assists.next().expect("expected assist").assist.label, "Change visibility to pub(crate)" ); - assert_eq!(assists.next().expect("expected assist").label.label, "Add `#[derive]`"); + assert_eq!(assists.next().expect("expected assist").assist.label, "Add `#[derive]`"); } #[test] @@ -162,6 +162,6 @@ fn assist_order_if_expr() { let assists = resolved_assists(&db, frange); let mut assists = assists.iter(); - assert_eq!(assists.next().expect("expected assist").label.label, "Extract into variable"); - assert_eq!(assists.next().expect("expected assist").label.label, "Replace with match"); + assert_eq!(assists.next().expect("expected assist").assist.label, "Extract into variable"); + assert_eq!(assists.next().expect("expected assist").assist.label, "Replace with match"); } -- cgit v1.2.3