diff options
Diffstat (limited to 'crates/server/src/util.rs')
-rw-r--r-- | crates/server/src/util.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/crates/server/src/util.rs b/crates/server/src/util.rs new file mode 100644 index 000000000..3691852f0 --- /dev/null +++ b/crates/server/src/util.rs | |||
@@ -0,0 +1,42 @@ | |||
1 | use std::path::PathBuf; | ||
2 | use languageserver_types::{TextDocumentItem, VersionedTextDocumentIdentifier, TextDocumentIdentifier}; | ||
3 | use ::{Result}; | ||
4 | |||
5 | pub trait FnBox<A, R>: Send { | ||
6 | fn call_box(self: Box<Self>, a: A) -> R; | ||
7 | } | ||
8 | |||
9 | impl<A, R, F: FnOnce(A) -> R + Send> FnBox<A, R> for F { | ||
10 | fn call_box(self: Box<F>, a: A) -> R { | ||
11 | (*self)(a) | ||
12 | } | ||
13 | } | ||
14 | |||
15 | pub trait FilePath { | ||
16 | fn file_path(&self) -> Result<PathBuf>; | ||
17 | } | ||
18 | |||
19 | impl FilePath for TextDocumentItem { | ||
20 | fn file_path(&self) -> Result<PathBuf> { | ||
21 | self.uri.file_path() | ||
22 | } | ||
23 | } | ||
24 | |||
25 | impl FilePath for VersionedTextDocumentIdentifier { | ||
26 | fn file_path(&self) -> Result<PathBuf> { | ||
27 | self.uri.file_path() | ||
28 | } | ||
29 | } | ||
30 | |||
31 | impl FilePath for TextDocumentIdentifier { | ||
32 | fn file_path(&self) -> Result<PathBuf> { | ||
33 | self.uri.file_path() | ||
34 | } | ||
35 | } | ||
36 | |||
37 | impl FilePath for ::url::Url { | ||
38 | fn file_path(&self) -> Result<PathBuf> { | ||
39 | self.to_file_path() | ||
40 | .map_err(|()| format_err!("invalid uri: {}", self)) | ||
41 | } | ||
42 | } | ||