@@ -17,8 +17,9 @@ use std::{
17
17
use crossbeam_channel:: { never, select, unbounded, RecvError , Sender } ;
18
18
use lsp_server:: { Connection , ErrorCode , Message , Notification , Request , RequestId , Response } ;
19
19
use lsp_types:: {
20
- ClientCapabilities , NumberOrString , WorkDoneProgress , WorkDoneProgressBegin ,
21
- WorkDoneProgressCreateParams , WorkDoneProgressEnd , WorkDoneProgressReport ,
20
+ ClientCapabilities , NumberOrString , TextDocumentClientCapabilities , WorkDoneProgress ,
21
+ WorkDoneProgressBegin , WorkDoneProgressCreateParams , WorkDoneProgressEnd ,
22
+ WorkDoneProgressReport ,
22
23
} ;
23
24
use ra_cargo_watch:: { url_from_path_with_drive_lowercasing, CheckOptions , CheckTask } ;
24
25
use ra_ide:: { Canceled , FileId , InlayHintsOptions , LibraryData , SourceRootId } ;
@@ -64,6 +65,53 @@ impl fmt::Display for LspError {
64
65
65
66
impl Error for LspError { }
66
67
68
+ fn get_feature_flags ( config : & ServerConfig , connection : & Connection ) -> FeatureFlags {
69
+ let mut ff = FeatureFlags :: default ( ) ;
70
+ for ( flag, & value) in & config. feature_flags {
71
+ if ff. set ( flag. as_str ( ) , value) . is_err ( ) {
72
+ log:: error!( "unknown feature flag: {:?}" , flag) ;
73
+ show_message (
74
+ req:: MessageType :: Error ,
75
+ format ! ( "unknown feature flag: {:?}" , flag) ,
76
+ & connection. sender ,
77
+ ) ;
78
+ }
79
+ }
80
+ log:: info!( "feature_flags: {:#?}" , ff) ;
81
+ ff
82
+ }
83
+
84
+ fn get_options (
85
+ config : & ServerConfig ,
86
+ text_document_caps : Option < & TextDocumentClientCapabilities > ,
87
+ ) -> Options {
88
+ Options {
89
+ publish_decorations : config. publish_decorations ,
90
+ supports_location_link : text_document_caps
91
+ . and_then ( |it| it. definition )
92
+ . and_then ( |it| it. link_support )
93
+ . unwrap_or ( false ) ,
94
+ line_folding_only : text_document_caps
95
+ . and_then ( |it| it. folding_range . as_ref ( ) )
96
+ . and_then ( |it| it. line_folding_only )
97
+ . unwrap_or ( false ) ,
98
+ inlay_hints : InlayHintsOptions {
99
+ type_hints : config. inlay_hints_type ,
100
+ parameter_hints : config. inlay_hints_parameter ,
101
+ chaining_hints : config. inlay_hints_chaining ,
102
+ max_length : config. inlay_hints_max_length ,
103
+ } ,
104
+ cargo_watch : CheckOptions {
105
+ enable : config. cargo_watch_enable ,
106
+ args : config. cargo_watch_args . clone ( ) ,
107
+ command : config. cargo_watch_command . clone ( ) ,
108
+ all_targets : config. cargo_watch_all_targets ,
109
+ } ,
110
+ rustfmt_args : config. rustfmt_args . clone ( ) ,
111
+ vscode_lldb : config. vscode_lldb ,
112
+ }
113
+ }
114
+
67
115
pub fn main_loop (
68
116
ws_roots : Vec < PathBuf > ,
69
117
client_caps : ClientCapabilities ,
@@ -91,23 +139,10 @@ pub fn main_loop(
91
139
SetThreadPriority ( thread, thread_priority_above_normal) ;
92
140
}
93
141
142
+ let text_document_caps = client_caps. text_document . as_ref ( ) ;
94
143
let mut loop_state = LoopState :: default ( ) ;
95
144
let mut world_state = {
96
- let feature_flags = {
97
- let mut ff = FeatureFlags :: default ( ) ;
98
- for ( flag, value) in config. feature_flags {
99
- if ff. set ( flag. as_str ( ) , value) . is_err ( ) {
100
- log:: error!( "unknown feature flag: {:?}" , flag) ;
101
- show_message (
102
- req:: MessageType :: Error ,
103
- format ! ( "unknown feature flag: {:?}" , flag) ,
104
- & connection. sender ,
105
- ) ;
106
- }
107
- }
108
- ff
109
- } ;
110
- log:: info!( "feature_flags: {:#?}" , feature_flags) ;
145
+ let feature_flags = get_feature_flags ( & config, & connection) ;
111
146
112
147
// FIXME: support dynamic workspace loading.
113
148
let workspaces = {
@@ -169,42 +204,13 @@ pub fn main_loop(
169
204
connection. sender . send ( request. into ( ) ) . unwrap ( ) ;
170
205
}
171
206
172
- let options = {
173
- let text_document_caps = client_caps. text_document . as_ref ( ) ;
174
- Options {
175
- publish_decorations : config. publish_decorations ,
176
- supports_location_link : text_document_caps
177
- . and_then ( |it| it. definition )
178
- . and_then ( |it| it. link_support )
179
- . unwrap_or ( false ) ,
180
- line_folding_only : text_document_caps
181
- . and_then ( |it| it. folding_range . as_ref ( ) )
182
- . and_then ( |it| it. line_folding_only )
183
- . unwrap_or ( false ) ,
184
- inlay_hints : InlayHintsOptions {
185
- type_hints : config. inlay_hints_type ,
186
- parameter_hints : config. inlay_hints_parameter ,
187
- chaining_hints : config. inlay_hints_chaining ,
188
- max_length : config. inlay_hints_max_length ,
189
- } ,
190
- cargo_watch : CheckOptions {
191
- enable : config. cargo_watch_enable ,
192
- args : config. cargo_watch_args ,
193
- command : config. cargo_watch_command ,
194
- all_targets : config. cargo_watch_all_targets ,
195
- } ,
196
- rustfmt_args : config. rustfmt_args ,
197
- vscode_lldb : config. vscode_lldb ,
198
- }
199
- } ;
200
-
201
207
WorldState :: new (
202
208
ws_roots,
203
209
workspaces,
204
210
config. lru_capacity ,
205
211
& globs,
206
212
Watch ( !config. use_client_watching ) ,
207
- options ,
213
+ get_options ( & config , text_document_caps ) ,
208
214
feature_flags,
209
215
)
210
216
} ;
@@ -243,17 +249,16 @@ pub fn main_loop(
243
249
break ;
244
250
} ;
245
251
}
246
- if let Some ( new_server_config ) = loop_turn (
252
+ loop_turn (
247
253
& pool,
248
254
& task_sender,
249
255
& libdata_sender,
250
256
& connection,
257
+ text_document_caps,
251
258
& mut world_state,
252
259
& mut loop_state,
253
260
event,
254
- ) ? {
255
- dbg ! ( new_server_config) ;
256
- }
261
+ ) ?;
257
262
}
258
263
}
259
264
world_state. analysis_host . request_cancellation ( ) ;
@@ -360,10 +365,11 @@ fn loop_turn(
360
365
task_sender : & Sender < Task > ,
361
366
libdata_sender : & Sender < LibraryData > ,
362
367
connection : & Connection ,
368
+ text_document_caps : Option < & TextDocumentClientCapabilities > ,
363
369
world_state : & mut WorldState ,
364
370
loop_state : & mut LoopState ,
365
371
event : Event ,
366
- ) -> Result < Option < ServerConfig > > {
372
+ ) -> Result < ( ) > {
367
373
let loop_start = Instant :: now ( ) ;
368
374
369
375
// NOTE: don't count blocking select! call as a loop-turn time
@@ -374,8 +380,6 @@ fn loop_turn(
374
380
log:: info!( "queued count = {}" , queue_count) ;
375
381
}
376
382
377
- let mut new_server_config = None ;
378
-
379
383
match event {
380
384
Event :: Task ( task) => {
381
385
on_task ( task, & connection. sender , & mut loop_state. pending_requests , world_state) ;
@@ -411,13 +415,18 @@ fn loop_turn(
411
415
}
412
416
if Some ( & resp. id ) == loop_state. configuration_request_id . as_ref ( ) {
413
417
loop_state. configuration_request_id . take ( ) ;
418
+ // TODO kb unwrap-unwrap-unwrap
414
419
let new_config =
415
420
serde_json:: from_value :: < Vec < ServerConfig > > ( resp. result . unwrap ( ) )
416
421
. unwrap ( )
417
422
. first ( )
418
423
. unwrap ( )
419
424
. to_owned ( ) ;
420
- new_server_config = Some ( new_config) ;
425
+ world_state. update_configuration (
426
+ new_config. lru_capacity ,
427
+ get_options ( & new_config, text_document_caps) ,
428
+ get_feature_flags ( & new_config, connection) ,
429
+ ) ;
421
430
}
422
431
}
423
432
} ,
@@ -488,7 +497,7 @@ fn loop_turn(
488
497
}
489
498
}
490
499
491
- Ok ( new_server_config )
500
+ Ok ( ( ) )
492
501
}
493
502
494
503
fn on_task (
0 commit comments