11use std:: borrow:: Cow ;
2+ use std:: fmt;
23use std:: iter:: FusedIterator ;
34use std:: str:: Split ;
45
@@ -611,11 +612,17 @@ fn resolve_name(db: &dyn Db, name: &ModuleName) -> Option<(SearchPath, ResolvedM
611612 // stubs package doesn't exist, continue with the regular package
612613 }
613614 Err ( PackageKind :: Regular ) => {
615+ tracing:: trace!(
616+ "Stub-package in `{search_path} doesn't contain module: `{name}`"
617+ ) ;
614618 // stub exists, but the module doesn't.
615619 // TODO: Support partial packages.
616620 return None ;
617621 }
618622 Err ( PackageKind :: Namespace ) => {
623+ tracing:: trace!(
624+ "Stub-package in `{search_path} doesn't contain module: `{name}` but it is a namespace package, keep going."
625+ ) ;
619626 // stub exists, but the module doesn't. But this is a namespace package,
620627 // keep searchig the next search path for a stub package with the same name.
621628 continue ;
@@ -625,13 +632,20 @@ fn resolve_name(db: &dyn Db, name: &ModuleName) -> Option<(SearchPath, ResolvedM
625632
626633 match resolve_module_in_search_path ( & resolver_state, & name, search_path) {
627634 Ok ( ( file, kind) ) => return Some ( ( search_path. clone ( ) , ResolvedModule { kind, file } ) ) ,
628- Err ( kind) => {
629- // For regular packages, don't search the next search path. All files of that
630- // package must be in the same location
631- if kind. is_regular_package ( ) {
635+ Err ( kind) => match kind {
636+ PackageKind :: Root => { }
637+ PackageKind :: Regular => {
638+ // For regular packages, don't search the next search path. All files of that
639+ // package must be in the same location
640+ tracing:: trace!( "Package in `{search_path} doesn't contain module: `{name}`" ) ;
632641 return None ;
633642 }
634- }
643+ PackageKind :: Namespace => {
644+ tracing:: trace!(
645+ "Package in `{search_path} doesn't contain module: `{name}` but it is a namespace package, keep going."
646+ ) ;
647+ }
648+ } ,
635649 }
636650 }
637651
@@ -787,12 +801,6 @@ enum PackageKind {
787801 Namespace ,
788802}
789803
790- impl PackageKind {
791- const fn is_regular_package ( self ) -> bool {
792- matches ! ( self , PackageKind :: Regular )
793- }
794- }
795-
796804pub ( super ) struct ResolverContext < ' db > {
797805 pub ( super ) db : & ' db dyn Db ,
798806 pub ( super ) python_version : PythonVersion ,
@@ -830,6 +838,12 @@ impl RelaxedModuleName {
830838 }
831839}
832840
841+ impl fmt:: Display for RelaxedModuleName {
842+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
843+ self . 0 . fmt ( f)
844+ }
845+ }
846+
833847#[ cfg( test) ]
834848mod tests {
835849 use ruff_db:: files:: { system_path_to_file, File , FilePath } ;
0 commit comments