This commit is contained in:
Aleksey Kladov 2020-05-06 16:01:47 +02:00
parent fdd4df97ba
commit 0970c3454b
4 changed files with 13 additions and 13 deletions

View file

@ -22,16 +22,16 @@ pub(crate) struct Assist(pub(crate) Vec<AssistInfo>);
pub(crate) struct AssistInfo { pub(crate) struct AssistInfo {
pub(crate) label: AssistLabel, pub(crate) label: AssistLabel,
pub(crate) group_label: Option<GroupLabel>, pub(crate) group_label: Option<GroupLabel>,
pub(crate) action: Option<SourceChange>, pub(crate) source_change: Option<SourceChange>,
} }
impl AssistInfo { impl AssistInfo {
fn new(label: AssistLabel) -> AssistInfo { fn new(label: AssistLabel) -> AssistInfo {
AssistInfo { label, group_label: None, action: None } AssistInfo { label, group_label: None, source_change: None }
} }
fn resolved(self, action: SourceChange) -> AssistInfo { fn resolved(self, source_change: SourceChange) -> AssistInfo {
AssistInfo { action: Some(action), ..self } AssistInfo { source_change: Some(source_change), ..self }
} }
fn with_group(self, group_label: GroupLabel) -> AssistInfo { fn with_group(self, group_label: GroupLabel) -> AssistInfo {
@ -40,7 +40,7 @@ impl AssistInfo {
pub(crate) fn into_resolved(self) -> Option<ResolvedAssist> { pub(crate) fn into_resolved(self) -> Option<ResolvedAssist> {
let label = self.label; let label = self.label;
self.action.map(|action| ResolvedAssist { label, action }) self.source_change.map(|source_change| ResolvedAssist { label, source_change })
} }
} }
@ -104,12 +104,12 @@ impl<'a> AssistCtx<'a> {
let change_label = label.label.clone(); let change_label = label.label.clone();
let mut info = AssistInfo::new(label); let mut info = AssistInfo::new(label);
if self.should_compute_edit { if self.should_compute_edit {
let action = { let source_change = {
let mut edit = ActionBuilder::new(&self); let mut edit = ActionBuilder::new(&self);
f(&mut edit); f(&mut edit);
edit.build(change_label, self.frange.file_id) edit.build(change_label, self.frange.file_id)
}; };
info = info.resolved(action) info = info.resolved(source_change)
}; };
Some(Assist(vec![info])) Some(Assist(vec![info]))
@ -163,12 +163,12 @@ impl<'a> AssistGroup<'a> {
let change_label = label.label.clone(); let change_label = label.label.clone();
let mut info = AssistInfo::new(label).with_group(self.group.clone()); let mut info = AssistInfo::new(label).with_group(self.group.clone());
if self.ctx.should_compute_edit { if self.ctx.should_compute_edit {
let action = { let source_change = {
let mut edit = ActionBuilder::new(&self.ctx); let mut edit = ActionBuilder::new(&self.ctx);
f(&mut edit); f(&mut edit);
edit.build(change_label, self.ctx.frange.file_id) edit.build(change_label, self.ctx.frange.file_id)
}; };
info = info.resolved(action) info = info.resolved(source_change)
}; };
self.assists.push(info) self.assists.push(info)

View file

@ -59,7 +59,7 @@ impl AssistLabel {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ResolvedAssist { pub struct ResolvedAssist {
pub label: AssistLabel, pub label: AssistLabel,
pub action: SourceChange, pub source_change: SourceChange,
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]

View file

@ -57,7 +57,7 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) {
}); });
let actual = { let actual = {
let change = assist.action.source_file_edits.pop().unwrap(); let change = assist.source_change.source_file_edits.pop().unwrap();
let mut actual = before.clone(); let mut actual = before.clone();
change.edit.apply(&mut actual); change.edit.apply(&mut actual);
actual actual
@ -94,7 +94,7 @@ fn check(assist: Handler, before: &str, expected: ExpectedResult) {
match (assist(assist_ctx), expected) { match (assist(assist_ctx), expected) {
(Some(assist), ExpectedResult::After(after)) => { (Some(assist), ExpectedResult::After(after)) => {
let mut action = assist.0[0].action.clone().unwrap(); let mut action = assist.0[0].source_change.clone().unwrap();
let change = action.source_file_edits.pop().unwrap(); let change = action.source_file_edits.pop().unwrap();
let mut actual = db.file_text(change.file_id).as_ref().to_owned(); let mut actual = db.file_text(change.file_id).as_ref().to_owned();

View file

@ -478,7 +478,7 @@ impl Analysis {
id: assist.label.id, id: assist.label.id,
label: assist.label.label, label: assist.label.label,
group_label: assist.label.group.map(|it| it.0), group_label: assist.label.group.map(|it| it.0),
source_change: assist.action, source_change: assist.source_change,
}) })
.collect() .collect()
}) })