]> granicus.if.org Git - clang/commitdiff
[CodeComplete] only respect LoadExternal hint at namespace/tu scope
authorSam McCall <sam.mccall@gmail.com>
Wed, 24 Jan 2018 17:50:20 +0000 (17:50 +0000)
committerSam McCall <sam.mccall@gmail.com>
Wed, 24 Jan 2018 17:50:20 +0000 (17:50 +0000)
Reviewers: ilya-biryukov

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D42428

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@323347 91177308-0d34-0410-b5e6-96231b3b80d8

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

index f1a58f8e08acbf64b5fad011ad0fa9209ecd7120..ebbf38975a1e89364e3af88806d0fd552bcbf45a 100644 (file)
@@ -5247,9 +5247,9 @@ enum CXCodeComplete_Flags {
   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 bfba2be3ec90e2bb01c29e73efb88acdc5a0b640..bdd4732fd77377201bdbf90bb9d5c675a1fe549a 100644 (file)
@@ -35,8 +35,8 @@ public:
   /// 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 7e7eac38c1f14ea93f6aac2eb57c998f951832b0..dd54fb4ad9e53b2ab401b80f538a8279d05b9de0 100644 (file)
@@ -3543,10 +3543,13 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result,
   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);
index 1aabd5f5a291be6b4eb73cd247e0b46b7f434767..6abf40df36c1e68f7ece745aa0228d91cb687296 100644 (file)
@@ -3,8 +3,9 @@ int bar;
 }
 
 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 @@ int main() { return ns:: }
 // 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}
+