File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ pub struct Query {
5353 case_sensitive : bool ,
5454 only_types : bool ,
5555 libs : bool ,
56+ include_hidden : bool ,
5657}
5758
5859impl Query {
@@ -66,9 +67,14 @@ impl Query {
6667 mode : SearchMode :: Fuzzy ,
6768 assoc_mode : AssocSearchMode :: Include ,
6869 case_sensitive : false ,
70+ include_hidden : false ,
6971 }
7072 }
7173
74+ pub fn include_hidden ( & mut self ) {
75+ self . include_hidden = true ;
76+ }
77+
7278 pub fn only_types ( & mut self ) {
7379 self . only_types = true ;
7480 }
@@ -192,7 +198,8 @@ impl<DB> std::ops::Deref for Snap<DB> {
192198// Note that filtering does not currently work in VSCode due to the editor never
193199// sending the special symbols to the language server. Instead, you can configure
194200// the filtering via the `rust-analyzer.workspace.symbol.search.scope` and
195- // `rust-analyzer.workspace.symbol.search.kind` settings.
201+ // `rust-analyzer.workspace.symbol.search.kind` settings. Symbols prefixed
202+ // with `__` are hidden from the search results unless configured otherwise.
196203//
197204// |===
198205// | Editor | Shortcut
@@ -374,6 +381,9 @@ impl Query {
374381 if non_type_for_type_only_query || !self . matches_assoc_mode ( symbol. is_assoc ) {
375382 continue ;
376383 }
384+ if !self . include_hidden && symbol. name . starts_with ( "__" ) {
385+ continue ;
386+ }
377387 if self . mode . check ( & self . query , self . case_sensitive , & symbol. name ) {
378388 cb ( symbol) ;
379389 }
Original file line number Diff line number Diff line change @@ -926,4 +926,25 @@ struct Foo;
926926 let navs = analysis. symbol_search ( Query :: new ( "foo" . to_owned ( ) ) , !0 ) . unwrap ( ) ;
927927 assert_eq ! ( navs. len( ) , 2 )
928928 }
929+
930+ #[ test]
931+ fn test_ensure_hidden_symbols_are_not_returned ( ) {
932+ let ( analysis, _) = fixture:: file (
933+ r#"
934+ fn foo() {}
935+ struct Foo;
936+ static __FOO_CALLSITE: () = ();
937+ "# ,
938+ ) ;
939+
940+ // It doesn't show the hidden symbol
941+ let navs = analysis. symbol_search ( Query :: new ( "foo" . to_owned ( ) ) , !0 ) . unwrap ( ) ;
942+ assert_eq ! ( navs. len( ) , 2 ) ;
943+
944+ // Unless we configure a query to show hidden symbols
945+ let mut query = Query :: new ( "foo" . to_owned ( ) ) ;
946+ query. include_hidden ( ) ;
947+ let navs = analysis. symbol_search ( query, !0 ) . unwrap ( ) ;
948+ assert_eq ! ( navs. len( ) , 3 ) ;
949+ }
929950}
You can’t perform that action at this time.
0 commit comments