aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/conv.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-13 14:35:17 +0100
committerAleksey Kladov <[email protected]>2018-08-13 14:35:17 +0100
commit8ae56fa6d0e8a03d6ad75919d6be953f5fc27083 (patch)
treed93a4f3e1d279a27cc851546796bb488edfe2c65 /crates/server/src/conv.rs
parent7fc91f41d8bd948cef3085d7c0d0ec92d1b2bc53 (diff)
Stupid goto definition
Diffstat (limited to 'crates/server/src/conv.rs')
-rw-r--r--crates/server/src/conv.rs26
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 @@
1use languageserver_types::{Range, SymbolKind, Position, TextEdit}; 1use std::path::Path;
2
3use languageserver_types::{Range, SymbolKind, Position, TextEdit, Location, Url};
2use libeditor::{LineIndex, LineCol, Edit, AtomEdit}; 4use libeditor::{LineIndex, LineCol, Edit, AtomEdit};
3use libsyntax2::{SyntaxKind, TextUnit, TextRange}; 5use libsyntax2::{SyntaxKind, TextUnit, TextRange};
4 6
7use Result;
8
5pub trait Conv { 9pub 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
20pub trait TryConvWith {
21 type Ctx;
22 type Output;
23 fn try_conv_with(self, ctx: &Self::Ctx) -> Result<Self::Output>;
24}
25
16impl Conv for SyntaxKind { 26impl 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
117impl<'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
108pub trait MapConvWith<'a>: Sized { 132pub trait MapConvWith<'a>: Sized {
109 type Ctx; 133 type Ctx;