@@ -135,15 +135,11 @@ final class CrashRecoveryTests: XCTestCase {
135
135
}
136
136
}
137
137
138
- /// Crashes clangd and waits for it to restart
139
- /// - Parameters:
140
- /// - ws: The workspace for which the clangd server shall be crashed
141
- /// - document: The URI of a C/C++/... document in the workspace
142
- private func crashClangd( for ws: SKTibsTestWorkspace , document docUri: DocumentURI ) async throws {
143
- let clangdServer = await ws. testClient. server. _languageService (
138
+ private func crashClangd( for testClient: TestSourceKitLSPClient , document docUri: DocumentURI ) async throws {
139
+ let clangdServer = await testClient. server. _languageService (
144
140
for: docUri,
145
141
. cpp,
146
- in: ws . testClient. server. workspaceForDocument ( uri: docUri) !
142
+ in: testClient. server. workspaceForDocument ( uri: docUri) !
147
143
) !
148
144
149
145
let clangdCrashed = self . expectation ( description: " clangd crashed " )
@@ -169,25 +165,26 @@ final class CrashRecoveryTests: XCTestCase {
169
165
func testClangdCrashRecovery( ) async throws {
170
166
try XCTSkipIf ( longTestsDisabled)
171
167
172
- let ws = try await staticSourceKitTibsWorkspace ( name : " ClangCrashRecovery " ) !
173
- let loc = ws . testLoc ( " loc " )
168
+ let testClient = try await TestSourceKitLSPClient ( )
169
+ let uri = DocumentURI . for ( . cpp )
174
170
175
- try ws . openDocument ( loc . url , language : . cpp )
171
+ let positions = testClient . openDocument ( " 1️⃣ " , uri : uri )
176
172
177
173
// Make a change to the file that's not saved to disk. This way we can check that we re-open the correct in-memory state.
178
174
179
175
let addFuncChange = TextDocumentContentChangeEvent (
180
- range: loc . position ..< loc . position ,
176
+ range: Range ( positions [ " 1️⃣ " ] ) ,
181
177
rangeLength: 0 ,
182
178
text: """
183
179
184
180
void main() {
185
181
}
186
182
"""
187
183
)
188
- ws. testClient. send (
184
+
185
+ testClient. send (
189
186
DidChangeTextDocumentNotification (
190
- textDocument: VersionedTextDocumentIdentifier ( loc . docUri , version: 2 ) ,
187
+ textDocument: VersionedTextDocumentIdentifier ( uri , version: 2 ) ,
191
188
contentChanges: [ addFuncChange]
192
189
)
193
190
)
@@ -196,21 +193,24 @@ final class CrashRecoveryTests: XCTestCase {
196
193
197
194
let expectedHoverRange = Position ( line: 1 , utf16index: 5 ) ..< Position ( line: 1 , utf16index: 9 )
198
195
199
- let hoverRequest = HoverRequest ( textDocument: loc. docIdentifier, position: Position ( line: 1 , utf16index: 6 ) )
200
- let preCrashHoverResponse = try await ws. testClient. send ( hoverRequest)
196
+ let hoverRequest = HoverRequest (
197
+ textDocument: TextDocumentIdentifier ( uri) ,
198
+ position: Position ( line: 1 , utf16index: 6 )
199
+ )
200
+ let preCrashHoverResponse = try await testClient. send ( hoverRequest)
201
201
precondition (
202
202
preCrashHoverResponse? . range == expectedHoverRange,
203
203
" Sanity check failed. The Hover response was not what we expected, even before crashing sourcekitd "
204
204
)
205
205
206
206
// Crash clangd
207
207
208
- try await crashClangd ( for: ws , document: loc . docUri )
208
+ try await crashClangd ( for: testClient , document: uri )
209
209
210
210
// Check that we have re-opened the document with the correct in-memory state
211
211
212
212
await assertNoThrow {
213
- let postCrashHoverResponse = try await ws . testClient. send ( hoverRequest)
213
+ let postCrashHoverResponse = try await testClient. send ( hoverRequest)
214
214
XCTAssertEqual ( postCrashHoverResponse? . range, expectedHoverRange)
215
215
}
216
216
}
@@ -242,7 +242,7 @@ final class CrashRecoveryTests: XCTestCase {
242
242
243
243
// Crash clangd
244
244
245
- try await crashClangd ( for: ws, document: loc. docUri)
245
+ try await crashClangd ( for: ws. testClient , document: loc. docUri)
246
246
247
247
// Check that we have re-opened the document with the correct build settings
248
248
// If we did not recover the correct build settings, document highlight would
@@ -257,22 +257,22 @@ final class CrashRecoveryTests: XCTestCase {
257
257
func testPreventClangdCrashLoop( ) async throws {
258
258
try XCTSkipIf ( longTestsDisabled)
259
259
260
- let ws = try await staticSourceKitTibsWorkspace ( name : " ClangCrashRecovery " ) !
261
- let loc = ws . testLoc ( " loc " )
260
+ let testClient = try await TestSourceKitLSPClient ( )
261
+ let uri = DocumentURI . for ( . cpp )
262
262
263
- try ws . openDocument ( loc . url , language : . cpp )
263
+ let positions = testClient . openDocument ( " 1️⃣ " , uri : uri )
264
264
265
265
// Send a nonsensical request to wait for clangd to start up
266
266
267
- let hoverRequest = HoverRequest ( textDocument: loc . docIdentifier , position: Position ( line : 1 , utf16index : 6 ) )
268
- _ = try await ws . testClient. send ( hoverRequest)
267
+ let hoverRequest = HoverRequest ( textDocument: TextDocumentIdentifier ( uri ) , position: positions [ " 1️⃣ " ] )
268
+ _ = try await testClient. send ( hoverRequest)
269
269
270
270
// Keep track of clangd crashes
271
271
272
- let clangdServer = await ws . testClient. server. _languageService (
273
- for: loc . docUri ,
272
+ let clangdServer = await testClient. server. _languageService (
273
+ for: uri ,
274
274
. cpp,
275
- in: ws . testClient. server. workspaceForDocument ( uri: loc . docUri ) !
275
+ in: testClient. server. workspaceForDocument ( uri: uri ) !
276
276
) !
277
277
278
278
let clangdCrashed = self . expectation ( description: " clangd crashed " )
0 commit comments