rust-analyzer/crates/ra_ide_api/src/assists.rs

29 lines
837 B
Rust
Raw Normal View History

//! FIXME: write short doc here
use ra_db::{FilePosition, FileRange};
2019-02-03 18:26:35 +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;
let change = SourceChange::source_file_edit(label.label, file_edit).with_cursor_opt(
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()
}