@@ -158,19 +158,32 @@ fn run_server() -> Result<()> {
158
158
let initialize_params =
159
159
from_json :: < lsp_types:: InitializeParams > ( "InitializeParams" , initialize_params) ?;
160
160
161
- let server_capabilities = rust_analyzer:: server_capabilities ( & initialize_params. capabilities ) ;
161
+ let root_path = match initialize_params
162
+ . root_uri
163
+ . and_then ( |it| it. to_file_path ( ) . ok ( ) )
164
+ . and_then ( |it| AbsPathBuf :: try_from ( it) . ok ( ) )
165
+ {
166
+ Some ( it) => it,
167
+ None => {
168
+ let cwd = env:: current_dir ( ) ?;
169
+ AbsPathBuf :: assert ( cwd)
170
+ }
171
+ } ;
172
+
173
+ let mut config = Config :: new ( root_path, initialize_params. capabilities ) ;
174
+ if let Some ( json) = initialize_params. initialization_options {
175
+ config. update ( json) ;
176
+ }
177
+
178
+ let server_capabilities = rust_analyzer:: server_capabilities ( & config) ;
162
179
163
180
let initialize_result = lsp_types:: InitializeResult {
164
181
capabilities : server_capabilities,
165
182
server_info : Some ( lsp_types:: ServerInfo {
166
183
name : String :: from ( "rust-analyzer" ) ,
167
184
version : Some ( String :: from ( env ! ( "REV" ) ) ) ,
168
185
} ) ,
169
- offset_encoding : if supports_utf8 ( & initialize_params. capabilities ) {
170
- Some ( "utf-8" . to_string ( ) )
171
- } else {
172
- None
173
- } ,
186
+ offset_encoding : if supports_utf8 ( & config. caps ) { Some ( "utf-8" . to_string ( ) ) } else { None } ,
174
187
} ;
175
188
176
189
let initialize_result = serde_json:: to_value ( initialize_result) . unwrap ( ) ;
@@ -181,47 +194,26 @@ fn run_server() -> Result<()> {
181
194
log:: info!( "Client '{}' {}" , client_info. name, client_info. version. unwrap_or_default( ) ) ;
182
195
}
183
196
184
- let config = {
185
- let root_path = match initialize_params
186
- . root_uri
187
- . and_then ( |it| it. to_file_path ( ) . ok ( ) )
188
- . and_then ( |it| AbsPathBuf :: try_from ( it) . ok ( ) )
189
- {
190
- Some ( it) => it,
191
- None => {
192
- let cwd = env:: current_dir ( ) ?;
193
- AbsPathBuf :: assert ( cwd)
194
- }
195
- } ;
196
-
197
- let mut config = Config :: new ( root_path, initialize_params. capabilities ) ;
198
- if let Some ( json) = initialize_params. initialization_options {
199
- config. update ( json) ;
200
- }
201
-
202
- if config. linked_projects ( ) . is_empty ( ) && config. detached_files ( ) . is_empty ( ) {
203
- let workspace_roots = initialize_params
204
- . workspace_folders
205
- . map ( |workspaces| {
206
- workspaces
207
- . into_iter ( )
208
- . filter_map ( |it| it. uri . to_file_path ( ) . ok ( ) )
209
- . filter_map ( |it| AbsPathBuf :: try_from ( it) . ok ( ) )
210
- . collect :: < Vec < _ > > ( )
211
- } )
212
- . filter ( |workspaces| !workspaces. is_empty ( ) )
213
- . unwrap_or_else ( || vec ! [ config. root_path. clone( ) ] ) ;
214
-
215
- let discovered = ProjectManifest :: discover_all ( & workspace_roots) ;
216
- log:: info!( "discovered projects: {:?}" , discovered) ;
217
- if discovered. is_empty ( ) {
218
- log:: error!( "failed to find any projects in {:?}" , workspace_roots) ;
219
- }
220
- config. discovered_projects = Some ( discovered) ;
197
+ if config. linked_projects ( ) . is_empty ( ) && config. detached_files ( ) . is_empty ( ) {
198
+ let workspace_roots = initialize_params
199
+ . workspace_folders
200
+ . map ( |workspaces| {
201
+ workspaces
202
+ . into_iter ( )
203
+ . filter_map ( |it| it. uri . to_file_path ( ) . ok ( ) )
204
+ . filter_map ( |it| AbsPathBuf :: try_from ( it) . ok ( ) )
205
+ . collect :: < Vec < _ > > ( )
206
+ } )
207
+ . filter ( |workspaces| !workspaces. is_empty ( ) )
208
+ . unwrap_or_else ( || vec ! [ config. root_path. clone( ) ] ) ;
209
+
210
+ let discovered = ProjectManifest :: discover_all ( & workspace_roots) ;
211
+ log:: info!( "discovered projects: {:?}" , discovered) ;
212
+ if discovered. is_empty ( ) {
213
+ log:: error!( "failed to find any projects in {:?}" , workspace_roots) ;
221
214
}
222
-
223
- config
224
- } ;
215
+ config. discovered_projects = Some ( discovered) ;
216
+ }
225
217
226
218
rust_analyzer:: main_loop ( config, connection) ?;
227
219
0 commit comments