From aa1a7a5414e59c7f1c6e74002df1b6a04937459e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 18 Aug 2020 16:41:21 +0200 Subject: Introduce Label --- crates/assists/src/assist_context.rs | 16 +++++++++------- crates/assists/src/lib.rs | 13 ++----------- 2 files changed, 11 insertions(+), 18 deletions(-) (limited to 'crates/assists') diff --git a/crates/assists/src/assist_context.rs b/crates/assists/src/assist_context.rs index 79574b9ac..11c171fc2 100644 --- a/crates/assists/src/assist_context.rs +++ b/crates/assists/src/assist_context.rs @@ -6,6 +6,7 @@ use algo::find_covering_element; use base_db::{FileId, FileRange}; use hir::Semantics; use ide_db::{ + label::Label, source_change::{SourceChange, SourceFileEdit}, RootDatabase, }; @@ -157,8 +158,9 @@ impl Assists { if !self.is_allowed(&id) { return None; } - let label = Assist::new(id, label.into(), None, target); - self.add_impl(label, f) + let label = Label::new(label.into()); + let assist = Assist { id, label, group: None, target }; + self.add_impl(assist, f) } pub(crate) fn add_group( @@ -172,12 +174,12 @@ impl Assists { if !self.is_allowed(&id) { return None; } - - let label = Assist::new(id, label.into(), Some(group.clone()), target); - self.add_impl(label, f) + let label = Label::new(label.into()); + let assist = Assist { id, label, group: Some(group.clone()), target }; + self.add_impl(assist, f) } - fn add_impl(&mut self, label: Assist, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> { + fn add_impl(&mut self, assist: Assist, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> { let source_change = if self.resolve { let mut builder = AssistBuilder::new(self.file); f(&mut builder); @@ -186,7 +188,7 @@ impl Assists { None }; - self.buf.push((label, source_change)); + self.buf.push((assist, source_change)); Some(()) } diff --git a/crates/assists/src/lib.rs b/crates/assists/src/lib.rs index c589b08dc..14834480a 100644 --- a/crates/assists/src/lib.rs +++ b/crates/assists/src/lib.rs @@ -19,7 +19,7 @@ pub mod ast_transform; use base_db::FileRange; use hir::Semantics; -use ide_db::{source_change::SourceChange, RootDatabase}; +use ide_db::{label::Label, source_change::SourceChange, RootDatabase}; use syntax::TextRange; pub(crate) use crate::assist_context::{AssistContext, Assists}; @@ -68,7 +68,7 @@ pub struct GroupLabel(pub String); pub struct Assist { pub id: AssistId, /// Short description of the assist, as shown in the UI. - label: String, + pub label: Label, pub group: Option, /// Target ranges are used to sort assists: the smaller the target range, /// the more specific assist is, and so it should be sorted first. @@ -82,11 +82,6 @@ pub struct ResolvedAssist { } impl Assist { - fn new(id: AssistId, label: String, group: Option, target: TextRange) -> Assist { - assert!(label.starts_with(char::is_uppercase)); - Assist { id, label, group, target } - } - /// Return all the assists applicable at the given position. /// /// Assists are returned in the "unresolved" state, that is only labels are @@ -118,10 +113,6 @@ impl Assist { }); acc.finish_resolved() } - - pub fn label(&self) -> &str { - self.label.as_str() - } } mod handlers { -- cgit v1.2.3