Skip to content

Commit

Permalink
[clangd] Disable IncludeCleaner for ObjC
Browse files Browse the repository at this point in the history
  • Loading branch information
kadircet committed Aug 22, 2022
1 parent b3125ad commit 3c2cb8e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/IncludeCleaner.cpp
Expand Up @@ -476,6 +476,9 @@ std::vector<Diag> issueUnusedIncludesDiagnostics(ParsedAST &AST,
Cfg.Diagnostics.SuppressAll ||
Cfg.Diagnostics.Suppress.contains("unused-includes"))
return {};
// Interaction is only polished for C/CPP.
if (AST.getLangOpts().ObjC)
return {};
trace::Span Tracer("IncludeCleaner::issueUnusedIncludesDiagnostics");
std::vector<Diag> Result;
std::string FileName =
Expand Down
23 changes: 23 additions & 0 deletions clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
Expand Up @@ -7,10 +7,12 @@
//===----------------------------------------------------------------------===//

#include "Annotations.h"
#include "Config.h"
#include "IncludeCleaner.h"
#include "SourceCode.h"
#include "TestFS.h"
#include "TestTU.h"
#include "support/Context.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/Testing/Support/SupportHelpers.h"
#include "gmock/gmock.h"
Expand Down Expand Up @@ -599,6 +601,27 @@ TEST(IncludeCleaner, IWYUPragmaExport) {
EXPECT_THAT(computeUnusedIncludes(AST), IsEmpty());
}

TEST(IncludeCleaner, NoDiagsForObjC) {
TestTU TU;
TU.Code = R"cpp(
#include "foo.h"
void bar() {}
)cpp";
TU.AdditionalFiles["foo.h"] = R"cpp(
#ifndef FOO_H
#define FOO_H
#endif
)cpp";
TU.ExtraArgs.emplace_back("-xobjective-c");

Config Cfg;
Cfg.Diagnostics.UnusedIncludes = Config::Strict;
WithContextValue Ctx(Config::Key, std::move(Cfg));
ParsedAST AST = TU.build();
EXPECT_THAT(AST.getDiagnostics(), llvm::ValueIs(IsEmpty()));
}
} // namespace
} // namespace clangd
} // namespace clang

0 comments on commit 3c2cb8e

Please sign in to comment.