aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/util.rs
blob: 6747c20a8950369425798c6d5c49c7fa31a32edc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::path::PathBuf;
use languageserver_types::{TextDocumentItem, VersionedTextDocumentIdentifier,
                           TextDocumentIdentifier, Url};
use ::{Result};

pub trait FilePath {
    fn file_path(&self) -> Result<PathBuf>;
}

impl FilePath for TextDocumentItem {
    fn file_path(&self) -> Result<PathBuf> {
        self.uri.file_path()
    }
}

impl FilePath for VersionedTextDocumentIdentifier {
    fn file_path(&self) -> Result<PathBuf> {
        self.uri.file_path()
    }
}

impl FilePath for TextDocumentIdentifier {
    fn file_path(&self) -> Result<PathBuf> {
        self.uri.file_path()
    }
}

impl FilePath for Url {
    fn file_path(&self) -> Result<PathBuf> {
        self.to_file_path()
            .map_err(|()| format_err!("invalid uri: {}", self))
    }
}