diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/lib.rs | 74 | ||||
-rw-r--r-- | crates/ra_ide_db/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_db/src/line_index.rs | 3 | ||||
-rw-r--r-- | crates/ra_ide_db/src/line_index_utils.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_db/src/symbol_index.rs | 75 |
5 files changed, 81 insertions, 79 deletions
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 013b960c1..5fb111a90 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -479,3 +479,77 @@ fn analysis_is_send() { | |||
479 | fn is_send<T: Send>() {} | 479 | fn is_send<T: Send>() {} |
480 | is_send::<Analysis>(); | 480 | is_send::<Analysis>(); |
481 | } | 481 | } |
482 | |||
483 | #[cfg(test)] | ||
484 | mod tests { | ||
485 | use crate::{display::NavigationTarget, mock_analysis::single_file, Query}; | ||
486 | use ra_syntax::{ | ||
487 | SmolStr, | ||
488 | SyntaxKind::{FN_DEF, STRUCT_DEF}, | ||
489 | }; | ||
490 | |||
491 | #[test] | ||
492 | fn test_world_symbols_with_no_container() { | ||
493 | let code = r#" | ||
494 | enum FooInner { } | ||
495 | "#; | ||
496 | |||
497 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
498 | |||
499 | let s = symbols.pop().unwrap(); | ||
500 | |||
501 | assert_eq!(s.name(), "FooInner"); | ||
502 | assert!(s.container_name().is_none()); | ||
503 | } | ||
504 | |||
505 | #[test] | ||
506 | fn test_world_symbols_include_container_name() { | ||
507 | let code = r#" | ||
508 | fn foo() { | ||
509 | enum FooInner { } | ||
510 | } | ||
511 | "#; | ||
512 | |||
513 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
514 | |||
515 | let s = symbols.pop().unwrap(); | ||
516 | |||
517 | assert_eq!(s.name(), "FooInner"); | ||
518 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
519 | |||
520 | let code = r#" | ||
521 | mod foo { | ||
522 | struct FooInner; | ||
523 | } | ||
524 | "#; | ||
525 | |||
526 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
527 | |||
528 | let s = symbols.pop().unwrap(); | ||
529 | |||
530 | assert_eq!(s.name(), "FooInner"); | ||
531 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
532 | } | ||
533 | |||
534 | #[test] | ||
535 | fn test_world_symbols_are_case_sensitive() { | ||
536 | let code = r#" | ||
537 | fn foo() {} | ||
538 | |||
539 | struct Foo; | ||
540 | "#; | ||
541 | |||
542 | let symbols = get_symbols_matching(code, "Foo"); | ||
543 | |||
544 | let fn_match = symbols.iter().find(|s| s.name() == "foo").map(|s| s.kind()); | ||
545 | let struct_match = symbols.iter().find(|s| s.name() == "Foo").map(|s| s.kind()); | ||
546 | |||
547 | assert_eq!(fn_match, Some(FN_DEF)); | ||
548 | assert_eq!(struct_match, Some(STRUCT_DEF)); | ||
549 | } | ||
550 | |||
551 | fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> { | ||
552 | let (analysis, _) = single_file(text); | ||
553 | analysis.symbol_search(Query::new(query.into())).unwrap() | ||
554 | } | ||
555 | } | ||
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index d04c59a4a..e922d1e5f 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -1,4 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! This crate defines the core datastructure representing IDE state -- `RootDatabase`. |
2 | //! | ||
3 | //! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search. | ||
2 | 4 | ||
3 | pub mod line_index; | 5 | pub mod line_index; |
4 | pub mod line_index_utils; | 6 | pub mod line_index_utils; |
diff --git a/crates/ra_ide_db/src/line_index.rs b/crates/ra_ide_db/src/line_index.rs index 6f99ca3a7..452c87ac5 100644 --- a/crates/ra_ide_db/src/line_index.rs +++ b/crates/ra_ide_db/src/line_index.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! `LineIndex` maps flat `TextUnit` offsets into `(Line, Column)` |
2 | //! representation. | ||
2 | 3 | ||
3 | use ra_syntax::TextUnit; | 4 | use ra_syntax::TextUnit; |
4 | use rustc_hash::FxHashMap; | 5 | use rustc_hash::FxHashMap; |
diff --git a/crates/ra_ide_db/src/line_index_utils.rs b/crates/ra_ide_db/src/line_index_utils.rs index daf9d8ab9..effbef11d 100644 --- a/crates/ra_ide_db/src/line_index_utils.rs +++ b/crates/ra_ide_db/src/line_index_utils.rs | |||
@@ -18,7 +18,7 @@ struct LineIndexStepIter<'a> { | |||
18 | utf16_chars: Option<(TextUnit, std::slice::Iter<'a, Utf16Char>)>, | 18 | utf16_chars: Option<(TextUnit, std::slice::Iter<'a, Utf16Char>)>, |
19 | } | 19 | } |
20 | 20 | ||
21 | impl<'a> LineIndexStepIter<'a> { | 21 | impl LineIndexStepIter<'_> { |
22 | fn from(line_index: &LineIndex) -> LineIndexStepIter { | 22 | fn from(line_index: &LineIndex) -> LineIndexStepIter { |
23 | let mut x = LineIndexStepIter { line_index, next_newline_idx: 0, utf16_chars: None }; | 23 | let mut x = LineIndexStepIter { line_index, next_newline_idx: 0, utf16_chars: None }; |
24 | // skip first newline since it's not real | 24 | // skip first newline since it's not real |
@@ -27,7 +27,7 @@ impl<'a> LineIndexStepIter<'a> { | |||
27 | } | 27 | } |
28 | } | 28 | } |
29 | 29 | ||
30 | impl<'a> Iterator for LineIndexStepIter<'a> { | 30 | impl Iterator for LineIndexStepIter<'_> { |
31 | type Item = Step; | 31 | type Item = Step; |
32 | fn next(&mut self) -> Option<Step> { | 32 | fn next(&mut self) -> Option<Step> { |
33 | self.utf16_chars | 33 | self.utf16_chars |
diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs index 436b4497f..ddad03633 100644 --- a/crates/ra_ide_db/src/symbol_index.rs +++ b/crates/ra_ide_db/src/symbol_index.rs | |||
@@ -369,78 +369,3 @@ fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> { | |||
369 | container_name: None, | 369 | container_name: None, |
370 | }) | 370 | }) |
371 | } | 371 | } |
372 | |||
373 | // TODO: fix this | ||
374 | #[cfg(never)] | ||
375 | mod tests { | ||
376 | use crate::{display::NavigationTarget, mock_analysis::single_file, Query}; | ||
377 | use ra_syntax::{ | ||
378 | SmolStr, | ||
379 | SyntaxKind::{FN_DEF, STRUCT_DEF}, | ||
380 | }; | ||
381 | |||
382 | #[test] | ||
383 | fn test_world_symbols_with_no_container() { | ||
384 | let code = r#" | ||
385 | enum FooInner { } | ||
386 | "#; | ||
387 | |||
388 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
389 | |||
390 | let s = symbols.pop().unwrap(); | ||
391 | |||
392 | assert_eq!(s.name(), "FooInner"); | ||
393 | assert!(s.container_name().is_none()); | ||
394 | } | ||
395 | |||
396 | #[test] | ||
397 | fn test_world_symbols_include_container_name() { | ||
398 | let code = r#" | ||
399 | fn foo() { | ||
400 | enum FooInner { } | ||
401 | } | ||
402 | "#; | ||
403 | |||
404 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
405 | |||
406 | let s = symbols.pop().unwrap(); | ||
407 | |||
408 | assert_eq!(s.name(), "FooInner"); | ||
409 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
410 | |||
411 | let code = r#" | ||
412 | mod foo { | ||
413 | struct FooInner; | ||
414 | } | ||
415 | "#; | ||
416 | |||
417 | let mut symbols = get_symbols_matching(code, "FooInner"); | ||
418 | |||
419 | let s = symbols.pop().unwrap(); | ||
420 | |||
421 | assert_eq!(s.name(), "FooInner"); | ||
422 | assert_eq!(s.container_name(), Some(&SmolStr::new("foo"))); | ||
423 | } | ||
424 | |||
425 | #[test] | ||
426 | fn test_world_symbols_are_case_sensitive() { | ||
427 | let code = r#" | ||
428 | fn foo() {} | ||
429 | |||
430 | struct Foo; | ||
431 | "#; | ||
432 | |||
433 | let symbols = get_symbols_matching(code, "Foo"); | ||
434 | |||
435 | let fn_match = symbols.iter().find(|s| s.name() == "foo").map(|s| s.kind()); | ||
436 | let struct_match = symbols.iter().find(|s| s.name() == "Foo").map(|s| s.kind()); | ||
437 | |||
438 | assert_eq!(fn_match, Some(FN_DEF)); | ||
439 | assert_eq!(struct_match, Some(STRUCT_DEF)); | ||
440 | } | ||
441 | |||
442 | fn get_symbols_matching(text: &str, query: &str) -> Vec<NavigationTarget> { | ||
443 | let (analysis, _) = single_file(text); | ||
444 | analysis.symbol_search(Query::new(query.into())).unwrap() | ||
445 | } | ||
446 | } | ||