@@ -11,6 +11,7 @@ import {
11
11
debounce ,
12
12
} from "./common" ;
13
13
import { WorkspaceChannel } from "./workspaceChannel" ;
14
+ import SorbetClient from "./sorbet" ;
14
15
15
16
export class Workspace implements WorkspaceInterface {
16
17
public lspClient ?: Client ;
@@ -22,6 +23,7 @@ export class Workspace implements WorkspaceInterface {
22
23
private readonly isMainWorkspace : boolean ;
23
24
private readonly telemetry : vscode . TelemetryLogger ;
24
25
private needsRestart = false ;
26
+ private sorbetClient ?: SorbetClient ;
25
27
#rebaseInProgress = false ;
26
28
#error = false ;
27
29
@@ -96,6 +98,10 @@ export class Workspace implements WorkspaceInterface {
96
98
await this . lspClient . stop ( ) ;
97
99
await this . lspClient . dispose ( ) ;
98
100
}
101
+ if ( this . sorbetClient ) {
102
+ await this . sorbetClient . stop ( ) ;
103
+ await this . sorbetClient . dispose ( ) ;
104
+ }
99
105
100
106
this . lspClient = new Client (
101
107
this . context ,
@@ -106,11 +112,17 @@ export class Workspace implements WorkspaceInterface {
106
112
this . outputChannel ,
107
113
this . isMainWorkspace ,
108
114
) ;
115
+ this . sorbetClient = new SorbetClient (
116
+ this . ruby ,
117
+ this . workspaceFolder ,
118
+ this . outputChannel ,
119
+ ) ;
109
120
110
121
try {
111
122
STATUS_EMITTER . fire ( this ) ;
112
123
await this . lspClient . start ( ) ;
113
124
await this . lspClient . afterStart ( ) ;
125
+ await this . sorbetClient . start ( ) ;
114
126
STATUS_EMITTER . fire ( this ) ;
115
127
116
128
// If something triggered a restart while we were still booting, then now we need to perform the restart since the
@@ -127,6 +139,7 @@ export class Workspace implements WorkspaceInterface {
127
139
128
140
async stop ( ) {
129
141
await this . lspClient ?. stop ( ) ;
142
+ await this . sorbetClient ?. stop ( ) ;
130
143
}
131
144
132
145
async restart ( ) {
@@ -138,39 +151,50 @@ export class Workspace implements WorkspaceInterface {
138
151
this . error = false ;
139
152
140
153
// If there's no client, then we can just start a new one
141
- if ( ! this . lspClient ) {
142
- return this . start ( ) ;
143
- }
144
-
145
- switch ( this . lspClient . state ) {
146
- // If the server is still starting, then it may not be ready to handle a shutdown request yet. Trying to send
147
- // one could lead to a hanging process. Instead we set a flag and only restart once the server finished booting
148
- // in `start`
149
- case State . Starting :
150
- this . needsRestart = true ;
151
- break ;
152
- // If the server is running, we want to stop it, dispose of the client and start a new one
153
- case State . Running :
154
- await this . stop ( ) ;
155
- await this . lspClient . dispose ( ) ;
156
- this . lspClient = undefined ;
157
- await this . start ( ) ;
158
- break ;
159
- // If the server is already stopped, then we need to dispose it and start a new one
160
- case State . Stopped :
161
- await this . lspClient . dispose ( ) ;
162
- this . lspClient = undefined ;
163
- await this . start ( ) ;
164
- break ;
154
+ if ( this . lspClient && this . sorbetClient ) {
155
+ try {
156
+ await this . sorbetClient . stop ( ) ;
157
+ await this . sorbetClient . dispose ( ) ;
158
+ } catch ( error : any ) {
159
+ this . outputChannel . error (
160
+ `Error restarting the Sorbet server: ${ error . message } ` ,
161
+ ) ;
162
+ }
163
+ this . sorbetClient = undefined ;
164
+
165
+ switch ( this . lspClient . state ) {
166
+ // If the server is still starting, then it may not be ready to handle a shutdown request yet. Trying to send
167
+ // one could lead to a hanging process. Instead we set a flag and only restart once the server finished
168
+ // booting in `start`
169
+ case State . Starting :
170
+ this . needsRestart = true ;
171
+ break ;
172
+ // If the server is running, we want to stop it, dispose of the client and start a new one
173
+ case State . Running :
174
+ await this . stop ( ) ;
175
+ await this . lspClient . dispose ( ) ;
176
+ this . lspClient = undefined ;
177
+ await this . start ( ) ;
178
+ break ;
179
+ // If the server is already stopped, then we need to dispose it and start a new one
180
+ case State . Stopped :
181
+ await this . lspClient . dispose ( ) ;
182
+ this . lspClient = undefined ;
183
+ await this . start ( ) ;
184
+ break ;
185
+ }
165
186
}
166
187
} catch ( error : any ) {
167
188
this . error = true ;
168
189
this . outputChannel . error ( `Error restarting the server: ${ error . message } ` ) ;
169
190
}
191
+
192
+ return this . start ( ) ;
170
193
}
171
194
172
195
async dispose ( ) {
173
196
await this . lspClient ?. dispose ( ) ;
197
+ await this . sorbetClient ?. dispose ( ) ;
174
198
}
175
199
176
200
// Install or update the `ruby-lsp` gem globally with `gem install ruby-lsp` or `gem update ruby-lsp`. We only try to
0 commit comments