From ef442b8682909f2ab758f55507d4c2e81673cfa1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Feb 2019 13:53:35 +0300 Subject: Assign IDs to assists --- crates/ra_ide_api/src/assists.rs | 16 +++++++++++++--- crates/ra_ide_api/src/lib.rs | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/assists.rs b/crates/ra_ide_api/src/assists.rs index 7a9c66681..3c0475a51 100644 --- a/crates/ra_ide_api/src/assists.rs +++ b/crates/ra_ide_api/src/assists.rs @@ -2,20 +2,30 @@ use ra_db::{FileRange, FilePosition}; use crate::{SourceFileEdit, SourceChange, db::RootDatabase}; -pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec { +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 { 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 }; - SourceChange { + 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() } diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 4b9fc9372..076a8396c 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -57,6 +57,7 @@ pub use crate::{ runnables::{Runnable, RunnableKind}, navigation_target::NavigationTarget, references::ReferenceSearchResult, + assists::{Assist, AssistId}, }; pub use ra_ide_api_light::{ Fold, FoldKind, HighlightedRange, Severity, StructureNode, LocalEdit, @@ -368,7 +369,7 @@ impl Analysis { /// Computes assists (aks code actons aka intentions) for the given /// position. - pub fn assists(&self, frange: FileRange) -> Cancelable> { + pub fn assists(&self, frange: FileRange) -> Cancelable> { self.with_db(|db| assists::assists(db, frange)) } -- cgit v1.2.3