[PATCH] D104540: [clangd] Dont index ObjCCategoryDecls for completion
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 22 08:22:38 PDT 2021
kadircet updated this revision to Diff 353658.
kadircet marked an inline comment as done.
kadircet added a comment.
- Also handle ObjcCategoryImplDecl
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104540/new/
https://reviews.llvm.org/D104540
Files:
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -552,8 +552,9 @@
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) {
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -3221,6 +3221,45 @@
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
Index: clang-tools-extra/clangd/CodeComplete.cpp
===================================================================
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ 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 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104540.353658.patch
Type: text/x-patch
Size: 3123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210622/791218df/attachment.bin>
More information about the cfe-commits
mailing list