diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -991,6 +991,7 @@ continue; IndexRequest.IDs.insert(S.IDForDoc); } + IndexRequest.IncludeObjC = S.getLangOpts().ObjC; Index->lookup(IndexRequest, [&](const Symbol &S) { if (!S.Documentation.empty()) FetchedDocs[S.ID] = std::string(S.Documentation); @@ -1415,6 +1416,8 @@ llvm::Optional PreferredType; // Initialized once Sema runs. // Whether to query symbols from any scope. Initialized once Sema runs. bool AllScopes = false; + /// Whether Objective-C symbols should be included in the search. + bool IncludeObjC = false; llvm::StringSet<> ContextWords; // Include-insertion and proximity scoring rely on the include structure. // This is available after Sema has run. @@ -1635,13 +1638,14 @@ } Filter = FuzzyMatcher( Recorder->CCSema->getPreprocessor().getCodeCompletionFilter()); + auto &ASTCtx = Recorder->CCSema->getASTContext(); + IncludeObjC = ASTCtx.getLangOpts().ObjC; std::tie(QueryScopes, AllScopes) = getQueryScopes( Recorder->CCContext, *Recorder->CCSema, HeuristicPrefix, Opts); if (!QueryScopes.empty()) ScopeProximity.emplace(QueryScopes); PreferredType = - OpaqueType::fromType(Recorder->CCSema->getASTContext(), - Recorder->CCContext.getPreferredType()); + OpaqueType::fromType(ASTCtx, Recorder->CCContext.getPreferredType()); // Sema provides the needed context to query the index. // FIXME: in addition to querying for extra/overlapping symbols, we should // explicitly request symbols corresponding to Sema results. @@ -1685,6 +1689,7 @@ Req.RestrictForCodeCompletion = true; Req.Scopes = QueryScopes; Req.AnyScope = AllScopes; + Req.IncludeObjC = IncludeObjC; // FIXME: we should send multiple weighted paths here. Req.ProximityPaths.push_back(std::string(FileName)); if (PreferredType) diff --git a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp --- a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp +++ b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp @@ -75,6 +75,7 @@ return None; } LookupRequest Request; + Request.IncludeObjC = AST.getLangOpts().ObjC; // Find all symbols present in the original file. for (const auto *D : getIndexableLocalDecls(AST)) { if (auto ID = getSymbolID(D)) diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -331,6 +331,7 @@ return; LookupRequest Req; Req.IDs.insert(ID); + Req.IncludeObjC = ND.getASTContext().getLangOpts().ObjC; Index->lookup(Req, [&](const Symbol &S) { Hover.Documentation = std::string(S.Documentation); }); diff --git a/clang-tools-extra/clangd/IncludeFixer.h b/clang-tools-extra/clangd/IncludeFixer.h --- a/clang-tools-extra/clangd/IncludeFixer.h +++ b/clang-tools-extra/clangd/IncludeFixer.h @@ -61,6 +61,9 @@ std::string Name; // E.g. "X" in foo::X. SourceLocation Loc; // Start location of the unresolved name. std::vector Scopes; // Namespace scopes we should search in. + /// Whether Objective-C symbols should be included in the search for this + /// name. + bool IncludeObjC = false; }; /// Records the last unresolved name seen by Sema. diff --git a/clang-tools-extra/clangd/IncludeFixer.cpp b/clang-tools-extra/clangd/IncludeFixer.cpp --- a/clang-tools-extra/clangd/IncludeFixer.cpp +++ b/clang-tools-extra/clangd/IncludeFixer.cpp @@ -511,6 +511,7 @@ UnresolvedName Unresolved; Unresolved.Name = Extracted->Name; Unresolved.Loc = Typo.getBeginLoc(); + Unresolved.IncludeObjC = SemaPtr->getLangOpts().ObjC; if (!Extracted->ResolvedScope && !S) // Give up if no scope available. return TypoCorrection(); @@ -553,6 +554,7 @@ Req.AnyScope = false; Req.Query = Unresolved.Name; Req.Scopes = Unresolved.Scopes; + Req.IncludeObjC = Unresolved.IncludeObjC; Req.RestrictForCodeCompletion = true; Req.Limit = 100; diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -455,6 +455,7 @@ // Now query the index for all Symbol IDs we found in the AST. if (Index && !ResultIndex.empty()) { LookupRequest QueryRequest; + QueryRequest.IncludeObjC = AST.getLangOpts().ObjC; for (auto It : ResultIndex) QueryRequest.IDs.insert(It.first); std::string Scratch; @@ -588,6 +589,7 @@ // too much data, while still likely having enough for 3 results to remain // after additional filtering. Req.Limit = 10; + Req.IncludeObjC = AST.getLangOpts().ObjC; bool TooMany = false; using ScoredLocatedSymbol = std::pair; std::vector ScoredResults; @@ -1397,6 +1399,7 @@ } RelationsRequest OverriddenBy; + OverriddenBy.IncludeObjC = AST.getLangOpts().ObjC; if (Index) { OverriddenBy.Predicate = RelationKind::OverriddenBy; for (const NamedDecl *ND : Decls) { @@ -1472,6 +1475,7 @@ return; RefsRequest Req; Req.IDs = std::move(IDs); + Req.IncludeObjC = AST.getLangOpts().ObjC; if (Limit) { if (Limit < Results.References.size()) { // We've already filled our quota, still check the index to correctly diff --git a/clang-tools-extra/clangd/index/Index.h b/clang-tools-extra/clangd/index/Index.h --- a/clang-tools-extra/clangd/index/Index.h +++ b/clang-tools-extra/clangd/index/Index.h @@ -47,13 +47,15 @@ std::vector ProximityPaths; /// Preferred types of symbols. These are raw representation of `OpaqueType`. std::vector PreferredTypes; + /// Whether Objective-C symbols should be included in the search. + bool IncludeObjC = false; bool operator==(const FuzzyFindRequest &Req) const { return std::tie(Query, Scopes, Limit, RestrictForCodeCompletion, - ProximityPaths, PreferredTypes) == + ProximityPaths, PreferredTypes, IncludeObjC) == std::tie(Req.Query, Req.Scopes, Req.Limit, Req.RestrictForCodeCompletion, Req.ProximityPaths, - Req.PreferredTypes); + Req.PreferredTypes, Req.IncludeObjC); } bool operator!=(const FuzzyFindRequest &Req) const { return !(*this == Req); } }; @@ -63,6 +65,8 @@ struct LookupRequest { llvm::DenseSet IDs; + /// Whether Objective-C symbols should be included in the lookup. + bool IncludeObjC = false; }; struct RefsRequest { @@ -75,6 +79,8 @@ /// If set, populates the container of the reference. /// Index implementations may chose to populate containers no matter what. bool WantContainer = false; + /// Whether Objective-C code should be included in the search. + bool IncludeObjC = false; }; struct RelationsRequest { @@ -82,6 +88,8 @@ RelationKind Predicate; /// If set, limit the number of relations returned from the index. llvm::Optional Limit; + /// Whether Objective-C code should be included in the search. + bool IncludeObjC = false; }; /// Describes what data is covered by an index.