dgoldman created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
Herald added a project: All.
dgoldman requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

clangd will set this flag for files with ObjC language flag enabled. This can 
be used to only include ObjC symbols when searching for symbols.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127116

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/HeaderSourceSwitch.cpp
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeFixer.cpp
  clang-tools-extra/clangd/IncludeFixer.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/index/Index.h

Index: clang-tools-extra/clangd/index/Index.h
===================================================================
--- clang-tools-extra/clangd/index/Index.h
+++ clang-tools-extra/clangd/index/Index.h
@@ -47,13 +47,15 @@
   std::vector<std::string> ProximityPaths;
   /// Preferred types of symbols. These are raw representation of `OpaqueType`.
   std::vector<std::string> 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<SymbolID> 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<uint32_t> Limit;
+  /// Whether Objective-C code should be included in the search.
+  bool IncludeObjC = false;
 };
 
 /// Describes what data is covered by an index.
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ 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<float, LocatedSymbol>;
   std::vector<ScoredLocatedSymbol> 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
Index: clang-tools-extra/clangd/IncludeFixer.h
===================================================================
--- clang-tools-extra/clangd/IncludeFixer.h
+++ 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<std::string> 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.
Index: clang-tools-extra/clangd/IncludeFixer.cpp
===================================================================
--- clang-tools-extra/clangd/IncludeFixer.cpp
+++ 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;
 
Index: clang-tools-extra/clangd/Hover.cpp
===================================================================
--- clang-tools-extra/clangd/Hover.cpp
+++ 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);
   });
Index: clang-tools-extra/clangd/HeaderSourceSwitch.cpp
===================================================================
--- clang-tools-extra/clangd/HeaderSourceSwitch.cpp
+++ 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))
Index: clang-tools-extra/clangd/CodeComplete.cpp
===================================================================
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ 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<OpaqueType> 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)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to