@@ -8,8 +8,10 @@ use std::{
88use hir_def:: { db:: DefDatabase , AssocItemId , ModuleDefId , ModuleId } ;
99use hir_expand:: { db:: AstDatabase , diagnostics:: DiagnosticSink } ;
1010use ra_db:: { salsa, CrateId , FileId , FileLoader , FileLoaderDelegate , SourceDatabase , Upcast } ;
11- use rustc_hash:: FxHashSet ;
11+ use ra_syntax:: TextRange ;
12+ use rustc_hash:: { FxHashMap , FxHashSet } ;
1213use stdx:: format_to;
14+ use test_utils:: extract_annotations;
1315
1416use crate :: {
1517 db:: HirDatabase , diagnostics:: Diagnostic , expr:: ExprValidator ,
@@ -155,17 +157,27 @@ impl TestDB {
155157 ( buf, count)
156158 }
157159
158- pub fn all_files ( & self ) -> Vec < FileId > {
159- let mut res = Vec :: new ( ) ;
160+ pub fn extract_annotations ( & self ) -> FxHashMap < FileId , Vec < ( TextRange , String ) > > {
161+ let mut files = Vec :: new ( ) ;
160162 let crate_graph = self . crate_graph ( ) ;
161163 for krate in crate_graph. iter ( ) {
162164 let crate_def_map = self . crate_def_map ( krate) ;
163165 for ( module_id, _) in crate_def_map. modules . iter ( ) {
164166 let file_id = crate_def_map[ module_id] . origin . file_id ( ) ;
165- res . extend ( file_id)
167+ files . extend ( file_id)
166168 }
167169 }
168- res
170+ files
171+ . into_iter ( )
172+ . filter_map ( |file_id| {
173+ let text = self . file_text ( file_id) ;
174+ let annotations = extract_annotations ( & text) ;
175+ if annotations. is_empty ( ) {
176+ return None ;
177+ }
178+ Some ( ( file_id, annotations) )
179+ } )
180+ . collect ( )
169181 }
170182}
171183
0 commit comments