@@ -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) {
@@ -281,6 +310,7 @@ impl GlobalState {
281310 Status :: Loading => lsp_ext:: Status :: Loading ,
282311 Status :: Ready => lsp_ext:: Status :: Ready ,
283312 Status :: Invalid => lsp_ext:: Status :: Invalid ,
313+ Status :: NeedsReload => lsp_ext:: Status :: NeedsReload ,
284314 } ;
285315 self . send_notification :: < lsp_ext:: StatusNotification > ( lsp_status) ;
286316 }
@@ -395,10 +425,16 @@ impl GlobalState {
395425 ) ;
396426 Ok ( ( ) )
397427 } ) ?
398- . on :: < lsp_types:: notification:: DidSaveTextDocument > ( |this, _params | {
428+ . on :: < lsp_types:: notification:: DidSaveTextDocument > ( |this, params | {
399429 if let Some ( flycheck) = & this. flycheck {
400430 flycheck. handle . update ( ) ;
401431 }
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+ }
402438 Ok ( ( ) )
403439 } ) ?
404440 . on :: < lsp_types:: notification:: DidChangeConfiguration > ( |this, _params| {
0 commit comments