|
1 | 1 | package fourslash
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "context" |
4 | 5 | "fmt"
|
5 | 6 | "io"
|
6 | 7 | "maps"
|
@@ -140,6 +141,8 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
|
140 | 141 | // Just skip this for now.
|
141 | 142 | t.Skip("bundled files are not embedded")
|
142 | 143 | }
|
| 144 | + ctx := t.Context() |
| 145 | + |
143 | 146 | fileName := getFileNameFromTest(t)
|
144 | 147 | testfs := make(map[string]string)
|
145 | 148 | scriptInfos := make(map[string]*scriptInfo)
|
@@ -171,14 +174,14 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
|
171 | 174 | ParsedFileCache: &parsedFileCache{},
|
172 | 175 | })
|
173 | 176 |
|
| 177 | + lspCtx, lspCancel := context.WithCancel(ctx) |
| 178 | + lspErrChan := make(chan error, 1) |
| 179 | + |
174 | 180 | go func() {
|
175 | 181 | defer func() {
|
176 | 182 | outputWriter.Close()
|
177 | 183 | }()
|
178 |
| - err := server.Run(t.Context()) |
179 |
| - if err != nil { |
180 |
| - t.Error("server error:", err) |
181 |
| - } |
| 184 | + lspErrChan <- server.Run(lspCtx) |
182 | 185 | }()
|
183 | 186 |
|
184 | 187 | converters := ls.NewConverters(lsproto.PositionEncodingKindUTF8, func(fileName string) *ls.LineMap {
|
@@ -209,7 +212,17 @@ func NewFourslash(t *testing.T, capabilities *lsproto.ClientCapabilities, conten
|
209 | 212 | f.activeFilename = f.testData.Files[0].fileName
|
210 | 213 |
|
211 | 214 | t.Cleanup(func() {
|
| 215 | + lspCancel() |
212 | 216 | 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 | + } |
213 | 226 | })
|
214 | 227 | return f
|
215 | 228 | }
|
|
0 commit comments