use location link in goto def
This commit is contained in:
parent
3aaf20bd6e
commit
8a5f74a24f
@ -1,5 +1,5 @@
|
|||||||
use languageserver_types::{
|
use languageserver_types::{
|
||||||
self, CreateFile, DocumentChangeOperation, DocumentChanges, InsertTextFormat, Location,
|
self, CreateFile, DocumentChangeOperation, DocumentChanges, InsertTextFormat, Location, LocationLink,
|
||||||
Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
|
Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
|
||||||
TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier,
|
TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier,
|
||||||
WorkspaceEdit,
|
WorkspaceEdit,
|
||||||
@ -349,13 +349,25 @@ impl TryConvWith for &NavigationTarget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryConvWith for &RangeInfo<NavigationTarget> {
|
pub fn to_location_link(
|
||||||
type Ctx = ServerWorld;
|
target: &RangeInfo<NavigationTarget>,
|
||||||
type Output = Location;
|
world: &ServerWorld,
|
||||||
fn try_conv_with(self, world: &ServerWorld) -> Result<Location> {
|
// line index for original range file
|
||||||
let line_index = world.analysis().file_line_index(self.info.file_id());
|
line_index: &LineIndex,
|
||||||
to_location(self.info.file_id(), self.info.range(), &world, &line_index)
|
) -> Result<LocationLink> {
|
||||||
}
|
let url = target.info.file_id().try_conv_with(world)?;
|
||||||
|
let tgt_line_index = world.analysis().file_line_index(target.info.file_id());
|
||||||
|
|
||||||
|
let res = LocationLink {
|
||||||
|
origin_selection_range: Some(target.range.conv_with(line_index)),
|
||||||
|
target_uri: url.to_string(),
|
||||||
|
target_range: target.info.range().conv_with(&tgt_line_index),
|
||||||
|
target_selection_range: target
|
||||||
|
.info
|
||||||
|
.focus_range()
|
||||||
|
.map(|it| it.conv_with(&tgt_line_index)),
|
||||||
|
};
|
||||||
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_location(
|
pub fn to_location(
|
||||||
|
@ -9,7 +9,7 @@ use languageserver_types::{
|
|||||||
SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit,
|
SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit,
|
||||||
};
|
};
|
||||||
use ra_ide_api::{
|
use ra_ide_api::{
|
||||||
FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange, RangeInfo,
|
FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, RangeInfo,
|
||||||
};
|
};
|
||||||
use ra_syntax::{TextUnit, AstNode};
|
use ra_syntax::{TextUnit, AstNode};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
@ -17,7 +17,7 @@ use serde_json::to_value;
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
conv::{to_location, Conv, ConvWith, MapConvWith, TryConvWith},
|
conv::{to_location, to_location_link, Conv, ConvWith, MapConvWith, TryConvWith},
|
||||||
project_model::TargetKind,
|
project_model::TargetKind,
|
||||||
req::{self, Decoration},
|
req::{self, Decoration},
|
||||||
server_world::ServerWorld,
|
server_world::ServerWorld,
|
||||||
@ -208,6 +208,7 @@ pub fn handle_goto_definition(
|
|||||||
params: req::TextDocumentPositionParams,
|
params: req::TextDocumentPositionParams,
|
||||||
) -> Result<Option<req::GotoDefinitionResponse>> {
|
) -> Result<Option<req::GotoDefinitionResponse>> {
|
||||||
let position = params.try_conv_with(&world)?;
|
let position = params.try_conv_with(&world)?;
|
||||||
|
let line_index = world.analysis().file_line_index(position.file_id);
|
||||||
let nav_info = match world.analysis().goto_definition(position)? {
|
let nav_info = match world.analysis().goto_definition(position)? {
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
@ -217,9 +218,9 @@ pub fn handle_goto_definition(
|
|||||||
.info
|
.info
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|nav| RangeInfo::new(nav_range, nav))
|
.map(|nav| RangeInfo::new(nav_range, nav))
|
||||||
.map(|nav| nav.try_conv_with(&world))
|
.map(|nav| to_location_link(&nav, &world, &line_index))
|
||||||
.collect::<Result<Vec<_>>>()?;
|
.collect::<Result<Vec<_>>>()?;
|
||||||
Ok(Some(req::GotoDefinitionResponse::Array(res)))
|
Ok(Some(req::GotoDefinitionResponse::Link(res)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_parent_module(
|
pub fn handle_parent_module(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user