Skip to content

Commit 8762147

Browse files
committed
Coordinate LSP server exit error
1 parent e624abe commit 8762147

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

internal/fourslash/fourslash.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fourslash
22

33
import (
4+
"context"
45
"fmt"
56
"io"
67
"maps"
@@ -140,6 +141,8 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
140141
// Just skip this for now.
141142
t.Skip("bundled files are not embedded")
142143
}
144+
ctx := t.Context()
145+
143146
fileName := getFileNameFromTest(t)
144147
testfs := make(map[string]string)
145148
scriptInfos := make(map[string]*scriptInfo)
@@ -171,14 +174,14 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
171174
ParsedFileCache: &parsedFileCache{},
172175
})
173176

177+
lspCtx, lspCancel := context.WithCancel(ctx)
178+
lspErrChan := make(chan error, 1)
179+
174180
go func() {
175181
defer func() {
176182
outputWriter.Close()
177183
}()
178-
err := server.Run(t.Context())
179-
if err != nil {
180-
t.Error("server error:", err)
181-
}
184+
lspErrChan <- server.Run(lspCtx)
182185
}()
183186

184187
converters := ls.NewConverters(lsproto.PositionEncodingKindUTF8, func(fileName string) *ls.LineMap {
@@ -209,7 +212,17 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
209212
f.activeFilename = f.testData.Files[0].fileName
210213

211214
t.Cleanup(func() {
215+
lspCancel()
212216
inputWriter.Close()
217+
218+
select {
219+
case <-ctx.Done():
220+
// do nothing
221+
case err := <-lspErrChan:
222+
if err != nil && lspCtx.Err() == nil {
223+
t.Errorf("LSP server exited with error: %v", err)
224+
}
225+
}
213226
})
214227
return f
215228
}

0 commit comments

Comments
 (0)