diff options
Diffstat (limited to 'crates/server/src/conv.rs')
-rw-r--r-- | crates/server/src/conv.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/crates/server/src/conv.rs b/crates/server/src/conv.rs index 0ed989b32..1c31d32fe 100644 --- a/crates/server/src/conv.rs +++ b/crates/server/src/conv.rs | |||
@@ -1,7 +1,11 @@ | |||
1 | use languageserver_types::{Range, SymbolKind, Position, TextEdit}; | 1 | use std::path::Path; |
2 | |||
3 | use languageserver_types::{Range, SymbolKind, Position, TextEdit, Location, Url}; | ||
2 | use libeditor::{LineIndex, LineCol, Edit, AtomEdit}; | 4 | use libeditor::{LineIndex, LineCol, Edit, AtomEdit}; |
3 | use libsyntax2::{SyntaxKind, TextUnit, TextRange}; | 5 | use libsyntax2::{SyntaxKind, TextUnit, TextRange}; |
4 | 6 | ||
7 | use Result; | ||
8 | |||
5 | pub trait Conv { | 9 | pub trait Conv { |
6 | type Output; | 10 | type Output; |
7 | fn conv(self) -> Self::Output; | 11 | fn conv(self) -> Self::Output; |
@@ -13,6 +17,12 @@ pub trait ConvWith { | |||
13 | fn conv_with(self, ctx: &Self::Ctx) -> Self::Output; | 17 | fn conv_with(self, ctx: &Self::Ctx) -> Self::Output; |
14 | } | 18 | } |
15 | 19 | ||
20 | pub trait TryConvWith { | ||
21 | type Ctx; | ||
22 | type Output; | ||
23 | fn try_conv_with(self, ctx: &Self::Ctx) -> Result<Self::Output>; | ||
24 | } | ||
25 | |||
16 | impl Conv for SyntaxKind { | 26 | impl Conv for SyntaxKind { |
17 | type Output = SymbolKind; | 27 | type Output = SymbolKind; |
18 | 28 | ||
@@ -104,6 +114,20 @@ impl ConvWith for AtomEdit { | |||
104 | } | 114 | } |
105 | } | 115 | } |
106 | 116 | ||
117 | impl<'a> TryConvWith for (&'a Path, TextRange) { | ||
118 | type Ctx = LineIndex; | ||
119 | type Output = Location; | ||
120 | |||
121 | fn try_conv_with(self, line_index: &LineIndex) -> Result<Location> { | ||
122 | let loc = Location::new( | ||
123 | Url::from_file_path(self.0) | ||
124 | .map_err(|()| format_err!("can't convert path to url: {}", self.0.display()))?, | ||
125 | self.1.conv_with(line_index), | ||
126 | ); | ||
127 | Ok(loc) | ||
128 | } | ||
129 | } | ||
130 | |||
107 | 131 | ||
108 | pub trait MapConvWith<'a>: Sized { | 132 | pub trait MapConvWith<'a>: Sized { |
109 | type Ctx; | 133 | type Ctx; |