diff options
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 28 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 16 |
2 files changed, 35 insertions, 9 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 35c679a4a..76fa98cbe 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -1,12 +1,12 @@ | |||
1 | use languageserver_types::{ | 1 | use 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, |
6 | }; | 6 | }; |
7 | use ra_ide_api::{ | 7 | use ra_ide_api::{ |
8 | CompletionItem, CompletionItemKind, FileId, FilePosition, FileRange, FileSystemEdit, | 8 | CompletionItem, CompletionItemKind, FileId, FilePosition, FileRange, FileSystemEdit, |
9 | InsertText, NavigationTarget, SourceChange, SourceFileEdit, | 9 | InsertText, NavigationTarget, SourceChange, SourceFileEdit, RangeInfo, |
10 | LineCol, LineIndex, translate_offset_with_edit | 10 | LineCol, LineIndex, translate_offset_with_edit |
11 | }; | 11 | }; |
12 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; | 12 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; |
@@ -345,10 +345,32 @@ impl TryConvWith for &NavigationTarget { | |||
345 | type Output = Location; | 345 | type Output = Location; |
346 | fn try_conv_with(self, world: &ServerWorld) -> Result<Location> { | 346 | fn try_conv_with(self, world: &ServerWorld) -> Result<Location> { |
347 | let line_index = world.analysis().file_line_index(self.file_id()); | 347 | let line_index = world.analysis().file_line_index(self.file_id()); |
348 | to_location(self.file_id(), self.range(), &world, &line_index) | 348 | let range = self.focus_range().unwrap_or(self.full_range()); |
349 | to_location(self.file_id(), range, &world, &line_index) | ||
349 | } | 350 | } |
350 | } | 351 | } |
351 | 352 | ||
353 | pub fn to_location_link( | ||
354 | target: &RangeInfo<NavigationTarget>, | ||
355 | world: &ServerWorld, | ||
356 | // line index for original range file | ||
357 | line_index: &LineIndex, | ||
358 | ) -> Result<LocationLink> { | ||
359 | let url = target.info.file_id().try_conv_with(world)?; | ||
360 | let tgt_line_index = world.analysis().file_line_index(target.info.file_id()); | ||
361 | |||
362 | let res = LocationLink { | ||
363 | origin_selection_range: Some(target.range.conv_with(line_index)), | ||
364 | target_uri: url.to_string(), | ||
365 | target_range: target.info.full_range().conv_with(&tgt_line_index), | ||
366 | target_selection_range: target | ||
367 | .info | ||
368 | .focus_range() | ||
369 | .map(|it| it.conv_with(&tgt_line_index)), | ||
370 | }; | ||
371 | Ok(res) | ||
372 | } | ||
373 | |||
352 | pub fn to_location( | 374 | pub fn to_location( |
353 | file_id: FileId, | 375 | file_id: FileId, |
354 | range: TextRange, | 376 | range: TextRange, |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 5f4b27149..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 | }; |
11 | use ra_ide_api::{ | 11 | use ra_ide_api::{ |
12 | FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, | 12 | FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, Severity, RangeInfo, |
13 | }; | 13 | }; |
14 | use ra_syntax::{TextUnit, AstNode}; | 14 | use ra_syntax::{TextUnit, AstNode}; |
15 | use rustc_hash::FxHashMap; | 15 | use rustc_hash::FxHashMap; |
@@ -17,7 +17,7 @@ use serde_json::to_value; | |||
17 | use std::io::Write; | 17 | use std::io::Write; |
18 | 18 | ||
19 | use crate::{ | 19 | use 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,15 +208,19 @@ 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 navs = match world.analysis().goto_definition(position)? { | 211 | let line_index = world.analysis().file_line_index(position.file_id); |
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, |
214 | }; | 215 | }; |
215 | let res = navs | 216 | let nav_range = nav_info.range; |
217 | let res = nav_info | ||
218 | .info | ||
216 | .into_iter() | 219 | .into_iter() |
217 | .map(|nav| nav.try_conv_with(&world)) | 220 | .map(|nav| RangeInfo::new(nav_range, nav)) |
221 | .map(|nav| to_location_link(&nav, &world, &line_index)) | ||
218 | .collect::<Result<Vec<_>>>()?; | 222 | .collect::<Result<Vec<_>>>()?; |
219 | Ok(Some(req::GotoDefinitionResponse::Array(res))) | 223 | Ok(Some(req::GotoDefinitionResponse::Link(res))) |
220 | } | 224 | } |
221 | 225 | ||
222 | pub fn handle_parent_module( | 226 | pub fn handle_parent_module( |