[PATCH] D42428: [CodeComplete] only respect LoadExternal hint at namespace/tu scope

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 24 09:51:55 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL323347: [CodeComplete] only respect LoadExternal hint at namespace/tu scope (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42428

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/include/clang/Sema/CodeCompleteOptions.h
  cfe/trunk/lib/Sema/SemaLookup.cpp
  cfe/trunk/test/Index/complete-pch-skip.cpp


Index: cfe/trunk/include/clang-c/Index.h
===================================================================
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -5247,9 +5247,9 @@
   CXCodeComplete_IncludeBriefComments = 0x04,
 
   /**
-   * \brief Whether to speed up completion by omitting some entities which are
-   * defined in the preamble. There's no guarantee any particular entity will
-   * be omitted. This may be useful if the headers are indexed externally.
+   * Whether to speed up completion by omitting top- or namespace-level entities
+   * defined in the preamble. There's no guarantee any particular entity is
+   * omitted. This may be useful if the headers are indexed externally.
    */
   CXCodeComplete_SkipPreamble = 0x08
 };
Index: cfe/trunk/include/clang/Sema/CodeCompleteOptions.h
===================================================================
--- cfe/trunk/include/clang/Sema/CodeCompleteOptions.h
+++ cfe/trunk/include/clang/Sema/CodeCompleteOptions.h
@@ -35,8 +35,8 @@
   /// Show brief documentation comments in code completion results.
   unsigned IncludeBriefComments : 1;
 
-  /// Hint whether to load data from the external AST in order to provide
-  /// full results. If false, declarations from the preamble may be omitted.
+  /// Hint whether to load data from the external AST to provide full results.
+  /// If false, namespace-level declarations from the preamble may be omitted.
   unsigned LoadExternal : 1;
 
   CodeCompleteOptions()
Index: cfe/trunk/test/Index/complete-pch-skip.cpp
===================================================================
--- cfe/trunk/test/Index/complete-pch-skip.cpp
+++ cfe/trunk/test/Index/complete-pch-skip.cpp
@@ -3,8 +3,9 @@
 }
 
 int main() { return ns:: }
+int main2() { return ns::foo(). }
 
-// RUN: echo "namespace ns { int foo; }" > %t.h
+// RUN: echo "namespace ns { struct foo { int baz }; }" > %t.h
 // RUN: c-index-test -write-pch %t.h.pch -x c++-header %t.h
 //
 // RUN: c-index-test -code-completion-at=%s:5:26 -include %t.h %s | FileCheck -check-prefix=WITH-PCH %s
@@ -23,3 +24,7 @@
 // NO-PCH: {TypedText bar}
 // NO-PCH-NOT: foo
 
+// Verify that we still get member results from the preamble.
+// RUN: env CINDEXTEST_COMPLETION_SKIP_PREAMBLE=1 c-index-test -code-completion-at=%s:6:32 -include %t.h %s | FileCheck -check-prefix=MEMBER %s
+// MEMBER: {TypedText baz}
+
Index: cfe/trunk/lib/Sema/SemaLookup.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp
+++ cfe/trunk/lib/Sema/SemaLookup.cpp
@@ -3543,10 +3543,13 @@
   if (CXXRecordDecl *Class = dyn_cast<CXXRecordDecl>(Ctx))
     Result.getSema().ForceDeclarationOfImplicitMembers(Class);
 
+  // We sometimes skip loading namespace-level results (they tend to be huge).
+  bool Load = LoadExternal ||
+              !(isa<TranslationUnitDecl>(Ctx) || isa<NamespaceDecl>(Ctx));
   // Enumerate all of the results in this context.
   for (DeclContextLookupResult R :
-       LoadExternal ? Ctx->lookups()
-                    : Ctx->noload_lookups(/*PreserveInternalState=*/false)) {
+       Load ? Ctx->lookups()
+            : Ctx->noload_lookups(/*PreserveInternalState=*/false)) {
     for (auto *D : R) {
       if (auto *ND = Result.getAcceptableDecl(D)) {
         Consumer.FoundDecl(ND, Visited.checkHidden(ND), Ctx, InBaseClass);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42428.131301.patch
Type: text/x-patch
Size: 3381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180124/7a9a1fa8/attachment.bin>


More information about the cfe-commits mailing list