@@ -10,7 +10,8 @@ import {
10
10
STATUS_EMITTER ,
11
11
debounce ,
12
12
} from "./common" ;
13
- import { WorkspaceChannel } from "./workspaceChannel" ;
13
+ import { SorbetWorkspaceChannel , 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
+ new SorbetWorkspaceChannel ( this . workspaceFolder . name , LOG_CHANNEL ) ,
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
@@ -126,7 +138,19 @@ export class Workspace implements WorkspaceInterface {
126
138
}
127
139
128
140
async stop ( ) {
129
- await this . lspClient ?. stop ( ) ;
141
+ try {
142
+ await this . lspClient ?. stop ( ) ;
143
+ } catch ( error : any ) {
144
+ this . outputChannel . error ( `Error stopping the Ruby LSP: ${ error . message } ` ) ;
145
+ }
146
+
147
+ try {
148
+ await this . sorbetClient ?. stop ( ) ;
149
+ } catch ( error : any ) {
150
+ this . outputChannel . error (
151
+ `Error stopping the Sorbet server: ${ error . message } ` ,
152
+ ) ;
153
+ }
130
154
}
131
155
132
156
async restart ( ) {
@@ -138,28 +162,30 @@ export class Workspace implements WorkspaceInterface {
138
162
this . error = false ;
139
163
140
164
// If there's no client, then we can just start a new one
141
- if ( ! this . lspClient ) {
165
+ if ( ! this . lspClient && ! this . sorbetClient ) {
142
166
return this . start ( ) ;
143
167
}
144
168
145
- switch ( this . lspClient . state ) {
169
+ switch ( this . lspClient ! . state ) {
146
170
// 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`
171
+ // one could lead to a hanging process. Instead we set a flag and only restart once the server finished
172
+ // booting in `start`
149
173
case State . Starting :
150
174
this . needsRestart = true ;
151
175
break ;
152
176
// If the server is running, we want to stop it, dispose of the client and start a new one
153
177
case State . Running :
154
178
await this . stop ( ) ;
155
- await this . lspClient . dispose ( ) ;
179
+ await this . dispose ( ) ;
156
180
this . lspClient = undefined ;
181
+ this . sorbetClient = undefined ;
157
182
await this . start ( ) ;
158
183
break ;
159
184
// If the server is already stopped, then we need to dispose it and start a new one
160
185
case State . Stopped :
161
- await this . lspClient . dispose ( ) ;
186
+ await this . dispose ( ) ;
162
187
this . lspClient = undefined ;
188
+ this . sorbetClient = undefined ;
163
189
await this . start ( ) ;
164
190
break ;
165
191
}
@@ -171,6 +197,7 @@ export class Workspace implements WorkspaceInterface {
171
197
172
198
async dispose ( ) {
173
199
await this . lspClient ?. dispose ( ) ;
200
+ await this . sorbetClient ?. dispose ( ) ;
174
201
}
175
202
176
203
// 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