mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-25 03:15:08 +00:00
33 lines
794 B
Rust
33 lines
794 B
Rust
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))
|
|
}
|
|
}
|