diff --git a/clang-tools-extra/clangd/Config.h b/clang-tools-extra/clangd/Config.h --- a/clang-tools-extra/clangd/Config.h +++ b/clang-tools-extra/clangd/Config.h @@ -106,7 +106,7 @@ /// Enable emitting diagnostics using stale preambles. bool AllowStalePreamble = false; - IncludesPolicy UnusedIncludes = IncludesPolicy::None; + IncludesPolicy UnusedIncludes = IncludesPolicy::Strict; IncludesPolicy MissingIncludes = IncludesPolicy::None; /// IncludeCleaner will not diagnose usages of these headers matched by diff --git a/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp b/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp --- a/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp +++ b/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp @@ -246,10 +246,9 @@ } TEST_F(ConfigCompileTests, DiagnosticsIncludeCleaner) { - // Defaults to None. EXPECT_TRUE(compileAndApply()); EXPECT_EQ(Conf.Diagnostics.UnusedIncludes, - Config::IncludesPolicy::None); + Config::IncludesPolicy::Strict); Frag = {}; Frag.Diagnostics.UnusedIncludes.emplace("None"); diff --git a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp --- a/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp +++ b/clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp @@ -171,11 +171,6 @@ } TEST(IncludeCleaner, GenerateMissingHeaderDiags) { - Config Cfg; - Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict; - Cfg.Diagnostics.Includes.IgnoreHeader = { - [](llvm::StringRef Header) { return Header.ends_with("buzz.h"); }}; - WithContextValue Ctx(Config::Key, std::move(Cfg)); Annotations MainFile(R"cpp( #include "a.h" #include "all.h" @@ -247,6 +242,12 @@ TU.Code = MainFile.code(); ParsedAST AST = TU.build(); + Config Cfg; + Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::None; + Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict; + Cfg.Diagnostics.Includes.IgnoreHeader = { + [](llvm::StringRef Header) { return Header.ends_with("buzz.h"); }}; + WithContextValue Ctx(Config::Key, std::move(Cfg)); std::vector Diags = issueIncludeCleanerDiagnostics(AST, TU.Code); EXPECT_THAT( @@ -308,9 +309,7 @@ // IWYU pragma: private, include "public.h" void foo() {} )cpp"); - Config Cfg; - Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict; - WithContextValue Ctx(Config::Key, std::move(Cfg)); + TU.Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict; ParsedAST AST = TU.build(); EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty())); IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST); @@ -356,11 +355,8 @@ )cpp"; TU.ExtraArgs.emplace_back("-xobjective-c"); - Config Cfg; - - Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict; - Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict; - WithContextValue Ctx(Config::Key, std::move(Cfg)); + TU.Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict; + TU.Cfg.Diagnostics.MissingIncludes = Config::IncludesPolicy::Strict; ParsedAST AST = TU.build(); EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty())); } @@ -375,9 +371,7 @@ void foo() {} )cpp"); TU.Filename = "public.h"; - Config Cfg; - Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict; - WithContextValue Ctx(Config::Key, std::move(Cfg)); + TU.Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict; ParsedAST AST = TU.build(); EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty())); IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);