Skip to content

Commit 8a39519

Browse files
committed
Cleanup
1 parent 88267c8 commit 8a39519

File tree

5 files changed

+81
-79
lines changed

5 files changed

+81
-79
lines changed

crates/ra_ide/src/lib.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,77 @@ fn analysis_is_send() {
479479
fn is_send<T: Send>() {}
480480
is_send::<Analysis>();
481481
}
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+
}

crates/ra_ide_db/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
24
35
pub mod line_index;
46
pub mod line_index_utils;

crates/ra_ide_db/src/line_index.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! FIXME: write short doc here
1+
//! `LineIndex` maps flat `TextUnit` offsets into `(Line, Column)`
2+
//! representation.
23
34
use ra_syntax::TextUnit;
45
use rustc_hash::FxHashMap;

crates/ra_ide_db/src/line_index_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct LineIndexStepIter<'a> {
1818
utf16_chars: Option<(TextUnit, std::slice::Iter<'a, Utf16Char>)>,
1919
}
2020

21-
impl<'a> LineIndexStepIter<'a> {
21+
impl LineIndexStepIter<'_> {
2222
fn from(line_index: &LineIndex) -> LineIndexStepIter {
2323
let mut x = LineIndexStepIter { line_index, next_newline_idx: 0, utf16_chars: None };
2424
// skip first newline since it's not real
@@ -27,7 +27,7 @@ impl<'a> LineIndexStepIter<'a> {
2727
}
2828
}
2929

30-
impl<'a> Iterator for LineIndexStepIter<'a> {
30+
impl Iterator for LineIndexStepIter<'_> {
3131
type Item = Step;
3232
fn next(&mut self) -> Option<Step> {
3333
self.utf16_chars

crates/ra_ide_db/src/symbol_index.rs

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -369,78 +369,3 @@ fn to_file_symbol(node: &SyntaxNode, file_id: FileId) -> Option<FileSymbol> {
369369
container_name: None,
370370
})
371371
}
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-
}

0 commit comments

Comments
 (0)