@@ -17,8 +17,9 @@ use std::{
1717use crossbeam_channel:: { never, select, unbounded, RecvError , Sender } ;
1818use lsp_server:: { Connection , ErrorCode , Message , Notification , Request , RequestId , Response } ;
1919use lsp_types:: {
20- ClientCapabilities , NumberOrString , WorkDoneProgress , WorkDoneProgressBegin ,
21- WorkDoneProgressCreateParams , WorkDoneProgressEnd , WorkDoneProgressReport ,
20+ ClientCapabilities , NumberOrString , TextDocumentClientCapabilities , WorkDoneProgress ,
21+ WorkDoneProgressBegin , WorkDoneProgressCreateParams , WorkDoneProgressEnd ,
22+ WorkDoneProgressReport ,
2223} ;
2324use ra_cargo_watch:: { url_from_path_with_drive_lowercasing, CheckOptions , CheckTask } ;
2425use ra_ide:: { Canceled , FileId , InlayHintsOptions , LibraryData , SourceRootId } ;
@@ -64,6 +65,53 @@ impl fmt::Display for LspError {
6465
6566impl Error for LspError { }
6667
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+
67115pub fn main_loop (
68116 ws_roots : Vec < PathBuf > ,
69117 client_caps : ClientCapabilities ,
@@ -91,23 +139,10 @@ pub fn main_loop(
91139 SetThreadPriority ( thread, thread_priority_above_normal) ;
92140 }
93141
142+ let text_document_caps = client_caps. text_document . as_ref ( ) ;
94143 let mut loop_state = LoopState :: default ( ) ;
95144 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) ;
111146
112147 // FIXME: support dynamic workspace loading.
113148 let workspaces = {
@@ -169,42 +204,13 @@ pub fn main_loop(
169204 connection. sender . send ( request. into ( ) ) . unwrap ( ) ;
170205 }
171206
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-
201207 WorldState :: new (
202208 ws_roots,
203209 workspaces,
204210 config. lru_capacity ,
205211 & globs,
206212 Watch ( !config. use_client_watching ) ,
207- options ,
213+ get_options ( & config , text_document_caps ) ,
208214 feature_flags,
209215 )
210216 } ;
@@ -243,17 +249,16 @@ pub fn main_loop(
243249 break ;
244250 } ;
245251 }
246- if let Some ( new_server_config ) = loop_turn (
252+ loop_turn (
247253 & pool,
248254 & task_sender,
249255 & libdata_sender,
250256 & connection,
257+ text_document_caps,
251258 & mut world_state,
252259 & mut loop_state,
253260 event,
254- ) ? {
255- dbg ! ( new_server_config) ;
256- }
261+ ) ?;
257262 }
258263 }
259264 world_state. analysis_host . request_cancellation ( ) ;
@@ -360,10 +365,11 @@ fn loop_turn(
360365 task_sender : & Sender < Task > ,
361366 libdata_sender : & Sender < LibraryData > ,
362367 connection : & Connection ,
368+ text_document_caps : Option < & TextDocumentClientCapabilities > ,
363369 world_state : & mut WorldState ,
364370 loop_state : & mut LoopState ,
365371 event : Event ,
366- ) -> Result < Option < ServerConfig > > {
372+ ) -> Result < ( ) > {
367373 let loop_start = Instant :: now ( ) ;
368374
369375 // NOTE: don't count blocking select! call as a loop-turn time
@@ -374,8 +380,6 @@ fn loop_turn(
374380 log:: info!( "queued count = {}" , queue_count) ;
375381 }
376382
377- let mut new_server_config = None ;
378-
379383 match event {
380384 Event :: Task ( task) => {
381385 on_task ( task, & connection. sender , & mut loop_state. pending_requests , world_state) ;
@@ -411,13 +415,18 @@ fn loop_turn(
411415 }
412416 if Some ( & resp. id ) == loop_state. configuration_request_id . as_ref ( ) {
413417 loop_state. configuration_request_id . take ( ) ;
418+ // TODO kb unwrap-unwrap-unwrap
414419 let new_config =
415420 serde_json:: from_value :: < Vec < ServerConfig > > ( resp. result . unwrap ( ) )
416421 . unwrap ( )
417422 . first ( )
418423 . unwrap ( )
419424 . 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+ ) ;
421430 }
422431 }
423432 } ,
@@ -488,7 +497,7 @@ fn loop_turn(
488497 }
489498 }
490499
491- Ok ( new_server_config )
500+ Ok ( ( ) )
492501}
493502
494503fn on_task (
0 commit comments