Stupid goto definition
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
use languageserver_types::{Range, SymbolKind, Position, TextEdit};
|
||||
use std::path::Path;
|
||||
|
||||
use languageserver_types::{Range, SymbolKind, Position, TextEdit, Location, Url};
|
||||
use libeditor::{LineIndex, LineCol, Edit, AtomEdit};
|
||||
use libsyntax2::{SyntaxKind, TextUnit, TextRange};
|
||||
|
||||
use Result;
|
||||
|
||||
pub trait Conv {
|
||||
type Output;
|
||||
fn conv(self) -> Self::Output;
|
||||
@@ -13,6 +17,12 @@ pub trait ConvWith {
|
||||
fn conv_with(self, ctx: &Self::Ctx) -> Self::Output;
|
||||
}
|
||||
|
||||
pub trait TryConvWith {
|
||||
type Ctx;
|
||||
type Output;
|
||||
fn try_conv_with(self, ctx: &Self::Ctx) -> Result<Self::Output>;
|
||||
}
|
||||
|
||||
impl Conv for SyntaxKind {
|
||||
type Output = SymbolKind;
|
||||
|
||||
@@ -104,6 +114,20 @@ impl ConvWith for AtomEdit {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryConvWith for (&'a Path, TextRange) {
|
||||
type Ctx = LineIndex;
|
||||
type Output = Location;
|
||||
|
||||
fn try_conv_with(self, line_index: &LineIndex) -> Result<Location> {
|
||||
let loc = Location::new(
|
||||
Url::from_file_path(self.0)
|
||||
.map_err(|()| format_err!("can't convert path to url: {}", self.0.display()))?,
|
||||
self.1.conv_with(line_index),
|
||||
);
|
||||
Ok(loc)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub trait MapConvWith<'a>: Sized {
|
||||
type Ctx;
|
||||
|
||||
Reference in New Issue
Block a user