aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/server/src/util.rs')
-rw-r--r--crates/server/src/util.rs42
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 @@
1use std::path::PathBuf;
2use languageserver_types::{TextDocumentItem, VersionedTextDocumentIdentifier, TextDocumentIdentifier};
3use ::{Result};
4
5pub trait FnBox<A, R>: Send {
6 fn call_box(self: Box<Self>, a: A) -> R;
7}
8
9impl<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
15pub trait FilePath {
16 fn file_path(&self) -> Result<PathBuf>;
17}
18
19impl FilePath for TextDocumentItem {
20 fn file_path(&self) -> Result<PathBuf> {
21 self.uri.file_path()
22 }
23}
24
25impl FilePath for VersionedTextDocumentIdentifier {
26 fn file_path(&self) -> Result<PathBuf> {
27 self.uri.file_path()
28 }
29}
30
31impl FilePath for TextDocumentIdentifier {
32 fn file_path(&self) -> Result<PathBuf> {
33 self.uri.file_path()
34 }
35}
36
37impl 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}