aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_lsp_server/src/conv.rs28
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs9
2 files changed, 25 insertions, 12 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 0b9b18cbf..aad698da1 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -1,5 +1,5 @@
1use languageserver_types::{ 1use languageserver_types::{
2 self, CreateFile, DocumentChangeOperation, DocumentChanges, InsertTextFormat, Location, 2 self, CreateFile, DocumentChangeOperation, DocumentChanges, InsertTextFormat, Location, LocationLink,
3 Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, 3 Position, Range, RenameFile, ResourceOp, SymbolKind, TextDocumentEdit, TextDocumentIdentifier,
4 TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, 4 TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier,
5 WorkspaceEdit, 5 WorkspaceEdit,
@@ -349,13 +349,25 @@ impl TryConvWith for &NavigationTarget {
349 } 349 }
350} 350}
351 351
352impl TryConvWith for &RangeInfo<NavigationTarget> { 352pub fn to_location_link(
353 type Ctx = ServerWorld; 353 target: &RangeInfo<NavigationTarget>,
354 type Output = Location; 354 world: &ServerWorld,
355 fn try_conv_with(self, world: &ServerWorld) -> Result<Location> { 355 // line index for original range file
356 let line_index = world.analysis().file_line_index(self.info.file_id()); 356 line_index: &LineIndex,
357 to_location(self.info.file_id(), self.info.range(), &world, &line_index) 357) -> Result<LocationLink> {
358 } 358 let url = target.info.file_id().try_conv_with(world)?;
359 let tgt_line_index = world.analysis().file_line_index(target.info.file_id());
360
361 let res = LocationLink {
362 origin_selection_range: Some(target.range.conv_with(line_index)),
363 target_uri: url.to_string(),
364 target_range: target.info.range().conv_with(&tgt_line_index),
365 target_selection_range: target
366 .info
367 .focus_range()
368 .map(|it| it.conv_with(&tgt_line_index)),
369 };
370 Ok(res)
359} 371}
360 372
361pub fn to_location( 373pub fn to_location(
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index e3bf55ae7..aad9d6568 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -9,7 +9,7 @@ use languageserver_types::{
9 SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit, 9 SignatureInformation, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit,
10}; 10};
11use ra_ide_api::{ 11use ra_ide_api::{
12 FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, SourceChange, RangeInfo, 12 FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, RangeInfo,
13}; 13};
14use ra_syntax::{TextUnit, AstNode}; 14use ra_syntax::{TextUnit, AstNode};
15use rustc_hash::FxHashMap; 15use rustc_hash::FxHashMap;
@@ -17,7 +17,7 @@ use serde_json::to_value;
17use std::io::Write; 17use std::io::Write;
18 18
19use crate::{ 19use crate::{
20 conv::{to_location, Conv, ConvWith, MapConvWith, TryConvWith}, 20 conv::{to_location, to_location_link, Conv, ConvWith, MapConvWith, TryConvWith},
21 project_model::TargetKind, 21 project_model::TargetKind,
22 req::{self, Decoration}, 22 req::{self, Decoration},
23 server_world::ServerWorld, 23 server_world::ServerWorld,
@@ -208,6 +208,7 @@ pub fn handle_goto_definition(
208 params: req::TextDocumentPositionParams, 208 params: req::TextDocumentPositionParams,
209) -> Result<Option<req::GotoDefinitionResponse>> { 209) -> Result<Option<req::GotoDefinitionResponse>> {
210 let position = params.try_conv_with(&world)?; 210 let position = params.try_conv_with(&world)?;
211 let line_index = world.analysis().file_line_index(position.file_id);
211 let nav_info = match world.analysis().goto_definition(position)? { 212 let nav_info = match world.analysis().goto_definition(position)? {
212 None => return Ok(None), 213 None => return Ok(None),
213 Some(it) => it, 214 Some(it) => it,
@@ -217,9 +218,9 @@ pub fn handle_goto_definition(
217 .info 218 .info
218 .into_iter() 219 .into_iter()
219 .map(|nav| RangeInfo::new(nav_range, nav)) 220 .map(|nav| RangeInfo::new(nav_range, nav))
220 .map(|nav| nav.try_conv_with(&world)) 221 .map(|nav| to_location_link(&nav, &world, &line_index))
221 .collect::<Result<Vec<_>>>()?; 222 .collect::<Result<Vec<_>>>()?;
222 Ok(Some(req::GotoDefinitionResponse::Array(res))) 223 Ok(Some(req::GotoDefinitionResponse::Link(res)))
223} 224}
224 225
225pub fn handle_parent_module( 226pub fn handle_parent_module(