aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/assist_ctx.rs14
-rw-r--r--crates/ra_assists/src/lib.rs10
2 files changed, 12 insertions, 12 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs
index da2880037..82f61bc8f 100644
--- a/crates/ra_assists/src/assist_ctx.rs
+++ b/crates/ra_assists/src/assist_ctx.rs
@@ -38,8 +38,7 @@ impl AssistInfo {
38 38
39 pub(crate) fn into_resolved(self) -> Option<ResolvedAssist> { 39 pub(crate) fn into_resolved(self) -> Option<ResolvedAssist> {
40 let label = self.label; 40 let label = self.label;
41 let group_label = self.group_label; 41 self.action.map(|action| ResolvedAssist { label, action })
42 self.action.map(|action| ResolvedAssist { label, group_label, action })
43 } 42 }
44} 43}
45 44
@@ -100,7 +99,7 @@ impl<'a> AssistCtx<'a> {
100 label: impl Into<String>, 99 label: impl Into<String>,
101 f: impl FnOnce(&mut ActionBuilder), 100 f: impl FnOnce(&mut ActionBuilder),
102 ) -> Option<Assist> { 101 ) -> Option<Assist> {
103 let label = AssistLabel::new(label.into(), id); 102 let label = AssistLabel::new(id, label.into(), None);
104 103
105 let mut info = AssistInfo::new(label); 104 let mut info = AssistInfo::new(label);
106 if self.should_compute_edit { 105 if self.should_compute_edit {
@@ -116,7 +115,8 @@ impl<'a> AssistCtx<'a> {
116 } 115 }
117 116
118 pub(crate) fn add_assist_group(self, group_name: impl Into<String>) -> AssistGroup<'a> { 117 pub(crate) fn add_assist_group(self, group_name: impl Into<String>) -> AssistGroup<'a> {
119 AssistGroup { ctx: self, group_name: group_name.into(), assists: Vec::new() } 118 let group = GroupLabel(group_name.into());
119 AssistGroup { ctx: self, group, assists: Vec::new() }
120 } 120 }
121 121
122 pub(crate) fn token_at_offset(&self) -> TokenAtOffset<SyntaxToken> { 122 pub(crate) fn token_at_offset(&self) -> TokenAtOffset<SyntaxToken> {
@@ -146,7 +146,7 @@ impl<'a> AssistCtx<'a> {
146 146
147pub(crate) struct AssistGroup<'a> { 147pub(crate) struct AssistGroup<'a> {
148 ctx: AssistCtx<'a>, 148 ctx: AssistCtx<'a>,
149 group_name: String, 149 group: GroupLabel,
150 assists: Vec<AssistInfo>, 150 assists: Vec<AssistInfo>,
151} 151}
152 152
@@ -157,9 +157,9 @@ impl<'a> AssistGroup<'a> {
157 label: impl Into<String>, 157 label: impl Into<String>,
158 f: impl FnOnce(&mut ActionBuilder), 158 f: impl FnOnce(&mut ActionBuilder),
159 ) { 159 ) {
160 let label = AssistLabel::new(label.into(), id); 160 let label = AssistLabel::new(id, label.into(), Some(self.group.clone()));
161 161
162 let mut info = AssistInfo::new(label).with_group(GroupLabel(self.group_name.clone())); 162 let mut info = AssistInfo::new(label).with_group(self.group.clone());
163 if self.ctx.should_compute_edit { 163 if self.ctx.should_compute_edit {
164 let action = { 164 let action = {
165 let mut edit = ActionBuilder::new(&self.ctx); 165 let mut edit = ActionBuilder::new(&self.ctx);
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index c5df86600..5cec10088 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -17,13 +17,13 @@ mod doc_tests;
17pub mod utils; 17pub mod utils;
18pub mod ast_transform; 18pub mod ast_transform;
19 19
20use hir::Semantics;
20use ra_db::{FileId, FileRange}; 21use ra_db::{FileId, FileRange};
21use ra_ide_db::RootDatabase; 22use ra_ide_db::RootDatabase;
22use ra_syntax::{TextRange, TextSize}; 23use ra_syntax::{TextRange, TextSize};
23use ra_text_edit::TextEdit; 24use ra_text_edit::TextEdit;
24 25
25pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler}; 26pub(crate) use crate::assist_ctx::{Assist, AssistCtx, AssistHandler};
26use hir::Semantics;
27 27
28/// Unique identifier of the assist, should not be shown to the user 28/// Unique identifier of the assist, should not be shown to the user
29/// directly. 29/// directly.
@@ -32,19 +32,20 @@ pub struct AssistId(pub &'static str);
32 32
33#[derive(Debug, Clone)] 33#[derive(Debug, Clone)]
34pub struct AssistLabel { 34pub struct AssistLabel {
35 pub id: AssistId,
35 /// Short description of the assist, as shown in the UI. 36 /// Short description of the assist, as shown in the UI.
36 pub label: String, 37 pub label: String,
37 pub id: AssistId, 38 pub group: Option<GroupLabel>,
38} 39}
39 40
40#[derive(Clone, Debug)] 41#[derive(Clone, Debug)]
41pub struct GroupLabel(pub String); 42pub struct GroupLabel(pub String);
42 43
43impl AssistLabel { 44impl AssistLabel {
44 pub(crate) fn new(label: String, id: AssistId) -> AssistLabel { 45 pub(crate) fn new(id: AssistId, label: String, group: Option<GroupLabel>) -> AssistLabel {
45 // FIXME: make fields private, so that this invariant can't be broken 46 // FIXME: make fields private, so that this invariant can't be broken
46 assert!(label.starts_with(|c: char| c.is_uppercase())); 47 assert!(label.starts_with(|c: char| c.is_uppercase()));
47 AssistLabel { label, id } 48 AssistLabel { id, label, group }
48 } 49 }
49} 50}
50 51
@@ -60,7 +61,6 @@ pub struct AssistAction {
60#[derive(Debug, Clone)] 61#[derive(Debug, Clone)]
61pub struct ResolvedAssist { 62pub struct ResolvedAssist {
62 pub label: AssistLabel, 63 pub label: AssistLabel,
63 pub group_label: Option<GroupLabel>,
64 pub action: AssistAction, 64 pub action: AssistAction,
65} 65}
66 66