Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/navigation_target.rs')
| -rw-r--r-- | crates/ide/src/navigation_target.rs | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/crates/ide/src/navigation_target.rs b/crates/ide/src/navigation_target.rs index fc836d5540..bfd62e7624 100644 --- a/crates/ide/src/navigation_target.rs +++ b/crates/ide/src/navigation_target.rs @@ -220,7 +220,7 @@ impl TryToNav for Definition { fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> { match self { Definition::Local(it) => Some(it.to_nav(db)), - Definition::Label(it) => Some(it.to_nav(db)), + Definition::Label(it) => it.try_to_nav(db), Definition::Module(it) => Some(it.to_nav(db)), Definition::Macro(it) => it.try_to_nav(db), Definition::Field(it) => it.try_to_nav(db), @@ -562,12 +562,12 @@ impl ToNav for hir::Local { } } -impl ToNav for hir::Label { - fn to_nav(&self, db: &RootDatabase) -> UpmappingResult<NavigationTarget> { - let InFile { file_id, value } = self.source(db); +impl TryToNav for hir::Label { + fn try_to_nav(&self, db: &RootDatabase) -> Option<UpmappingResult<NavigationTarget>> { + let InFile { file_id, value } = self.source(db)?; let name = self.name(db).to_smol_str(); - orig_range_with_focus(db, file_id, value.syntax(), value.lifetime()).map( + Some(orig_range_with_focus(db, file_id, value.syntax(), value.lifetime()).map( |(FileRange { file_id, range: full_range }, focus_range)| NavigationTarget { file_id, name: name.clone(), @@ -579,7 +579,7 @@ impl ToNav for hir::Label { description: None, docs: None, }, - ) + )) } } @@ -926,4 +926,26 @@ struct Foo; let navs = analysis.symbol_search(Query::new("foo".to_owned()), !0).unwrap(); assert_eq!(navs.len(), 2) } + + #[test] + fn test_ensure_hidden_symbols_are_not_returned() { + let (analysis, _) = fixture::file( + r#" +fn foo() {} +struct Foo; +static __FOO_CALLSITE: () = (); +"#, + ); + + // It doesn't show the hidden symbol + let navs = analysis.symbol_search(Query::new("foo".to_owned()), !0).unwrap(); + assert_eq!(navs.len(), 2); + let navs = analysis.symbol_search(Query::new("_foo".to_owned()), !0).unwrap(); + assert_eq!(navs.len(), 0); + + // Unless we explicitly search for a `__` prefix + let query = Query::new("__foo".to_owned()); + let navs = analysis.symbol_search(query, !0).unwrap(); + assert_eq!(navs.len(), 1); + } } |