aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_analysis/src/imp.rs8
-rw-r--r--crates/ra_analysis/src/lib.rs23
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs10
3 files changed, 28 insertions, 13 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index f3b513de1..836fb89f5 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -21,7 +21,7 @@ use ra_syntax::{
21 21
22use crate::{ 22use crate::{
23 AnalysisChange, 23 AnalysisChange,
24 Cancelable, 24 Cancelable, NavigationTarget,
25 completion::{CompletionItem, completions}, 25 completion::{CompletionItem, completions},
26 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, 26 CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
27 Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, 27 Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit,
@@ -355,9 +355,9 @@ impl AnalysisImpl {
355 Ok(Some((binding, descr))) 355 Ok(Some((binding, descr)))
356 } 356 }
357 } 357 }
358 pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> { 358 pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
359 let file = self.db.source_file(file_id); 359 let file = self.db.source_file(nav.file_id);
360 let result = match (symbol.description(&file), symbol.docs(&file)) { 360 let result = match (nav.symbol.description(&file), nav.symbol.docs(&file)) {
361 (Some(desc), Some(docs)) => { 361 (Some(desc), Some(docs)) => {
362 Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs) 362 Some("```rust\n".to_string() + &*desc + "\n```\n\n" + &*docs)
363 } 363 }
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index ff28271ab..4d8bdb61b 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -244,6 +244,21 @@ impl Query {
244 } 244 }
245} 245}
246 246
247#[derive(Debug)]
248pub struct NavigationTarget {
249 file_id: FileId,
250 symbol: FileSymbol,
251}
252
253impl NavigationTarget {
254 pub fn file_id(&self) -> FileId {
255 self.file_id
256 }
257 pub fn range(&self) -> TextRange {
258 self.symbol.node_range
259 }
260}
261
247/// Result of "goto def" query. 262/// Result of "goto def" query.
248#[derive(Debug)] 263#[derive(Debug)]
249pub struct ReferenceResolution { 264pub struct ReferenceResolution {
@@ -252,7 +267,7 @@ pub struct ReferenceResolution {
252 /// client where the reference was. 267 /// client where the reference was.
253 pub reference_range: TextRange, 268 pub reference_range: TextRange,
254 /// What this reference resolves to. 269 /// What this reference resolves to.
255 pub resolves_to: Vec<(FileId, FileSymbol)>, 270 pub resolves_to: Vec<NavigationTarget>,
256} 271}
257 272
258impl ReferenceResolution { 273impl ReferenceResolution {
@@ -264,7 +279,7 @@ impl ReferenceResolution {
264 } 279 }
265 280
266 fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) { 281 fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) {
267 self.resolves_to.push((file_id, symbol)) 282 self.resolves_to.push(NavigationTarget { file_id, symbol })
268 } 283 }
269} 284}
270 285
@@ -334,8 +349,8 @@ impl Analysis {
334 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { 349 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
335 self.imp.find_all_refs(position) 350 self.imp.find_all_refs(position)
336 } 351 }
337 pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> { 352 pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
338 self.imp.doc_text_for(file_id, symbol) 353 self.imp.doc_text_for(nav)
339 } 354 }
340 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { 355 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> {
341 self.imp.parent_module(position) 356 self.imp.parent_module(position)
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 11825d74e..5ff6219f9 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -213,9 +213,9 @@ pub fn handle_goto_definition(
213 Some(it) => it, 213 Some(it) => it,
214 }; 214 };
215 let mut res = Vec::new(); 215 let mut res = Vec::new();
216 for (file_id, symbol) in rr.resolves_to { 216 for nav in rr.resolves_to {
217 let line_index = world.analysis().file_line_index(file_id); 217 let line_index = world.analysis().file_line_index(nav.file_id());
218 let location = to_location(file_id, symbol.node_range, &world, &line_index)?; 218 let location = to_location(nav.file_id(), nav.range(), &world, &line_index)?;
219 res.push(location) 219 res.push(location)
220 } 220 }
221 Ok(Some(req::GotoDefinitionResponse::Array(res))) 221 Ok(Some(req::GotoDefinitionResponse::Array(res)))
@@ -517,8 +517,8 @@ pub fn handle_hover(
517 Some(it) => it, 517 Some(it) => it,
518 }; 518 };
519 let mut result = Vec::new(); 519 let mut result = Vec::new();
520 for (file_id, symbol) in rr.resolves_to { 520 for nav in rr.resolves_to {
521 if let Some(docs) = world.analysis().doc_text_for(file_id, symbol)? { 521 if let Some(docs) = world.analysis().doc_text_for(nav)? {
522 result.push(docs); 522 result.push(docs);
523 } 523 }
524 } 524 }