return Output;
}
+ bool includeSymbolFromIndex(const Symbol &Sym) {
+ if (CCContextKind == CodeCompletionContext::CCC_ObjCProtocolName) {
+ return Sym.SymInfo.Lang == index::SymbolLanguage::ObjC &&
+ Sym.SymInfo.Kind == index::SymbolKind::Protocol;
+ }
+ return true;
+ }
+
SymbolSlab queryIndex() {
trace::Span Tracer("Query index");
SPAN_ATTACH(Tracer, "limit", int64_t(Opts.Limit));
// Run the query against the index.
SymbolSlab::Builder ResultsBuilder;
- if (Opts.Index->fuzzyFind(
- Req, [&](const Symbol &Sym) { ResultsBuilder.insert(Sym); }))
+ if (Opts.Index->fuzzyFind(Req, [&](const Symbol &Sym) {
+ if (includeSymbolFromIndex(Sym))
+ ResultsBuilder.insert(Sym);
+ }))
Incomplete = true;
return std::move(ResultsBuilder).build();
}
EXPECT_THAT(C, ElementsAre(signature("(id)object")));
}
+TEST(CompletionTest, ObjectiveCProtocolFromIndex) {
+ Symbol FoodClass = objcClass("FoodClass");
+ Symbol SymFood = objcProtocol("Food");
+ Symbol SymFooey = objcProtocol("Fooey");
+ auto Results = completions(R"objc(
+ id<Foo^>
+ )objc",
+ {SymFood, FoodClass, SymFooey},
+ /*Opts=*/{}, "Foo.m");
+
+ auto C = Results.Completions;
+ EXPECT_THAT(C, UnorderedElementsAre(named("Food"), named("Fooey")));
+}
+
TEST(CompletionTest, CursorInSnippets) {
clangd::CodeCompleteOptions Options;
Options.EnableSnippets = true;
return sym(Name, index::SymbolKind::Concept, "@CT@\\0");
}
+Symbol objcSym(llvm::StringRef Name, index::SymbolKind Kind,
+ llvm::StringRef USRPrefix) {
+ Symbol Sym;
+ std::string USR = USRPrefix.str() + Name.str();
+ Sym.Name = Name;
+ Sym.Scope = "";
+ Sym.ID = SymbolID(USR);
+ Sym.SymInfo.Kind = Kind;
+ Sym.SymInfo.Lang = index::SymbolLanguage::ObjC;
+ Sym.Flags |= Symbol::IndexedForCodeCompletion;
+ Sym.Origin = SymbolOrigin::Static;
+ return Sym;
+}
+
+Symbol objcClass(llvm::StringRef Name) {
+ return objcSym(Name, index::SymbolKind::Class, "objc(cs)");
+}
+
+Symbol objcProtocol(llvm::StringRef Name) {
+ return objcSym(Name, index::SymbolKind::Protocol, "objc(pl)");
+}
+
SymbolSlab generateSymbols(std::vector<std::string> QualifiedNames) {
SymbolSlab::Builder Slab;
for (llvm::StringRef QName : QualifiedNames)
// Create a C++20 concept symbol.
Symbol conceptSym(llvm::StringRef Name);
+// Create an Objective-C symbol.
+Symbol objcSym(llvm::StringRef Name, index::SymbolKind Kind,
+ llvm::StringRef USRPrefix);
+// Create an @interface or @implementation.
+Symbol objcClass(llvm::StringRef Name);
+// Create an @protocol.
+Symbol objcProtocol(llvm::StringRef Name);
+
// Create a slab of symbols with the given qualified names as IDs and names.
SymbolSlab generateSymbols(std::vector<std::string> QualifiedNames);