[clang-tools-extra] 544d20e - [clangd] Dont index ObjCCategoryDecls for completion
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 22 13:42:53 PDT 2021
Author: Kadir Cetinkaya
Date: 2021-06-22T22:42:25+02:00
New Revision: 544d20eab662e29640c8435033e7458e5ee1857e
URL: https://github.com/llvm/llvm-project/commit/544d20eab662e29640c8435033e7458e5ee1857e
DIFF: https://github.com/llvm/llvm-project/commit/544d20eab662e29640c8435033e7458e5ee1857e.diff
LOG: [clangd] Dont index ObjCCategoryDecls for completion
They are already provided by Sema, deserializing from preamble if need
be. Moreover category names are meaningless outside interface/implementation
context, hence they were only causing noise.
Differential Revision: https://reviews.llvm.org/D104540
Added:
Modified:
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 19f33a40f889b..2eff1c61fa3b3 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -62,6 +62,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"
@@ -1910,6 +1911,13 @@ bool isIndexedForCodeCompletion(const NamedDecl &ND, ASTContext &ASTCtx) {
if (isExplicitTemplateSpecialization(&ND))
return false;
+ // Category decls are not useful on their own outside the interface or
+ // implementation blocks. Moreover, sema already provides completion for
+ // these, even if it requires preamble deserialization. So by excluding them
+ // from the index, we reduce the noise in all the other completion scopes.
+ if (llvm::isa<ObjCCategoryDecl>(&ND) || llvm::isa<ObjCCategoryImplDecl>(&ND))
+ return false;
+
if (InTopLevelScope(ND))
return true;
diff --git a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
index 78f6e7c4aa9fe..cfa2def7a615d 100644
--- a/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3221,6 +3221,45 @@ TEST(CompletionTest, NoCrashDueToMacroOrdering) {
UnorderedElementsAre(Labeled("ECHO(X)"), Labeled("ECHO2(X)")));
}
+TEST(CompletionTest, ObjCCategoryDecls) {
+ TestTU TU;
+ TU.ExtraArgs.push_back("-xobjective-c");
+ TU.HeaderCode = R"objc(
+ @interface Foo
+ @end
+
+ @interface Foo (FooExt1)
+ @end
+
+ @interface Foo (FooExt2)
+ @end
+
+ @interface Bar
+ @end
+
+ @interface Bar (BarExt)
+ @end)objc";
+
+ {
+ Annotations Test(R"objc(
+ @implementation Foo (^)
+ @end
+ )objc");
+ TU.Code = Test.code().str();
+ auto Results = completions(TU, Test.point());
+ EXPECT_THAT(Results.Completions,
+ UnorderedElementsAre(Labeled("FooExt1"), Labeled("FooExt2")));
+ }
+ {
+ Annotations Test(R"objc(
+ @interface Foo (^)
+ @end
+ )objc");
+ TU.Code = Test.code().str();
+ auto Results = completions(TU, Test.point());
+ EXPECT_THAT(Results.Completions, UnorderedElementsAre(Labeled("BarExt")));
+ }
+}
} // namespace
} // namespace clangd
} // namespace clang
diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 87df23baf48a7..e24c3c1d60b47 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -552,8 +552,9 @@ TEST_F(SymbolCollectorTest, ObjCSymbols) {
EXPECT_THAT(Symbols,
UnorderedElementsAre(
QName("Person"), QName("Person::someMethodName:lastName:"),
- QName("MyCategory"), QName("Person::someMethodName2:"),
- QName("MyProtocol"), QName("MyProtocol::someMethodName3:")));
+ AllOf(QName("MyCategory"), ForCodeCompletion(false)),
+ QName("Person::someMethodName2:"), QName("MyProtocol"),
+ QName("MyProtocol::someMethodName3:")));
}
TEST_F(SymbolCollectorTest, ObjCPropertyImpl) {
More information about the cfe-commits
mailing list