diff options
author | Aleksey Kladov <[email protected]> | 2020-08-18 15:41:21 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-08-18 15:50:07 +0100 |
commit | aa1a7a5414e59c7f1c6e74002df1b6a04937459e (patch) | |
tree | 6d112b6a8614138ebffa8bef0b27d90f8ef2cef9 /crates/assists | |
parent | eb81731600d1bc50efc00e32b9fc2244a2af52ad (diff) |
Introduce Label
Diffstat (limited to 'crates/assists')
-rw-r--r-- | crates/assists/src/assist_context.rs | 16 | ||||
-rw-r--r-- | crates/assists/src/lib.rs | 13 |
2 files changed, 11 insertions, 18 deletions
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; | |||
6 | use base_db::{FileId, FileRange}; | 6 | use base_db::{FileId, FileRange}; |
7 | use hir::Semantics; | 7 | use hir::Semantics; |
8 | use ide_db::{ | 8 | use ide_db::{ |
9 | label::Label, | ||
9 | source_change::{SourceChange, SourceFileEdit}, | 10 | source_change::{SourceChange, SourceFileEdit}, |
10 | RootDatabase, | 11 | RootDatabase, |
11 | }; | 12 | }; |
@@ -157,8 +158,9 @@ impl Assists { | |||
157 | if !self.is_allowed(&id) { | 158 | if !self.is_allowed(&id) { |
158 | return None; | 159 | return None; |
159 | } | 160 | } |
160 | let label = Assist::new(id, label.into(), None, target); | 161 | let label = Label::new(label.into()); |
161 | self.add_impl(label, f) | 162 | let assist = Assist { id, label, group: None, target }; |
163 | self.add_impl(assist, f) | ||
162 | } | 164 | } |
163 | 165 | ||
164 | pub(crate) fn add_group( | 166 | pub(crate) fn add_group( |
@@ -172,12 +174,12 @@ impl Assists { | |||
172 | if !self.is_allowed(&id) { | 174 | if !self.is_allowed(&id) { |
173 | return None; | 175 | return None; |
174 | } | 176 | } |
175 | 177 | let label = Label::new(label.into()); | |
176 | let label = Assist::new(id, label.into(), Some(group.clone()), target); | 178 | let assist = Assist { id, label, group: Some(group.clone()), target }; |
177 | self.add_impl(label, f) | 179 | self.add_impl(assist, f) |
178 | } | 180 | } |
179 | 181 | ||
180 | fn add_impl(&mut self, label: Assist, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> { | 182 | fn add_impl(&mut self, assist: Assist, f: impl FnOnce(&mut AssistBuilder)) -> Option<()> { |
181 | let source_change = if self.resolve { | 183 | let source_change = if self.resolve { |
182 | let mut builder = AssistBuilder::new(self.file); | 184 | let mut builder = AssistBuilder::new(self.file); |
183 | f(&mut builder); | 185 | f(&mut builder); |
@@ -186,7 +188,7 @@ impl Assists { | |||
186 | None | 188 | None |
187 | }; | 189 | }; |
188 | 190 | ||
189 | self.buf.push((label, source_change)); | 191 | self.buf.push((assist, source_change)); |
190 | Some(()) | 192 | Some(()) |
191 | } | 193 | } |
192 | 194 | ||
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; | |||
19 | 19 | ||
20 | use base_db::FileRange; | 20 | use base_db::FileRange; |
21 | use hir::Semantics; | 21 | use hir::Semantics; |
22 | use ide_db::{source_change::SourceChange, RootDatabase}; | 22 | use ide_db::{label::Label, source_change::SourceChange, RootDatabase}; |
23 | use syntax::TextRange; | 23 | use syntax::TextRange; |
24 | 24 | ||
25 | pub(crate) use crate::assist_context::{AssistContext, Assists}; | 25 | pub(crate) use crate::assist_context::{AssistContext, Assists}; |
@@ -68,7 +68,7 @@ pub struct GroupLabel(pub String); | |||
68 | pub struct Assist { | 68 | pub struct Assist { |
69 | pub id: AssistId, | 69 | pub id: AssistId, |
70 | /// Short description of the assist, as shown in the UI. | 70 | /// Short description of the assist, as shown in the UI. |
71 | label: String, | 71 | pub label: Label, |
72 | pub group: Option<GroupLabel>, | 72 | pub group: Option<GroupLabel>, |
73 | /// Target ranges are used to sort assists: the smaller the target range, | 73 | /// Target ranges are used to sort assists: the smaller the target range, |
74 | /// the more specific assist is, and so it should be sorted first. | 74 | /// the more specific assist is, and so it should be sorted first. |
@@ -82,11 +82,6 @@ pub struct ResolvedAssist { | |||
82 | } | 82 | } |
83 | 83 | ||
84 | impl Assist { | 84 | impl Assist { |
85 | fn new(id: AssistId, label: String, group: Option<GroupLabel>, target: TextRange) -> Assist { | ||
86 | assert!(label.starts_with(char::is_uppercase)); | ||
87 | Assist { id, label, group, target } | ||
88 | } | ||
89 | |||
90 | /// Return all the assists applicable at the given position. | 85 | /// Return all the assists applicable at the given position. |
91 | /// | 86 | /// |
92 | /// Assists are returned in the "unresolved" state, that is only labels are | 87 | /// Assists are returned in the "unresolved" state, that is only labels are |
@@ -118,10 +113,6 @@ impl Assist { | |||
118 | }); | 113 | }); |
119 | acc.finish_resolved() | 114 | acc.finish_resolved() |
120 | } | 115 | } |
121 | |||
122 | pub fn label(&self) -> &str { | ||
123 | self.label.as_str() | ||
124 | } | ||
125 | } | 116 | } |
126 | 117 | ||
127 | mod handlers { | 118 | mod handlers { |