aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/conv.rs59
1 files changed, 25 insertions, 34 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 236fdb972..bbe140b7a 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -19,10 +19,9 @@ pub trait Conv {
19 fn conv(self) -> Self::Output; 19 fn conv(self) -> Self::Output;
20} 20}
21 21
22pub trait ConvWith { 22pub trait ConvWith<CTX> {
23 type Ctx;
24 type Output; 23 type Output;
25 fn conv_with(self, ctx: &Self::Ctx) -> Self::Output; 24 fn conv_with(self, ctx: CTX) -> Self::Output;
26} 25}
27 26
28pub trait TryConvWith { 27pub trait TryConvWith {
@@ -89,8 +88,7 @@ impl Conv for Severity {
89 } 88 }
90} 89}
91 90
92impl ConvWith for CompletionItem { 91impl ConvWith<&'_ LineIndex> for CompletionItem {
93 type Ctx = LineIndex;
94 type Output = ::lsp_types::CompletionItem; 92 type Output = ::lsp_types::CompletionItem;
95 93
96 fn conv_with(self, ctx: &LineIndex) -> ::lsp_types::CompletionItem { 94 fn conv_with(self, ctx: &LineIndex) -> ::lsp_types::CompletionItem {
@@ -138,8 +136,7 @@ impl ConvWith for CompletionItem {
138 } 136 }
139} 137}
140 138
141impl ConvWith for Position { 139impl ConvWith<&'_ LineIndex> for Position {
142 type Ctx = LineIndex;
143 type Output = TextUnit; 140 type Output = TextUnit;
144 141
145 fn conv_with(self, line_index: &LineIndex) -> TextUnit { 142 fn conv_with(self, line_index: &LineIndex) -> TextUnit {
@@ -148,8 +145,7 @@ impl ConvWith for Position {
148 } 145 }
149} 146}
150 147
151impl ConvWith for TextUnit { 148impl ConvWith<&'_ LineIndex> for TextUnit {
152 type Ctx = LineIndex;
153 type Output = Position; 149 type Output = Position;
154 150
155 fn conv_with(self, line_index: &LineIndex) -> Position { 151 fn conv_with(self, line_index: &LineIndex) -> Position {
@@ -158,8 +154,7 @@ impl ConvWith for TextUnit {
158 } 154 }
159} 155}
160 156
161impl ConvWith for TextRange { 157impl ConvWith<&'_ LineIndex> for TextRange {
162 type Ctx = LineIndex;
163 type Output = Range; 158 type Output = Range;
164 159
165 fn conv_with(self, line_index: &LineIndex) -> Range { 160 fn conv_with(self, line_index: &LineIndex) -> Range {
@@ -167,8 +162,7 @@ impl ConvWith for TextRange {
167 } 162 }
168} 163}
169 164
170impl ConvWith for Range { 165impl ConvWith<&'_ LineIndex> for Range {
171 type Ctx = LineIndex;
172 type Output = TextRange; 166 type Output = TextRange;
173 167
174 fn conv_with(self, line_index: &LineIndex) -> TextRange { 168 fn conv_with(self, line_index: &LineIndex) -> TextRange {
@@ -208,8 +202,7 @@ impl Conv for ra_ide_api::FunctionSignature {
208 } 202 }
209} 203}
210 204
211impl ConvWith for TextEdit { 205impl ConvWith<&'_ LineIndex> for TextEdit {
212 type Ctx = LineIndex;
213 type Output = Vec<lsp_types::TextEdit>; 206 type Output = Vec<lsp_types::TextEdit>;
214 207
215 fn conv_with(self, line_index: &LineIndex) -> Vec<lsp_types::TextEdit> { 208 fn conv_with(self, line_index: &LineIndex) -> Vec<lsp_types::TextEdit> {
@@ -217,8 +210,7 @@ impl ConvWith for TextEdit {
217 } 210 }
218} 211}
219 212
220impl ConvWith for &'_ AtomTextEdit { 213impl ConvWith<&'_ LineIndex> for &'_ AtomTextEdit {
221 type Ctx = LineIndex;
222 type Output = lsp_types::TextEdit; 214 type Output = lsp_types::TextEdit;
223 215
224 fn conv_with(self, line_index: &LineIndex) -> lsp_types::TextEdit { 216 fn conv_with(self, line_index: &LineIndex) -> lsp_types::TextEdit {
@@ -229,10 +221,10 @@ impl ConvWith for &'_ AtomTextEdit {
229 } 221 }
230} 222}
231 223
232impl<T: ConvWith> ConvWith for Option<T> { 224impl<T: ConvWith<CTX>, CTX> ConvWith<CTX> for Option<T> {
233 type Ctx = <T as ConvWith>::Ctx; 225 type Output = Option<T::Output>;
234 type Output = Option<<T as ConvWith>::Output>; 226
235 fn conv_with(self, ctx: &Self::Ctx) -> Self::Output { 227 fn conv_with(self, ctx: CTX) -> Self::Output {
236 self.map(|x| ConvWith::conv_with(x, ctx)) 228 self.map(|x| ConvWith::conv_with(x, ctx))
237 } 229 }
238} 230}
@@ -454,35 +446,34 @@ pub fn to_location(
454 Ok(loc) 446 Ok(loc)
455} 447}
456 448
457pub trait MapConvWith<'a>: Sized + 'a { 449pub trait MapConvWith<CTX>: Sized {
458 type Ctx;
459 type Output; 450 type Output;
460 451
461 fn map_conv_with(self, ctx: &'a Self::Ctx) -> ConvWithIter<'a, Self, Self::Ctx> { 452 fn map_conv_with(self, ctx: CTX) -> ConvWithIter<Self, CTX> {
462 ConvWithIter { iter: self, ctx } 453 ConvWithIter { iter: self, ctx }
463 } 454 }
464} 455}
465 456
466impl<'a, I> MapConvWith<'a> for I 457impl<CTX, I> MapConvWith<CTX> for I
467where 458where
468 I: Iterator + 'a, 459 I: Iterator,
469 I::Item: ConvWith, 460 I::Item: ConvWith<CTX>,
470{ 461{
471 type Ctx = <I::Item as ConvWith>::Ctx; 462 type Output = <I::Item as ConvWith<CTX>>::Output;
472 type Output = <I::Item as ConvWith>::Output;
473} 463}
474 464
475pub struct ConvWithIter<'a, I, Ctx: 'a> { 465pub struct ConvWithIter<I, CTX> {
476 iter: I, 466 iter: I,
477 ctx: &'a Ctx, 467 ctx: CTX,
478} 468}
479 469
480impl<'a, I, Ctx> Iterator for ConvWithIter<'a, I, Ctx> 470impl<I, CTX> Iterator for ConvWithIter<I, CTX>
481where 471where
482 I: Iterator, 472 I: Iterator,
483 I::Item: ConvWith<Ctx = Ctx>, 473 I::Item: ConvWith<CTX>,
474 CTX: Copy,
484{ 475{
485 type Item = <I::Item as ConvWith>::Output; 476 type Item = <I::Item as ConvWith<CTX>>::Output;
486 477
487 fn next(&mut self) -> Option<Self::Item> { 478 fn next(&mut self) -> Option<Self::Item> {
488 self.iter.next().map(|item| item.conv_with(self.ctx)) 479 self.iter.next().map(|item| item.conv_with(self.ctx))