Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang-tools-extra/clangd/index/SymbolCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
auto Name = ND.getDeclName();
const auto NameKind = Name.getNameKind();
if (NameKind != DeclarationName::Identifier &&
NameKind != DeclarationName::CXXConstructorName)
NameKind != DeclarationName::CXXConstructorName &&
NameKind != DeclarationName::ObjCZeroArgSelector &&
NameKind != DeclarationName::ObjCOneArgSelector)
return false;
const auto &AST = ND.getASTContext();
const auto &SM = AST.getSourceManager();
Expand All @@ -183,6 +185,8 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
if (clang::Lexer::getRawToken(Loc, Tok, SM, LO))
return false;
auto StrName = Name.getAsString();
if (const auto *MD = dyn_cast<ObjCMethodDecl>(&ND))
StrName = MD->getSelector().getNameForSlot(0).str();
return clang::Lexer::getSpelling(Tok, SM, LO) == StrName;
}
} // namespace
Expand Down
44 changes: 44 additions & 0 deletions clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ MATCHER(refRange, "") {
MATCHER_P2(OverriddenBy, Subject, Object, "") {
return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID};
}
MATCHER(isSpelled, "") {
return static_cast<bool>(arg.Kind & RefKind::Spelled);
}
::testing::Matcher<const std::vector<Ref> &>
haveRanges(const std::vector<Range> Ranges) {
return ::testing::UnorderedPointwise(refRange(), Ranges);
Expand Down Expand Up @@ -524,6 +527,47 @@ TEST_F(SymbolCollectorTest, templateArgs) {
forCodeCompletion(false)))));
}

TEST_F(SymbolCollectorTest, ObjCRefs) {
Annotations Header(R"(
@interface Person
- (void)$talk[[talk]];
- (void)$say[[say]]:(id)something;
@end
@interface Person (Category)
- (void)categoryMethod;
- (void)multiArg:(id)a method:(id)b;
@end
)");
Annotations Main(R"(
@implementation Person
- (void)$talk[[talk]] {}
- (void)$say[[say]]:(id)something {}
@end

void fff(Person *p) {
[p $talk[[talk]]];
[p $say[[say]]:0];
[p categoryMethod];
[p multiArg:0 method:0];
}
)");
CollectorOpts.RefFilter = RefKind::All;
CollectorOpts.CollectMainFileRefs = true;
TestFileName = testPath("test.m");
runSymbolCollector(Header.code(), Main.code(),
{"-fblocks", "-xobjective-c++", "-Wno-objc-root-class"});
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::talk").ID,
haveRanges(Main.ranges("talk")))));
EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
haveRanges(Main.ranges("say")))));
EXPECT_THAT(Refs,
Contains(Pair(findSymbol(Symbols, "Person::categoryMethod").ID,
ElementsAre(isSpelled()))));
EXPECT_THAT(Refs,
Contains(Pair(findSymbol(Symbols, "Person::multiArg:method:").ID,
ElementsAre(Not(isSpelled())))));
}

TEST_F(SymbolCollectorTest, ObjCSymbols) {
const std::string Header = R"(
@interface Person
Expand Down