diff options
author | Aleksey Kladov <[email protected]> | 2019-01-02 14:09:39 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-02 14:09:39 +0000 |
commit | 830abe0c1b9fdbc20a78771d0b3df37d9eabdc3e (patch) | |
tree | f111e68f8f05274baaa2310a60dda34f6d1b6fa0 /crates/ra_analysis | |
parent | d25c89f7608cb15e8c5ae08a92b6a7a6d6f308b8 (diff) |
use navigation target in API
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 6 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 20 |
2 files changed, 19 insertions, 7 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 836fb89f5..b513736bb 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -205,7 +205,7 @@ impl AnalysisImpl { | |||
205 | 205 | ||
206 | /// This returns `Vec` because a module may be included from several places. We | 206 | /// This returns `Vec` because a module may be included from several places. We |
207 | /// don't handle this case yet though, so the Vec has length at most one. | 207 | /// don't handle this case yet though, so the Vec has length at most one. |
208 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 208 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { |
209 | let descr = match source_binder::module_from_position(&*self.db, position)? { | 209 | let descr = match source_binder::module_from_position(&*self.db, position)? { |
210 | None => return Ok(Vec::new()), | 210 | None => return Ok(Vec::new()), |
211 | Some(it) => it, | 211 | Some(it) => it, |
@@ -216,12 +216,12 @@ impl AnalysisImpl { | |||
216 | }; | 216 | }; |
217 | let decl = decl.borrowed(); | 217 | let decl = decl.borrowed(); |
218 | let decl_name = decl.name().unwrap(); | 218 | let decl_name = decl.name().unwrap(); |
219 | let sym = FileSymbol { | 219 | let symbol = FileSymbol { |
220 | name: decl_name.text(), | 220 | name: decl_name.text(), |
221 | node_range: decl_name.syntax().range(), | 221 | node_range: decl_name.syntax().range(), |
222 | kind: MODULE, | 222 | kind: MODULE, |
223 | }; | 223 | }; |
224 | Ok(vec![(file_id, sym)]) | 224 | Ok(vec![NavigationTarget { file_id, symbol }]) |
225 | } | 225 | } |
226 | /// Returns `Vec` for the same reason as `parent_module` | 226 | /// Returns `Vec` for the same reason as `parent_module` |
227 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { | 227 | pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 4d8bdb61b..75867ee86 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -24,7 +24,7 @@ mod macros; | |||
24 | use std::{fmt, sync::Arc}; | 24 | use std::{fmt, sync::Arc}; |
25 | 25 | ||
26 | use rustc_hash::FxHashMap; | 26 | use rustc_hash::FxHashMap; |
27 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; | 27 | use ra_syntax::{SourceFileNode, TextRange, TextUnit, SmolStr, SyntaxKind}; |
28 | use ra_text_edit::TextEdit; | 28 | use ra_text_edit::TextEdit; |
29 | use rayon::prelude::*; | 29 | use rayon::prelude::*; |
30 | use relative_path::RelativePathBuf; | 30 | use relative_path::RelativePathBuf; |
@@ -251,6 +251,12 @@ pub struct NavigationTarget { | |||
251 | } | 251 | } |
252 | 252 | ||
253 | impl NavigationTarget { | 253 | impl NavigationTarget { |
254 | pub fn name(&self) -> SmolStr { | ||
255 | self.symbol.name.clone() | ||
256 | } | ||
257 | pub fn kind(&self) -> SyntaxKind { | ||
258 | self.symbol.kind | ||
259 | } | ||
254 | pub fn file_id(&self) -> FileId { | 260 | pub fn file_id(&self) -> FileId { |
255 | self.file_id | 261 | self.file_id |
256 | } | 262 | } |
@@ -337,8 +343,14 @@ impl Analysis { | |||
337 | let file = self.imp.file_syntax(file_id); | 343 | let file = self.imp.file_syntax(file_id); |
338 | ra_editor::folding_ranges(&file) | 344 | ra_editor::folding_ranges(&file) |
339 | } | 345 | } |
340 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 346 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { |
341 | self.imp.world_symbols(query) | 347 | let res = self |
348 | .imp | ||
349 | .world_symbols(query)? | ||
350 | .into_iter() | ||
351 | .map(|(file_id, symbol)| NavigationTarget { file_id, symbol }) | ||
352 | .collect(); | ||
353 | Ok(res) | ||
342 | } | 354 | } |
343 | pub fn approximately_resolve_symbol( | 355 | pub fn approximately_resolve_symbol( |
344 | &self, | 356 | &self, |
@@ -352,7 +364,7 @@ impl Analysis { | |||
352 | pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { | 364 | pub fn doc_text_for(&self, nav: NavigationTarget) -> Cancelable<Option<String>> { |
353 | self.imp.doc_text_for(nav) | 365 | self.imp.doc_text_for(nav) |
354 | } | 366 | } |
355 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<(FileId, FileSymbol)>> { | 367 | pub fn parent_module(&self, position: FilePosition) -> Cancelable<Vec<NavigationTarget>> { |
356 | self.imp.parent_module(position) | 368 | self.imp.parent_module(position) |
357 | } | 369 | } |
358 | pub fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { | 370 | pub fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { |