diff options
author | Aleksey Kladov <[email protected]> | 2020-02-06 13:43:46 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-06 14:10:07 +0000 |
commit | 8a39519e1cef6a11a418692a8ca1dc5131a80974 (patch) | |
tree | 7152df60a836e871c9c4bfee2f7d555d43cf5f55 /crates/ra_ide_db | |
parent | 88267c86c0c49de395973574d2516ab904091cfb (diff) |
Cleanup
Diffstat (limited to 'crates/ra_ide_db')
-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 |
4 files changed, 7 insertions, 79 deletions
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 | } | ||