2019-09-30 08:58:53 +00:00
|
|
|
//! FIXME: write short doc here
|
|
|
|
|
2019-07-04 20:05:17 +00:00
|
|
|
use ra_db::{FilePosition, FileRange};
|
2019-02-03 18:26:35 +00:00
|
|
|
|
2019-07-04 20:05:17 +00:00
|
|
|
use crate::{db::RootDatabase, SourceChange, SourceFileEdit};
|
2019-02-03 18:26:35 +00:00
|
|
|
|
2019-02-24 10:53:35 +00:00
|
|
|
pub use ra_assists::AssistId;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Assist {
|
|
|
|
pub id: AssistId,
|
|
|
|
pub change: SourceChange,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> {
|
2019-02-03 18:26:35 +00:00
|
|
|
ra_assists::assists(db, frange)
|
|
|
|
.into_iter()
|
|
|
|
.map(|(label, action)| {
|
|
|
|
let file_id = frange.file_id;
|
2019-02-08 11:49:43 +00:00
|
|
|
let file_edit = SourceFileEdit { file_id, edit: action.edit };
|
2019-02-24 10:53:35 +00:00
|
|
|
let id = label.id;
|
2019-03-25 07:13:58 +00:00
|
|
|
let change = SourceChange::source_file_edit(label.label, file_edit).with_cursor_opt(
|
2019-03-24 20:53:41 +00:00
|
|
|
action.cursor_position.map(|offset| FilePosition { offset, file_id }),
|
|
|
|
);
|
2019-02-24 10:53:35 +00:00
|
|
|
Assist { id, change }
|
2019-02-03 18:26:35 +00:00
|
|
|
})
|
2019-02-03 16:27:36 +00:00
|
|
|
.collect()
|
|
|
|
}
|