@@ -71,7 +71,7 @@ pub enum ReferenceAccess {
71
71
/// For `pub(crate)` things it's a crate, for `pub` things it's a crate and dependant crates.
72
72
/// In some cases, the location of the references is known to within a `TextRange`,
73
73
/// e.g. for things like local variables.
74
- #[ derive( Clone ) ]
74
+ #[ derive( Clone , Debug ) ]
75
75
pub struct SearchScope {
76
76
entries : FxHashMap < FileId , Option < TextRange > > ,
77
77
}
@@ -216,6 +216,14 @@ impl Definition {
216
216
return SearchScope :: crate_graph ( db) ;
217
217
}
218
218
219
+ // def is crate root
220
+ // FIXME: We don't do searches for crates currently, as a crate does not actually have a single name
221
+ if let & Definition :: ModuleDef ( hir:: ModuleDef :: Module ( module) ) = self {
222
+ if module. crate_root ( db) == module {
223
+ return SearchScope :: reverse_dependencies ( db, module. krate ( ) ) ;
224
+ }
225
+ }
226
+
219
227
let module = match self . module ( db) {
220
228
Some ( it) => it,
221
229
None => return SearchScope :: empty ( ) ,
@@ -273,13 +281,22 @@ impl Definition {
273
281
}
274
282
275
283
if let Definition :: Macro ( macro_def) = self {
276
- if macro_def. kind ( ) == hir:: MacroKind :: Declarative {
277
- return if macro_def. attrs ( db) . by_key ( "macro_export" ) . exists ( ) {
284
+ return match macro_def. kind ( ) {
285
+ hir:: MacroKind :: Declarative => {
286
+ if macro_def. attrs ( db) . by_key ( "macro_export" ) . exists ( ) {
287
+ SearchScope :: reverse_dependencies ( db, module. krate ( ) )
288
+ } else {
289
+ SearchScope :: krate ( db, module. krate ( ) )
290
+ }
291
+ }
292
+ hir:: MacroKind :: BuiltIn => SearchScope :: crate_graph ( db) ,
293
+ // FIXME: We don't actually see derives in derive attributes as these do not
294
+ // expand to something that references the derive macro in the output.
295
+ // We could get around this by emitting dummy `use DeriveMacroPathHere as _;` items maybe?
296
+ hir:: MacroKind :: Derive | hir:: MacroKind :: Attr | hir:: MacroKind :: ProcMacro => {
278
297
SearchScope :: reverse_dependencies ( db, module. krate ( ) )
279
- } else {
280
- SearchScope :: krate ( db, module. krate ( ) )
281
- } ;
282
- }
298
+ }
299
+ } ;
283
300
}
284
301
285
302
let vis = self . visibility ( db) ;
0 commit comments