aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/lib.rs')
-rw-r--r--crates/ra_analysis/src/lib.rs49
1 files changed, 38 insertions, 11 deletions
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 08ecb125a..9576453ab 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -23,22 +23,22 @@ mod syntax_highlighting;
23use std::{fmt, sync::Arc}; 23use std::{fmt, sync::Arc};
24 24
25use rustc_hash::FxHashMap; 25use rustc_hash::FxHashMap;
26use ra_syntax::{SourceFileNode, TextRange, TextUnit}; 26use ra_syntax::{SourceFileNode, TextRange, TextUnit, SmolStr, SyntaxKind};
27use ra_text_edit::TextEdit; 27use ra_text_edit::TextEdit;
28use rayon::prelude::*; 28use rayon::prelude::*;
29use relative_path::RelativePathBuf; 29use relative_path::RelativePathBuf;
30 30
31use crate::{ 31use crate::{
32 imp::{AnalysisHostImpl, AnalysisImpl}, 32 imp::{AnalysisHostImpl, AnalysisImpl},
33 symbol_index::SymbolIndex, 33 symbol_index::{SymbolIndex, FileSymbol},
34}; 34};
35 35
36pub use crate::{ 36pub use crate::{
37 completion::{CompletionItem, CompletionItemKind, InsertText}, 37 completion::{CompletionItem, CompletionItemKind, InsertText},
38 runnables::{Runnable, RunnableKind} 38 runnables::{Runnable, RunnableKind},
39}; 39};
40pub use ra_editor::{ 40pub use ra_editor::{
41 FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, StructureNode, Severity 41 Fold, FoldKind, HighlightedRange, LineIndex, StructureNode, Severity
42}; 42};
43pub use hir::FnSignatureInfo; 43pub use hir::FnSignatureInfo;
44 44
@@ -242,6 +242,27 @@ impl Query {
242 } 242 }
243} 243}
244 244
245#[derive(Debug)]
246pub struct NavigationTarget {
247 file_id: FileId,
248 symbol: FileSymbol,
249}
250
251impl NavigationTarget {
252 pub fn name(&self) -> SmolStr {
253 self.symbol.name.clone()
254 }
255 pub fn kind(&self) -> SyntaxKind {
256 self.symbol.kind
257 }
258 pub fn file_id(&self) -> FileId {
259 self.file_id
260 }
261 pub fn range(&self) -> TextRange {
262 self.symbol.node_range
263 }
264}
265
245/// Result of "goto def" query. 266/// Result of "goto def" query.
246#[derive(Debug)] 267#[derive(Debug)]
247pub struct ReferenceResolution { 268pub struct ReferenceResolution {
@@ -250,7 +271,7 @@ pub struct ReferenceResolution {
250 /// client where the reference was. 271 /// client where the reference was.
251 pub reference_range: TextRange, 272 pub reference_range: TextRange,
252 /// What this reference resolves to. 273 /// What this reference resolves to.
253 pub resolves_to: Vec<(FileId, FileSymbol)>, 274 pub resolves_to: Vec<NavigationTarget>,
254} 275}
255 276
256impl ReferenceResolution { 277impl ReferenceResolution {
@@ -262,7 +283,7 @@ impl ReferenceResolution {
262 } 283 }
263 284
264 fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) { 285 fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) {
265 self.resolves_to.push((file_id, symbol)) 286 self.resolves_to.push(NavigationTarget { file_id, symbol })
266 } 287 }
267} 288}
268 289
@@ -320,8 +341,14 @@ impl Analysis {
320 let file = self.imp.file_syntax(file_id); 341 let file = self.imp.file_syntax(file_id);
321 ra_editor::folding_ranges(&file) 342 ra_editor::folding_ranges(&file)
322 } 343 }
323 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { 344 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
324 self.imp.world_symbols(query) 345 let res = self
346 .imp
347 .world_symbols(query)?
348 .into_iter()
349 .map(|(file_id, symbol)| NavigationTarget { file_id, symbol })
350 .collect();
351 Ok(res)
325 } 352 }
326 pub fn approximately_resolve_symbol( 353 pub fn approximately_resolve_symbol(
327 &self, 354 &self,
@@ -332,10 +359,10 @@ impl Analysis {
332 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { 359 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
333 self.imp.find_all_refs(position) 360 self.imp.find_all_refs(position)
334 } 361 }
335 pub fn doc_text_for(&self, file_id: FileId, symbol: FileSymbol) -> Cancelable<Option<String>> { 362 pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> {
336 self.imp.doc_text_for(file_id, symbol) 363 self.imp.doc_text_for(nav)
337 } 364 }
338 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { 365 pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> {
339 self.imp.parent_module(position) 366 self.imp.parent_module(position)
340 } 367 }
341 pub fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { 368 pub fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> {