Skip to content

Commit

Permalink
[clangd] Respect WantDiags when emitting diags from possibly stale pr…
Browse files Browse the repository at this point in the history
…eambles

Differential Revision: https://reviews.llvm.org/D146116
  • Loading branch information
kadircet committed Mar 15, 2023
1 parent 6db766a commit 9e8bac7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang-tools-extra/clangd/TUScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
7 changes: 7 additions & 0 deletions clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e8bac7

Please sign in to comment.