@@ -91,19 +91,37 @@ impl Connection {
91
91
self . sender
92
92
. send ( lsp:: Response :: new_ok ( id. clone ( ) , ( ) ) . into ( ) ) ?;
93
93
tracing:: info!( "Shutdown request received. Waiting for an exit notification..." ) ;
94
- match self . receiver . recv_timeout ( std:: time:: Duration :: from_secs ( 30 ) ) ? {
95
- lsp:: Message :: Notification ( lsp:: Notification { method, .. } ) if method == lsp_types:: notification:: Exit :: METHOD => {
96
- tracing:: info!( "Exit notification received. Server shutting down..." ) ;
97
- Ok ( true )
98
- } ,
99
- message => anyhow:: bail!( "Server received unexpected message {message:?} while waiting for exit notification" )
94
+
95
+ loop {
96
+ match & self
97
+ . receiver
98
+ . recv_timeout ( std:: time:: Duration :: from_secs ( 30 ) ) ?
99
+ {
100
+ lsp:: Message :: Notification ( lsp:: Notification { method, .. } )
101
+ if method == lsp_types:: notification:: Exit :: METHOD =>
102
+ {
103
+ tracing:: info!( "Exit notification received. Server shutting down..." ) ;
104
+ return Ok ( true ) ;
105
+ }
106
+ lsp:: Message :: Request ( lsp:: Request { id, .. } ) => {
107
+ self . sender . send ( lsp:: Message :: Response ( lsp:: Response :: new_err (
108
+ id. clone ( ) ,
109
+ lsp:: ErrorCode :: InvalidRequest as i32 ,
110
+ "Server received unexpected request while waiting for exit notification" . to_string ( ) ,
111
+ ) ) ) ?;
112
+ }
113
+ message => {
114
+ anyhow:: bail!(
115
+ "Server received unexpected message {message:?} while waiting for exit notification"
116
+ )
117
+ }
118
+ }
100
119
}
101
120
}
102
121
lsp:: Message :: Notification ( lsp:: Notification { method, .. } )
103
122
if method == lsp_types:: notification:: Exit :: METHOD =>
104
123
{
105
- tracing:: error!( "Server received an exit notification before a shutdown request was sent. Exiting..." ) ;
106
- Ok ( true )
124
+ anyhow:: bail!( "Server received an exit notification before a shutdown request was sent. Exiting..." ) ;
107
125
}
108
126
_ => Ok ( false ) ,
109
127
}
0 commit comments