aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/assists.rs
blob: 3c0475a51c7f735b881cd41ccdfb8ac3d77469b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use ra_db::{FileRange, FilePosition};

use crate::{SourceFileEdit, SourceChange, db::RootDatabase};

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> {
    ra_assists::assists(db, frange)
        .into_iter()
        .map(|(label, action)| {
            let file_id = frange.file_id;
            let file_edit = SourceFileEdit { file_id, edit: action.edit };
            let id = label.id;
            let change = SourceChange {
                label: label.label,
                source_file_edits: vec![file_edit],
                file_system_edits: vec![],
                cursor_position: action
                    .cursor_position
                    .map(|offset| FilePosition { offset, file_id }),
            };
            Assist { id, change }
        })
        .collect()
}