Skip to content

Commit 403f550

Browse files
authored
Merge pull request #1372 from ahoppen/clangd-may-not-return-up-to-date-diags
Relax `testMainFileChangesIfIncludeIsAdded` to allow `clangd` to return diagnostics from old build settings
2 parents 37480a6 + 094eb0c commit 403f550

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Tests/SourceKitLSPTests/MainFilesProviderTests.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,19 @@ final class MainFilesProviderTests: XCTestCase {
214214

215215
// 'MyFancyLibrary.c' now also includes 'shared.h'. Since it lexicographically preceeds MyLibrary, we should use its
216216
// build settings.
217-
let postEditDiags = try await project.testClient.nextDiagnosticsNotification()
218-
XCTAssertEqual(postEditDiags.diagnostics.count, 1)
219-
let postEditDiag = try XCTUnwrap(postEditDiags.diagnostics.first)
220-
XCTAssertEqual(postEditDiag.message, "Unused variable 'fromMyFancyLibrary'")
217+
// `clangd` may return diagnostics from the old build settings sometimes (I believe when it's still building the
218+
// preamble for shared.h when the new build settings come in). Check that it eventually returns the correct
219+
// diagnostics.
220+
var receivedCorrectDiagnostic = false
221+
for _ in 0..<Int(defaultTimeout) {
222+
let refreshedDiags = try await project.testClient.nextDiagnosticsNotification(timeout: 1)
223+
if let diagnostic = refreshedDiags.diagnostics.only,
224+
diagnostic.message == "Unused variable 'fromMyFancyLibrary'"
225+
{
226+
receivedCorrectDiagnostic = true
227+
break
228+
}
229+
}
230+
XCTAssert(receivedCorrectDiagnostic)
221231
}
222232
}

0 commit comments

Comments
 (0)