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.rs43
1 files changed, 32 insertions, 11 deletions
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index a01febf4e..61af676b2 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -1,6 +1,8 @@
1//! ra_analyzer crate is the brain of Rust analyzer. It relies on the `salsa` 1//! ra_analyzer crate provides "ide-centric" APIs for the rust-analyzer. What
2//! crate, which provides and incremental on-demand database of facts. 2//! powers this API are the `RootDatabase` struct, which defines a `salsa`
3 3//! database, and the `ra_hir` crate, where majority of the analysis happens.
4//! However, IDE specific bits of the analysis (most notably completion) happen
5//! in this crate.
4macro_rules! ctry { 6macro_rules! ctry {
5 ($expr:expr) => { 7 ($expr:expr) => {
6 match $expr { 8 match $expr {
@@ -41,7 +43,7 @@ pub use ra_editor::{
41pub use hir::FnSignatureInfo; 43pub use hir::FnSignatureInfo;
42 44
43pub use ra_db::{ 45pub use ra_db::{
44 Canceled, Cancelable, FilePosition, FileRange, 46 Canceled, Cancelable, FilePosition, FileRange, LocalSyntaxPtr,
45 CrateGraph, CrateId, SourceRootId, FileId, SyntaxDatabase, FilesDatabase 47 CrateGraph, CrateId, SourceRootId, FileId, SyntaxDatabase, FilesDatabase
46}; 48};
47 49
@@ -219,24 +221,42 @@ impl Query {
219 } 221 }
220} 222}
221 223
224/// `NavigationTarget` represents and element in the editor's UI whihc you can
225/// click on to navigate to a particular piece of code.
226///
227/// Typically, a `NavigationTarget` corresponds to some element in the source
228/// code, like a function or a struct, but this is not strictly required.
222#[derive(Debug)] 229#[derive(Debug)]
223pub struct NavigationTarget { 230pub struct NavigationTarget {
224 file_id: FileId, 231 file_id: FileId,
225 symbol: FileSymbol, 232 name: SmolStr,
233 kind: SyntaxKind,
234 range: TextRange,
235 // Should be DefId ideally
236 ptr: Option<LocalSyntaxPtr>,
226} 237}
227 238
228impl NavigationTarget { 239impl NavigationTarget {
229 pub fn name(&self) -> SmolStr { 240 fn from_symbol(file_id: FileId, symbol: FileSymbol) -> NavigationTarget {
230 self.symbol.name.clone() 241 NavigationTarget {
242 name: symbol.name.clone(),
243 kind: symbol.ptr.kind(),
244 file_id,
245 range: symbol.ptr.range(),
246 ptr: Some(symbol.ptr.clone()),
247 }
248 }
249 pub fn name(&self) -> &SmolStr {
250 &self.name
231 } 251 }
232 pub fn kind(&self) -> SyntaxKind { 252 pub fn kind(&self) -> SyntaxKind {
233 self.symbol.kind 253 self.kind
234 } 254 }
235 pub fn file_id(&self) -> FileId { 255 pub fn file_id(&self) -> FileId {
236 self.file_id 256 self.file_id
237 } 257 }
238 pub fn range(&self) -> TextRange { 258 pub fn range(&self) -> TextRange {
239 self.symbol.node_range 259 self.range
240 } 260 }
241} 261}
242 262
@@ -260,7 +280,8 @@ impl ReferenceResolution {
260 } 280 }
261 281
262 fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) { 282 fn add_resolution(&mut self, file_id: FileId, symbol: FileSymbol) {
263 self.resolves_to.push(NavigationTarget { file_id, symbol }) 283 self.resolves_to
284 .push(NavigationTarget::from_symbol(file_id, symbol))
264 } 285 }
265} 286}
266 287
@@ -359,7 +380,7 @@ impl Analysis {
359 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { 380 pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
360 let res = symbol_index::world_symbols(&*self.db, query)? 381 let res = symbol_index::world_symbols(&*self.db, query)?
361 .into_iter() 382 .into_iter()
362 .map(|(file_id, symbol)| NavigationTarget { file_id, symbol }) 383 .map(|(file_id, symbol)| NavigationTarget::from_symbol(file_id, symbol))
363 .collect(); 384 .collect();
364 Ok(res) 385 Ok(res)
365 } 386 }