@@ -167,8 +167,6 @@ impl LanguageServer for Backend {
167167 if worker. needs_init_linter ( ) . await {
168168 needed_configurations. insert ( worker. get_root_uri ( ) . clone ( ) , worker) ;
169169 }
170- // ToDo: check for configuration
171- worker. init_formatter ( ) . await ;
172170 }
173171
174172 if !needed_configurations. is_empty ( ) {
@@ -178,23 +176,21 @@ impl LanguageServer for Backend {
178176 // every worker should be initialized already in `initialize` request
179177 vec ! [ Some ( Options :: default ( ) ) ; needed_configurations. len( ) ]
180178 } ;
179+ let default_options = Options :: default ( ) ;
181180
182181 for ( index, worker) in needed_configurations. values ( ) . enumerate ( ) {
183- worker
184- . init_linter (
185- configurations
186- . get ( index)
187- . unwrap_or ( & None )
188- . as_ref ( )
189- . unwrap_or ( & Options :: default ( ) ) ,
190- )
191- . await ;
182+ let configuration =
183+ configurations. get ( index) . unwrap_or ( & None ) . as_ref ( ) . unwrap_or ( & default_options) ;
184+
185+ worker. init_linter ( configuration) . await ;
186+ worker. init_formatter ( & configuration. format ) . await ;
192187 }
193188 }
194189
190+ let mut registrations = vec ! [ ] ;
191+
195192 // init all file watchers
196193 if capabilities. dynamic_watchers {
197- let mut registrations = vec ! [ ] ;
198194 for worker in workers {
199195 registrations. push ( Registration {
200196 id : format ! ( "watcher-{}" , worker. get_root_uri( ) . as_str( ) ) ,
@@ -204,10 +200,21 @@ impl LanguageServer for Backend {
204200 } ) ) ,
205201 } ) ;
206202 }
203+ }
207204
208- if let Err ( err) = self . client . register_capability ( registrations) . await {
209- warn ! ( "sending registerCapability.didChangeWatchedFiles failed: {err}" ) ;
210- }
205+ if capabilities. dynamic_formatting {
206+ registrations. push ( Registration {
207+ id : "dynamic-formatting" . to_string ( ) ,
208+ method : "textDocument/formatting" . to_string ( ) ,
209+ register_options : None ,
210+ } ) ;
211+ }
212+
213+ if registrations. is_empty ( ) {
214+ return ;
215+ }
216+ if let Err ( err) = self . client . register_capability ( registrations) . await {
217+ warn ! ( "sending registerCapability.didChangeWatchedFiles failed: {err}" ) ;
211218 }
212219 }
213220
@@ -410,11 +417,16 @@ impl LanguageServer for Backend {
410417 )
411418 . await ;
412419
420+ let default_options = Options :: default ( ) ;
413421 for ( index, folder) in params. event . added . iter ( ) . enumerate ( ) {
414422 let worker = WorkspaceWorker :: new ( folder. uri . clone ( ) ) ;
415423 // get the configuration from the response and init the linter
416424 let options = configurations. get ( index) . unwrap_or ( & None ) ;
417- worker. init_linter ( options. as_ref ( ) . unwrap_or ( & Options :: default ( ) ) ) . await ;
425+ let options = options. as_ref ( ) . unwrap_or ( & default_options) ;
426+
427+ worker. init_linter ( options) . await ;
428+ worker. init_formatter ( & options. format ) . await ;
429+
418430 added_registrations. push ( Registration {
419431 id : format ! ( "watcher-{}" , worker. get_root_uri( ) . as_str( ) ) ,
420432 method : "workspace/didChangeWatchedFiles" . to_string ( ) ,
@@ -603,7 +615,7 @@ impl LanguageServer for Backend {
603615 let Some ( worker) = workers. iter ( ) . find ( |worker| worker. is_responsible_for_uri ( uri) ) else {
604616 return Ok ( None ) ;
605617 } ;
606- Ok ( worker. format_file ( uri) . await )
618+ Ok ( worker. format_file ( uri, self . file_system . read ( ) . await . get ( uri ) ) . await )
607619 }
608620}
609621
0 commit comments