@@ -51,26 +51,26 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
51
51
} )
52
52
. filter_map ( |submodule_file| {
53
53
let submodule_path = source_root. path_for_file ( & submodule_file) ?;
54
- if !is_special_rust_file_path ( & submodule_path)
55
- && submodule_path. parent ( ) ? == directory_to_look_for_submodules
56
- {
57
- submodule_path. file_name_and_extension ( )
58
- } else {
59
- None
60
- }
61
- } )
62
- . filter_map ( |submodule_file_name_and_extension| match submodule_file_name_and_extension {
63
- ( file_name, Some ( "rs" ) ) => Some ( file_name. to_owned ( ) ) ,
64
- ( subdirectory_name, None ) => {
65
- let mod_rs_path =
66
- directory_to_look_for_submodules. join ( subdirectory_name) ?. join ( "mod.rs" ) ?;
67
- if source_root. file_for_path ( & mod_rs_path) . is_some ( ) {
68
- Some ( subdirectory_name. to_owned ( ) )
69
- } else {
70
- None
54
+ let directory_with_submodule = submodule_path. parent ( ) ?;
55
+ match submodule_path. file_name_and_extension ( ) ? {
56
+ ( "lib" , Some ( "rs" ) ) | ( "main" , Some ( "rs" ) ) => None ,
57
+ ( "mod" , Some ( "rs" ) ) => {
58
+ if directory_with_submodule. parent ( ) ? == directory_to_look_for_submodules {
59
+ match directory_with_submodule. file_name_and_extension ( ) ? {
60
+ ( directory_name, None ) => Some ( directory_name. to_owned ( ) ) ,
61
+ _ => None ,
62
+ }
63
+ } else {
64
+ None
65
+ }
71
66
}
67
+ ( file_name, Some ( "rs" ) )
68
+ if directory_with_submodule == directory_to_look_for_submodules =>
69
+ {
70
+ Some ( file_name. to_owned ( ) )
71
+ }
72
+ _ => None ,
72
73
}
73
- _ => None ,
74
74
} )
75
75
. filter ( |name| !existing_mod_declarations. contains ( name) )
76
76
. for_each ( |submodule_name| {
@@ -87,41 +87,34 @@ pub(super) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
87
87
Some ( ( ) )
88
88
}
89
89
90
- fn is_special_rust_file_path ( path : & VfsPath ) -> bool {
91
- matches ! (
92
- path. file_name_and_extension( ) ,
93
- Some ( ( "mod" , Some ( "rs" ) ) ) | Some ( ( "lib" , Some ( "rs" ) ) ) | Some ( ( "main" , Some ( "rs" ) ) )
94
- )
95
- }
96
-
97
90
fn directory_to_look_for_submodules (
98
91
module : Module ,
99
92
db : & RootDatabase ,
100
93
module_file_path : & VfsPath ,
101
94
) -> Option < VfsPath > {
102
- let module_directory_path = module_file_path. parent ( ) ?;
103
- let base_directory = if is_special_rust_file_path ( module_file_path) {
104
- Some ( module_directory_path)
105
- } else if let ( regular_rust_file_name, Some ( "rs" ) ) =
106
- module_file_path. file_name_and_extension ( ) ?
107
- {
108
- if matches ! (
109
- (
110
- module_directory_path
111
- . parent( )
112
- . as_ref( )
113
- . and_then( |path| path. file_name_and_extension( ) ) ,
114
- module_directory_path. file_name_and_extension( ) ,
115
- ) ,
116
- ( Some ( ( "src" , None ) ) , Some ( ( "bin" , None ) ) )
117
- ) {
118
- // files in /src/bin/ can import each other directly
119
- Some ( module_directory_path)
120
- } else {
121
- module_directory_path. join ( regular_rust_file_name)
95
+ let directory_with_module_path = module_file_path. parent ( ) ?;
96
+ let base_directory = match module_file_path. file_name_and_extension ( ) ? {
97
+ ( "mod" , Some ( "rs" ) ) | ( "lib" , Some ( "rs" ) ) | ( "main" , Some ( "rs" ) ) => {
98
+ Some ( directory_with_module_path)
99
+ }
100
+ ( regular_rust_file_name, Some ( "rs" ) ) => {
101
+ if matches ! (
102
+ (
103
+ directory_with_module_path
104
+ . parent( )
105
+ . as_ref( )
106
+ . and_then( |path| path. file_name_and_extension( ) ) ,
107
+ directory_with_module_path. file_name_and_extension( ) ,
108
+ ) ,
109
+ ( Some ( ( "src" , None ) ) , Some ( ( "bin" , None ) ) )
110
+ ) {
111
+ // files in /src/bin/ can import each other directly
112
+ Some ( directory_with_module_path)
113
+ } else {
114
+ directory_with_module_path. join ( regular_rust_file_name)
115
+ }
122
116
}
123
- } else {
124
- None
117
+ _ => None ,
125
118
} ?;
126
119
127
120
let mut resulting_path = base_directory;
0 commit comments