From 73dc8b6f06b49f4728a50e83781c361e9a8b3100 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 2 Jan 2020 01:39:01 +0200 Subject: Another attempt to add multiple edits --- crates/ra_ide/src/assists.rs | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/assists.rs b/crates/ra_ide/src/assists.rs index e00589733..db6e4e8b7 100644 --- a/crates/ra_ide/src/assists.rs +++ b/crates/ra_ide/src/assists.rs @@ -2,27 +2,46 @@ use ra_db::{FilePosition, FileRange}; -use crate::{db::RootDatabase, SourceChange, SourceFileEdit}; +use crate::{db::RootDatabase, FileId, SourceChange, SourceFileEdit}; pub use ra_assists::AssistId; +use ra_assists::{AssistAction, AssistLabel}; #[derive(Debug)] pub struct Assist { pub id: AssistId, pub change: SourceChange, + pub label: String, + pub alternative_changes: Vec, } pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec { ra_assists::assists(db, frange) .into_iter() - .map(|(label, action)| { + .map(|(assist_label, action, alternative_actions)| { let file_id = frange.file_id; - let file_edit = SourceFileEdit { file_id, edit: action.edit }; - let id = label.id; - let change = SourceChange::source_file_edit(label.label, file_edit).with_cursor_opt( - action.cursor_position.map(|offset| FilePosition { offset, file_id }), - ); - Assist { id, change } + Assist { + id: assist_label.id, + label: assist_label.label.clone(), + change: action_to_edit(action, file_id, &assist_label), + alternative_changes: alternative_actions + .into_iter() + .map(|action| action_to_edit(action, file_id, &assist_label)) + .collect(), + } }) .collect() } + +fn action_to_edit( + action: AssistAction, + file_id: FileId, + assist_label: &AssistLabel, +) -> SourceChange { + let file_edit = SourceFileEdit { file_id, edit: action.edit }; + SourceChange::source_file_edit( + action.label.unwrap_or_else(|| assist_label.label.clone()), + file_edit, + ) + .with_cursor_opt(action.cursor_position.map(|offset| FilePosition { offset, file_id })) +} -- cgit v1.2.3