@@ -134,19 +134,18 @@ pub(crate) fn fetch_dependency_list(
134
134
_params : lsp_ext:: FetchDependencyListParams ,
135
135
) -> Result < lsp_ext:: FetchDependencyListResult > {
136
136
let crates = state. analysis . fetch_crates ( ) ?;
137
- Ok ( FetchDependencyListResult {
138
- crates : crates
139
- . into_iter ( )
140
- . filter_map ( |it| {
141
- let root_file_path = state. file_id_to_file_path ( it. root_file_id ) ;
142
- crate_path ( it. name . as_ref ( ) , root_file_path) . map ( |crate_path| CrateInfoResult {
143
- name : it. name ,
144
- version : it. version ,
145
- path : crate_path. to_string ( ) ,
146
- } )
137
+ let crate_infos = crates
138
+ . into_iter ( )
139
+ . filter_map ( |it| {
140
+ let root_file_path = state. file_id_to_file_path ( it. root_file_id ) ;
141
+ crate_path ( it. name . as_ref ( ) , root_file_path) . map ( |path| CrateInfoResult {
142
+ name : it. name ,
143
+ version : it. version ,
144
+ path : path. to_string ( ) ,
147
145
} )
148
- . collect ( ) ,
149
- } )
146
+ } )
147
+ . collect ( ) ;
148
+ Ok ( FetchDependencyListResult { crates : crate_infos } )
150
149
}
151
150
152
151
pub ( crate ) fn handle_shuffle_crate_graph ( state : & mut GlobalState , _: ( ) ) -> Result < ( ) > {
@@ -1190,7 +1189,7 @@ pub(crate) fn handle_code_action_resolve(
1190
1189
"Failed to parse action id string '{}': {e}" ,
1191
1190
params. id
1192
1191
) )
1193
- . into ( ) )
1192
+ . into ( ) ) ;
1194
1193
}
1195
1194
} ;
1196
1195
@@ -1210,14 +1209,14 @@ pub(crate) fn handle_code_action_resolve(
1210
1209
"Failed to find the assist for index {} provided by the resolve request. Resolve request assist id: {}" ,
1211
1210
assist_index, params. id,
1212
1211
) )
1213
- . into ( ) )
1212
+ . into ( ) )
1214
1213
} ;
1215
1214
if assist. id . 0 != expected_assist_id || assist. id . 1 != expected_kind {
1216
1215
return Err ( invalid_params_error ( format ! (
1217
1216
"Mismatching assist at index {} for the resolve parameters given. Resolve request assist id: {}, actual id: {:?}." ,
1218
1217
assist_index, params. id, assist. id
1219
1218
) )
1220
- . into ( ) ) ;
1219
+ . into ( ) ) ;
1221
1220
}
1222
1221
let ca = to_proto:: code_action ( & snap, assist. clone ( ) , None ) ?;
1223
1222
code_action. edit = ca. edit ;
@@ -1287,7 +1286,7 @@ pub(crate) fn handle_code_lens_resolve(
1287
1286
snap : GlobalStateSnapshot ,
1288
1287
code_lens : CodeLens ,
1289
1288
) -> Result < CodeLens > {
1290
- let Some ( annotation) = from_proto:: annotation ( & snap, code_lens. clone ( ) ) ? else { return Ok ( code_lens) } ;
1289
+ let Some ( annotation) = from_proto:: annotation ( & snap, code_lens. clone ( ) ) ? else { return Ok ( code_lens) ; } ;
1291
1290
let annotation = snap. analysis . resolve_annotation ( annotation) ?;
1292
1291
1293
1292
let mut acc = Vec :: new ( ) ;
@@ -1934,23 +1933,33 @@ fn run_rustfmt(
1934
1933
}
1935
1934
}
1936
1935
1937
- //Thats a best effort to try and find the crate path
1936
+ /// Searches for the directory of a Rust crate with a given name in the directory tree
1937
+ /// of the root file of that crate.
1938
+ ///
1939
+ /// # Arguments
1940
+ ///
1941
+ /// * `crate_name`: The name of the crate to search for. This should be a `Some` value if
1942
+ /// a crate name has been specified, or `None` if no crate name has been specified.
1943
+ /// * `root_file_path`: The path to the root file of the crate.
1944
+ ///
1945
+ /// # Returns
1946
+ ///
1947
+ /// An `Option` value representing the path to the directory of the crate with the given
1948
+ /// name, if such a crate is found. If no crate with the given name is found, this function
1949
+ /// returns `None`.
1938
1950
fn crate_path ( crate_name : Option < & String > , root_file_path : VfsPath ) -> Option < VfsPath > {
1939
1951
crate_name. and_then ( |crate_name| {
1940
- let mut crate_path = None ;
1941
1952
let mut root_path = root_file_path;
1942
1953
while let Some ( path) = root_path. parent ( ) {
1943
- match path. name_and_extension ( ) {
1944
- Some ( ( name, _) ) => {
1945
- if name. starts_with ( crate_name. as_str ( ) ) {
1946
- crate_path = Some ( path) ;
1947
- break ;
1948
- }
1954
+ if let Some ( ( name, _) ) = path. name_and_extension ( ) {
1955
+ if name. starts_with ( crate_name. as_str ( ) ) {
1956
+ return Some ( path) ;
1949
1957
}
1950
- None => break ,
1958
+ } else {
1959
+ break ;
1951
1960
}
1952
1961
root_path = path;
1953
1962
}
1954
- crate_path
1963
+ None
1955
1964
} )
1956
1965
}
0 commit comments