diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-02 14:26:06 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-02 14:26:06 +0000 |
commit | 29d8bfb9c909847cb37ff6e564ea0e61744277ad (patch) | |
tree | 53e4d51b9a80330e3ebb53959ed2a2a67a605fbf /crates/ra_analysis/src/lib.rs | |
parent | afa972e78d2d81598c02b742ab84d70c88208300 (diff) | |
parent | 76910639e6930d1d76ec0a5d7c11219e073b73be (diff) |
Merge #404
404: Move FileSymbol to ra_analysis r=matklad a=matklad
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 | 49 |
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; | |||
23 | use std::{fmt, sync::Arc}; | 23 | use std::{fmt, sync::Arc}; |
24 | 24 | ||
25 | use rustc_hash::FxHashMap; | 25 | use rustc_hash::FxHashMap; |
26 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; | 26 | use ra_syntax::{SourceFileNode, TextRange, TextUnit, SmolStr, SyntaxKind}; |
27 | use ra_text_edit::TextEdit; | 27 | use ra_text_edit::TextEdit; |
28 | use rayon::prelude::*; | 28 | use rayon::prelude::*; |
29 | use relative_path::RelativePathBuf; | 29 | use relative_path::RelativePathBuf; |
30 | 30 | ||
31 | use crate::{ | 31 | use crate::{ |
32 | imp::{AnalysisHostImpl, AnalysisImpl}, | 32 | imp::{AnalysisHostImpl, AnalysisImpl}, |
33 | symbol_index::SymbolIndex, | 33 | symbol_index::{SymbolIndex, FileSymbol}, |
34 | }; | 34 | }; |
35 | 35 | ||
36 | pub use crate::{ | 36 | pub use crate::{ |
37 | completion::{CompletionItem, CompletionItemKind, InsertText}, | 37 | completion::{CompletionItem, CompletionItemKind, InsertText}, |
38 | runnables::{Runnable, RunnableKind} | 38 | runnables::{Runnable, RunnableKind}, |
39 | }; | 39 | }; |
40 | pub use ra_editor::{ | 40 | pub use ra_editor::{ |
41 | FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, StructureNode, Severity | 41 | Fold, FoldKind, HighlightedRange, LineIndex, StructureNode, Severity |
42 | }; | 42 | }; |
43 | pub use hir::FnSignatureInfo; | 43 | pub use hir::FnSignatureInfo; |
44 | 44 | ||
@@ -242,6 +242,27 @@ impl Query { | |||
242 | } | 242 | } |
243 | } | 243 | } |
244 | 244 | ||
245 | #[derive(Debug)] | ||
246 | pub struct NavigationTarget { | ||
247 | file_id: FileId, | ||
248 | symbol: FileSymbol, | ||
249 | } | ||
250 | |||
251 | impl 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)] |
247 | pub struct ReferenceResolution { | 268 | pub 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 | ||
256 | impl ReferenceResolution { | 277 | impl 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>> { |