aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion/completion_item.rs
diff options
context:
space:
mode:
authorgfreezy <[email protected]>2019-01-20 04:02:00 +0000
committergfreezy <[email protected]>2019-01-20 04:02:00 +0000
commit2a43638052213d1faa690e6d68bd5702e44fa027 (patch)
tree38cb979816dcdff9b9847592a1f99193f0bda70b /crates/ra_ide_api/src/completion/completion_item.rs
parent94d96b60f334e662f516bd0f04cc4191d7a804e6 (diff)
use a combination of `source_change` and `text_edit` for `CompleteItem`
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_item.rs')
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs30
1 files changed, 18 insertions, 12 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index da8da94d1..f46d9e581 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -2,6 +2,7 @@ use hir::PerNs;
2 2
3use crate::completion::completion_context::CompletionContext; 3use crate::completion::completion_context::CompletionContext;
4use ra_syntax::TextRange; 4use ra_syntax::TextRange;
5use ra_text_edit::TextEdit;
5 6
6/// `CompletionItem` describes a single completion variant in the editor pop-up. 7/// `CompletionItem` describes a single completion variant in the editor pop-up.
7/// It is basically a POD with various properties. To construct a 8/// It is basically a POD with various properties. To construct a
@@ -17,8 +18,8 @@ pub struct CompletionItem {
17 lookup: Option<String>, 18 lookup: Option<String>,
18 insert_text: Option<String>, 19 insert_text: Option<String>,
19 insert_text_format: InsertTextFormat, 20 insert_text_format: InsertTextFormat,
20 replace_range: TextRange, 21 source_range: TextRange,
21 delete_range: Option<TextRange>, 22 text_edit: Option<TextEdit>,
22} 23}
23 24
24#[derive(Debug, Clone, Copy, PartialEq, Eq)] 25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -64,7 +65,7 @@ impl CompletionItem {
64 ) -> Builder { 65 ) -> Builder {
65 let label = label.into(); 66 let label = label.into();
66 Builder { 67 Builder {
67 replace_range, 68 source_range: replace_range,
68 completion_kind, 69 completion_kind,
69 label, 70 label,
70 insert_text: None, 71 insert_text: None,
@@ -72,7 +73,7 @@ impl CompletionItem {
72 detail: None, 73 detail: None,
73 lookup: None, 74 lookup: None,
74 kind: None, 75 kind: None,
75 delete_range: None, 76 text_edit: None,
76 } 77 }
77 } 78 }
78 /// What user sees in pop-up in the UI. 79 /// What user sees in pop-up in the UI.
@@ -103,18 +104,18 @@ impl CompletionItem {
103 pub fn kind(&self) -> Option<CompletionItemKind> { 104 pub fn kind(&self) -> Option<CompletionItemKind> {
104 self.kind 105 self.kind
105 } 106 }
106 pub fn delete_range(&self) -> Option<TextRange> { 107 pub fn take_text_edit(&mut self) -> Option<TextEdit> {
107 self.delete_range 108 self.text_edit.take()
108 } 109 }
109 pub fn replace_range(&self) -> TextRange { 110 pub fn source_range(&self) -> TextRange {
110 self.replace_range 111 self.source_range
111 } 112 }
112} 113}
113 114
114/// A helper to make `CompletionItem`s. 115/// A helper to make `CompletionItem`s.
115#[must_use] 116#[must_use]
116pub(crate) struct Builder { 117pub(crate) struct Builder {
117 replace_range: TextRange, 118 source_range: TextRange,
118 completion_kind: CompletionKind, 119 completion_kind: CompletionKind,
119 label: String, 120 label: String,
120 insert_text: Option<String>, 121 insert_text: Option<String>,
@@ -122,7 +123,7 @@ pub(crate) struct Builder {
122 detail: Option<String>, 123 detail: Option<String>,
123 lookup: Option<String>, 124 lookup: Option<String>,
124 kind: Option<CompletionItemKind>, 125 kind: Option<CompletionItemKind>,
125 delete_range: Option<TextRange>, 126 text_edit: Option<TextEdit>,
126} 127}
127 128
128impl Builder { 129impl Builder {
@@ -132,14 +133,14 @@ impl Builder {
132 133
133 pub(crate) fn build(self) -> CompletionItem { 134 pub(crate) fn build(self) -> CompletionItem {
134 CompletionItem { 135 CompletionItem {
135 replace_range: self.replace_range, 136 source_range: self.source_range,
136 label: self.label, 137 label: self.label,
137 detail: self.detail, 138 detail: self.detail,
138 insert_text_format: self.insert_text_format, 139 insert_text_format: self.insert_text_format,
139 lookup: self.lookup, 140 lookup: self.lookup,
140 kind: self.kind, 141 kind: self.kind,
141 completion_kind: self.completion_kind, 142 completion_kind: self.completion_kind,
142 delete_range: self.delete_range, 143 text_edit: self.text_edit,
143 insert_text: self.insert_text, 144 insert_text: self.insert_text,
144 } 145 }
145 } 146 }
@@ -165,6 +166,11 @@ impl Builder {
165 self 166 self
166 } 167 }
167 #[allow(unused)] 168 #[allow(unused)]
169 pub(crate) fn text_edit(mut self, edit: TextEdit) -> Builder {
170 self.text_edit = Some(edit);
171 self
172 }
173 #[allow(unused)]
168 pub(crate) fn detail(self, detail: impl Into<String>) -> Builder { 174 pub(crate) fn detail(self, detail: impl Into<String>) -> Builder {
169 self.set_detail(Some(detail)) 175 self.set_detail(Some(detail))
170 } 176 }