diff options
author | Sergey Parilin <[email protected]> | 2019-04-02 15:55:14 +0100 |
---|---|---|
committer | Sergey Parilin <[email protected]> | 2019-04-02 15:55:14 +0100 |
commit | b74449e9952846a8ea66c3507e52c24348d6dbc9 (patch) | |
tree | 00bb1101334b0bf1b189a2e6451cb28e0af959a1 /crates/ra_ide_api/src/symbol_index.rs | |
parent | 9b73f809596e955216dde24fcf921d6985a1a767 (diff) | |
parent | 849d7428aa6b733d452b2ebc55ec322d96345f49 (diff) |
Merge remote-tracking branch 'upstream/master' into issue961_profiling
Diffstat (limited to 'crates/ra_ide_api/src/symbol_index.rs')
-rw-r--r-- | crates/ra_ide_api/src/symbol_index.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs index 0978d164a..0eadc4e71 100644 --- a/crates/ra_ide_api/src/symbol_index.rs +++ b/crates/ra_ide_api/src/symbol_index.rs | |||
@@ -270,3 +270,61 @@ fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> { | |||
270 | container_name: None, | 270 | container_name: None, |
271 | }) | 271 | }) |
272 | } | 272 | } |
273 | |||
274 | #[cfg(test)] | ||
275 | mod tests { | ||
276 | use ra_syntax::SmolStr; | ||
277 | use crate::{ | ||
278 | navigation_target::NavigationTarget, | ||
279 | mock_analysis::single_file, | ||
280 | Query, | ||
281 | }; | ||
282 | |||
283 | #[test] | ||
284 | fn test_world_symbols_with_no_container() { | ||
285 | let code = r#" | ||
286 | enum FooInner { } | ||
287 | "#; | ||
288 | |||
289 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
290 | |||
291 | let s = symbols.pop().unwrap(); | ||
292 | |||
293 | assert_eq!(s.name(), "FooInner"); | ||
294 | assert!(s.container_name().is_none()); | ||
295 | } | ||
296 | |||
297 | #[test] | ||
298 | fn test_world_symbols_include_container_name() { | ||
299 | let code = r#" | ||
300 | fn foo() { | ||
301 | enum FooInner { } | ||
302 | } | ||
303 | "#; | ||
304 | |||
305 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
306 | |||
307 | let s = symbols.pop().unwrap(); | ||
308 | |||
309 | assert_eq!(s.name(), "FooInner"); | ||
310 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
311 | |||
312 | let code = r#" | ||
313 | mod foo { | ||
314 | struct FooInner; | ||
315 | } | ||
316 | "#; | ||
317 | |||
318 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
319 | |||
320 | let s = symbols.pop().unwrap(); | ||
321 | |||
322 | assert_eq!(s.name(), "FooInner"); | ||
323 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
324 | } | ||
325 | |||
326 | fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> { | ||
327 | let (analysis, _) = single_file(text); | ||
328 | analysis.symbol_search(Query::new(query.into())).unwrap() | ||
329 | } | ||
330 | } | ||