@@ -111,6 +111,35 @@ impl GlobalState {
111111 }
112112
113113 fn run ( mut self , inbox : Receiver < lsp_server:: Message > ) -> Result < ( ) > {
114+ let registration_options = lsp_types:: TextDocumentRegistrationOptions {
115+ document_selector : Some ( vec ! [
116+ lsp_types:: DocumentFilter {
117+ language: None ,
118+ scheme: None ,
119+ pattern: Some ( "**/*.rs" . into( ) ) ,
120+ } ,
121+ lsp_types:: DocumentFilter {
122+ language: None ,
123+ scheme: None ,
124+ pattern: Some ( "**/Cargo.toml" . into( ) ) ,
125+ } ,
126+ lsp_types:: DocumentFilter {
127+ language: None ,
128+ scheme: None ,
129+ pattern: Some ( "**/Cargo.lock" . into( ) ) ,
130+ } ,
131+ ] ) ,
132+ } ;
133+ let registration = lsp_types:: Registration {
134+ id : "textDocument/didSave" . to_string ( ) ,
135+ method : "textDocument/didSave" . to_string ( ) ,
136+ register_options : Some ( serde_json:: to_value ( registration_options) . unwrap ( ) ) ,
137+ } ;
138+ self . send_request :: < lsp_types:: request:: RegisterCapability > (
139+ lsp_types:: RegistrationParams { registrations : vec ! [ registration] } ,
140+ |_, _| ( ) ,
141+ ) ;
142+
114143 self . reload ( ) ;
115144
116145 while let Some ( event) = self . next_event ( & inbox) {
@@ -169,16 +198,16 @@ impl GlobalState {
169198 }
170199 vfs:: loader:: Message :: Progress { n_total, n_done } => {
171200 if n_total == 0 {
172- self . status = Status :: Ready ;
201+ self . transition ( Status :: Invalid ) ;
173202 } else {
174203 let state = if n_done == 0 {
175- self . status = Status :: Loading ;
204+ self . transition ( Status :: Loading ) ;
176205 Progress :: Begin
177206 } else if n_done < n_total {
178207 Progress :: Report
179208 } else {
180209 assert_eq ! ( n_done, n_total) ;
181- self . status = Status :: Ready ;
210+ self . transition ( Status :: Ready ) ;
182211 Progress :: End
183212 } ;
184213 self . report_progress (
@@ -274,6 +303,19 @@ impl GlobalState {
274303 Ok ( ( ) )
275304 }
276305
306+ fn transition ( & mut self , new_status : Status ) {
307+ self . status = Status :: Ready ;
308+ if self . config . client_caps . status_notification {
309+ let lsp_status = match new_status {
310+ Status :: Loading => lsp_ext:: Status :: Loading ,
311+ Status :: Ready => lsp_ext:: Status :: Ready ,
312+ Status :: Invalid => lsp_ext:: Status :: Invalid ,
313+ Status :: NeedsReload => lsp_ext:: Status :: NeedsReload ,
314+ } ;
315+ self . send_notification :: < lsp_ext:: StatusNotification > ( lsp_status) ;
316+ }
317+ }
318+
277319 fn on_request ( & mut self , request_received : Instant , req : Request ) -> Result < ( ) > {
278320 self . register_request ( & req, request_received) ;
279321
@@ -383,10 +425,16 @@ impl GlobalState {
383425 ) ;
384426 Ok ( ( ) )
385427 } ) ?
386- . on :: < lsp_types:: notification:: DidSaveTextDocument > ( |this, _params | {
428+ . on :: < lsp_types:: notification:: DidSaveTextDocument > ( |this, params | {
387429 if let Some ( flycheck) = & this. flycheck {
388430 flycheck. handle . update ( ) ;
389431 }
432+ let uri = params. text_document . uri . as_str ( ) ;
433+ if uri. ends_with ( "Cargo.toml" ) || uri. ends_with ( "Cargo.lock" ) {
434+ if matches ! ( this. status, Status :: Ready | Status :: Invalid ) {
435+ this. transition ( Status :: NeedsReload ) ;
436+ }
437+ }
390438 Ok ( ( ) )
391439 } ) ?
392440 . on :: < lsp_types:: notification:: DidChangeConfiguration > ( |this, _params| {
0 commit comments