diff options
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 11 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 9 |
4 files changed, 24 insertions, 10 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 4706dc733..3fb29950b 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -4,19 +4,21 @@ use ra_syntax::{ | |||
4 | algo::find_node_at_offset, | 4 | algo::find_node_at_offset, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | use crate::{FilePosition, NavigationTarget, db::RootDatabase}; | 7 | use crate::{FilePosition, NavigationTarget, db::RootDatabase, RangeInfo}; |
8 | 8 | ||
9 | pub(crate) fn goto_definition( | 9 | pub(crate) fn goto_definition( |
10 | db: &RootDatabase, | 10 | db: &RootDatabase, |
11 | position: FilePosition, | 11 | position: FilePosition, |
12 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { | 12 | ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> { |
13 | let file = db.source_file(position.file_id); | 13 | let file = db.source_file(position.file_id); |
14 | let syntax = file.syntax(); | 14 | let syntax = file.syntax(); |
15 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { | 15 | if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { |
16 | return Ok(Some(reference_definition(db, position.file_id, name_ref)?)); | 16 | let navs = reference_definition(db, position.file_id, name_ref)?; |
17 | return Ok(Some(RangeInfo::new(name_ref.syntax().range(), navs))); | ||
17 | } | 18 | } |
18 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { | 19 | if let Some(name) = find_node_at_offset::<ast::Name>(syntax, position.offset) { |
19 | return name_definition(db, position.file_id, name); | 20 | let navs = ctry!(name_definition(db, position.file_id, name)?); |
21 | return Ok(Some(RangeInfo::new(name.syntax().range(), navs))); | ||
20 | } | 22 | } |
21 | Ok(None) | 23 | Ok(None) |
22 | } | 24 | } |
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 2873bab36..2b02dab2a 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs | |||
@@ -251,7 +251,7 @@ pub struct RangeInfo<T> { | |||
251 | } | 251 | } |
252 | 252 | ||
253 | impl<T> RangeInfo<T> { | 253 | impl<T> RangeInfo<T> { |
254 | fn new(range: TextRange, info: T) -> RangeInfo<T> { | 254 | pub fn new(range: TextRange, info: T) -> RangeInfo<T> { |
255 | RangeInfo { range, info } | 255 | RangeInfo { range, info } |
256 | } | 256 | } |
257 | } | 257 | } |
@@ -391,7 +391,7 @@ impl Analysis { | |||
391 | pub fn goto_definition( | 391 | pub fn goto_definition( |
392 | &self, | 392 | &self, |
393 | position: FilePosition, | 393 | position: FilePosition, |
394 | ) -> Cancelable<Option<Vec<NavigationTarget>>> { | 394 | ) -> Cancelable<Option<RangeInfo<Vec<NavigationTarget>>>> { |
395 | self.db | 395 | self.db |
396 | .catch_canceled(|db| goto_definition::goto_definition(db, position))? | 396 | .catch_canceled(|db| goto_definition::goto_definition(db, position))? |
397 | } | 397 | } |
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 35c679a4a..0b9b18cbf 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -6,7 +6,7 @@ use languageserver_types::{ | |||
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}; |
@@ -349,6 +349,15 @@ impl TryConvWith for &NavigationTarget { | |||
349 | } | 349 | } |
350 | } | 350 | } |
351 | 351 | ||
352 | impl TryConvWith for &RangeInfo<NavigationTarget> { | ||
353 | type Ctx = ServerWorld; | ||
354 | type Output = Location; | ||
355 | fn try_conv_with(self, world: &ServerWorld) -> Result<Location> { | ||
356 | let line_index = world.analysis().file_line_index(self.info.file_id()); | ||
357 | to_location(self.info.file_id(), self.info.range(), &world, &line_index) | ||
358 | } | ||
359 | } | ||
360 | |||
352 | pub fn to_location( | 361 | pub fn to_location( |
353 | file_id: FileId, | 362 | file_id: FileId, |
354 | range: TextRange, | 363 | 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..e3bf55ae7 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, SourceChange, 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; |
@@ -208,12 +208,15 @@ 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 nav_info = match world.analysis().goto_definition(position)? { |
212 | None => return Ok(None), | 212 | None => return Ok(None), |
213 | Some(it) => it, | 213 | Some(it) => it, |
214 | }; | 214 | }; |
215 | let res = navs | 215 | let nav_range = nav_info.range; |
216 | let res = nav_info | ||
217 | .info | ||
216 | .into_iter() | 218 | .into_iter() |
219 | .map(|nav| RangeInfo::new(nav_range, nav)) | ||
217 | .map(|nav| nav.try_conv_with(&world)) | 220 | .map(|nav| nav.try_conv_with(&world)) |
218 | .collect::<Result<Vec<_>>>()?; | 221 | .collect::<Result<Vec<_>>>()?; |
219 | Ok(Some(req::GotoDefinitionResponse::Array(res))) | 222 | Ok(Some(req::GotoDefinitionResponse::Array(res))) |