@@ -71,7 +71,7 @@ pub enum ReferenceAccess {
7171/// For `pub(crate)` things it's a crate, for `pub` things it's a crate and dependant crates.
7272/// In some cases, the location of the references is known to within a `TextRange`,
7373/// e.g. for things like local variables.
74- #[ derive( Clone ) ]
74+ #[ derive( Clone , Debug ) ]
7575pub struct SearchScope {
7676 entries : FxHashMap < FileId , Option < TextRange > > ,
7777}
@@ -216,6 +216,14 @@ impl Definition {
216216 return SearchScope :: crate_graph ( db) ;
217217 }
218218
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+
219227 let module = match self . module ( db) {
220228 Some ( it) => it,
221229 None => return SearchScope :: empty ( ) ,
@@ -273,13 +281,22 @@ impl Definition {
273281 }
274282
275283 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 => {
278297 SearchScope :: reverse_dependencies ( db, module. krate ( ) )
279- } else {
280- SearchScope :: krate ( db, module. krate ( ) )
281- } ;
282- }
298+ }
299+ } ;
283300 }
284301
285302 let vis = self . visibility ( db) ;
0 commit comments