From 9e8bac7480640677e04f4b9f98c41cb94f8180e2 Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya Date: Wed, 15 Mar 2023 09:12:58 +0100 Subject: [PATCH] [clangd] Respect WantDiags when emitting diags from possibly stale preambles Differential Revision: https://reviews.llvm.org/D146116 --- clang-tools-extra/clangd/TUScheduler.cpp | 3 ++- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp index a4f6a93..9b366cd 100644 --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -948,7 +948,8 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics WantDiags, // rebuild. Newly built preamble cannot emit diagnostics before this call // finishes (ast callbacks are called from astpeer thread), hence we // gurantee eventual consistency. - if (LatestPreamble && Config::current().Diagnostics.AllowStalePreamble) + if (LatestPreamble && WantDiags != WantDiagnostics::No && + Config::current().Diagnostics.AllowStalePreamble) generateDiagnostics(std::move(Invocation), std::move(Inputs), std::move(CompilerInvocationDiags)); diff --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp index ead85a4..0538947 100644 --- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp +++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp @@ -1309,6 +1309,13 @@ TEST_F(TUSchedulerTests, PublishWithStalePreamble) { // Make sure that we have eventual consistency. EXPECT_THAT(Collector.diagVersions().back(), Pair(PI.Version, PI.Version)); + + // Check that WantDiagnostics::No doesn't emit any diags. + PI.Version = "4"; + PI.Contents = "#define FOO\n" + PI.Version; + S.update(File, PI, WantDiagnostics::No); + S.blockUntilIdle(timeoutSeconds(5)); + EXPECT_THAT(Collector.diagVersions().back(), Pair("3", "3")); } // If a header file is missing from the CDB (or inferred using heuristics), and -- 2.7.4