mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Apply the api design suggestions
This commit is contained in:
parent
73dc8b6f06
commit
78a21253b4
10 changed files with 97 additions and 59 deletions
|
@ -4,30 +4,37 @@ use ra_db::{FilePosition, FileRange};
|
|||
|
||||
use crate::{db::RootDatabase, FileId, SourceChange, SourceFileEdit};
|
||||
|
||||
use itertools::Either;
|
||||
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<SourceChange>,
|
||||
pub change_data: Either<SourceChange, Vec<SourceChange>>,
|
||||
}
|
||||
|
||||
pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> {
|
||||
ra_assists::assists(db, frange)
|
||||
.into_iter()
|
||||
.map(|(assist_label, action, alternative_actions)| {
|
||||
.map(|assist| {
|
||||
let file_id = frange.file_id;
|
||||
let assist_label = &assist.label;
|
||||
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(),
|
||||
change_data: match assist.action_data {
|
||||
Either::Left(action) => {
|
||||
Either::Left(action_to_edit(action, file_id, assist_label))
|
||||
}
|
||||
Either::Right(actions) => Either::Right(
|
||||
actions
|
||||
.into_iter()
|
||||
.map(|action| action_to_edit(action, file_id, assist_label))
|
||||
.collect(),
|
||||
),
|
||||
},
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue