diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-03 09:59:24 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-03 09:59:24 +0000 |
commit | e92f2ffe270c6a9fca312fb8a53cd0da0dd01fde (patch) | |
tree | 7f72fee435e82c750b321a52c551010d1b7afd09 /crates/ra_analysis/src/lib.rs | |
parent | f673529a3355cdd00062c873cd4fdd100f60a243 (diff) | |
parent | 8d6185350953391d0dd405cf790a69bb65d88a36 (diff) |
Merge #410
410: Detangle symbols r=matklad a=matklad
Previously, we used `FileSymbol` both to represent bytes which are stored in the index and as an API of `ra_analysis`. Mixing internal storage format and an API is not a really bright idea, so we introduce `NavigationTarget` to handle API part.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/lib.rs')
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 43 |
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. | ||
4 | macro_rules! ctry { | 6 | macro_rules! ctry { |
5 | ($expr:expr) => { | 7 | ($expr:expr) => { |
6 | match $expr { | 8 | match $expr { |
@@ -41,7 +43,7 @@ pub use ra_editor::{ | |||
41 | pub use hir::FnSignatureInfo; | 43 | pub use hir::FnSignatureInfo; |
42 | 44 | ||
43 | pub use ra_db::{ | 45 | pub 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)] |
223 | pub struct NavigationTarget { | 230 | pub 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 | ||
228 | impl NavigationTarget { | 239 | impl 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 | } |