From 0f91c8ccb398be2bd40dc402309bd79737542396 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Sat, 30 Jul 2011 06:55:39 +0000 Subject: [PATCH] When performing code completion after at @interface, allow both already-defined and forward-declared results. Already-defined results are fine because they could be the start of a category. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136559 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/CodeCompleteConsumer.h | 4 +-- lib/Frontend/ASTUnit.cpp | 4 +-- lib/Sema/CodeCompleteConsumer.cpp | 2 +- lib/Sema/SemaCodeComplete.cpp | 44 +++++++++++++---------- test/Index/complete-interfaces.m | 4 +++ tools/libclang/CIndexCodeCompletion.cpp | 2 +- 6 files changed, 35 insertions(+), 25 deletions(-) diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index 8c7a00280b..2213c7c7e6 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -248,9 +248,9 @@ public: CCC_ObjCInstanceMessage, /// \brief Code completion where an Objective-C class message is expected. CCC_ObjCClassMessage, - /// \brief Code completion where a superclass of an Objective-C class is + /// \brief Code completion where the name of an Objective-C class is /// expected. - CCC_ObjCSuperclass, + CCC_ObjCInterfaceName, /// \brief Code completion where an Objective-C category name is expected. CCC_ObjCCategoryName, /// \brief An unknown context, in which we are recovering from a parsing diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index dea9ed139a..f19acd093a 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -186,7 +186,7 @@ static unsigned getDeclShowContexts(NamedDecl *ND, // In Objective-C, you can only be a subclass of another Objective-C class if (isa(ND)) - Contexts |= (1 << (CodeCompletionContext::CCC_ObjCSuperclass - 1)); + Contexts |= (1 << (CodeCompletionContext::CCC_ObjCInterfaceName - 1)); // Deal with tag names. if (isa(ND)) { @@ -1992,7 +1992,7 @@ static void CalculateHiddenNames(const CodeCompletionContext &Context, case CodeCompletionContext::CCC_Name: case CodeCompletionContext::CCC_PotentiallyQualifiedName: case CodeCompletionContext::CCC_ParenthesizedExpression: - case CodeCompletionContext::CCC_ObjCSuperclass: + case CodeCompletionContext::CCC_ObjCInterfaceName: break; case CodeCompletionContext::CCC_EnumTag: diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index e753d6224a..3db9e4dcd5 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/lib/Sema/CodeCompleteConsumer.cpp @@ -67,7 +67,7 @@ bool CodeCompletionContext::wantConstructorResults() const { case CCC_OtherWithMacros: case CCC_ObjCInstanceMessage: case CCC_ObjCClassMessage: - case CCC_ObjCSuperclass: + case CCC_ObjCInterfaceName: case CCC_ObjCCategoryName: return false; } diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index f91d690796..66ecae0b79 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -5325,21 +5325,23 @@ void Sema::CodeCompleteObjCInterfaceDecl(Scope *S) { CodeCompletionContext::CCC_Other); Results.EnterNewScope(); - // Add all classes. - AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, true, - false, Results); - + if (CodeCompleter->includeGlobals()) { + // Add all classes. + AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false, + false, Results); + } + Results.ExitScope(); - // FIXME: Use cached global completion results. + HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, + CodeCompletionContext::CCC_ObjCInterfaceName, Results.data(),Results.size()); } void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName, SourceLocation ClassNameLoc) { ResultBuilder Results(*this, CodeCompleter->getAllocator(), - CodeCompletionContext::CCC_ObjCSuperclass); + CodeCompletionContext::CCC_ObjCInterfaceName); Results.EnterNewScope(); // Make sure that we ignore the class we're currently defining. @@ -5348,14 +5350,16 @@ void Sema::CodeCompleteObjCSuperclass(Scope *S, IdentifierInfo *ClassName, if (CurClass && isa(CurClass)) Results.Ignore(CurClass); - // Add all classes. - AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false, - false, Results); - + if (CodeCompleter->includeGlobals()) { + // Add all classes. + AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false, + false, Results); + } + Results.ExitScope(); - // FIXME: Use cached global completion results. + HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_ObjCSuperclass, + CodeCompletionContext::CCC_ObjCInterfaceName, Results.data(),Results.size()); } @@ -5364,14 +5368,16 @@ void Sema::CodeCompleteObjCImplementationDecl(Scope *S) { CodeCompletionContext::CCC_Other); Results.EnterNewScope(); - // Add all unimplemented classes. - AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false, - true, Results); - + if (CodeCompleter->includeGlobals()) { + // Add all unimplemented classes. + AddInterfaceResults(Context.getTranslationUnitDecl(), CurContext, false, + true, Results); + } + Results.ExitScope(); - // FIXME: Use cached global completion results. + HandleCodeCompleteResults(this, CodeCompleter, - CodeCompletionContext::CCC_Other, + CodeCompletionContext::CCC_ObjCInterfaceName, Results.data(),Results.size()); } diff --git a/test/Index/complete-interfaces.m b/test/Index/complete-interfaces.m index 229ec2dcbe..2f86c3d8f4 100644 --- a/test/Index/complete-interfaces.m +++ b/test/Index/complete-interfaces.m @@ -27,6 +27,7 @@ // RUN: c-index-test -code-completion-at=%s:11:12 %s | FileCheck -check-prefix=CHECK-CC2 %s // CHECK-CC2: ObjCInterfaceDecl:{TypedText Int1} // CHECK-CC2-NEXT: ObjCInterfaceDecl:{TypedText Int2} +// CHECK-CC2-NEXT: ObjCInterfaceDecl:{TypedText Int3} // CHECK-CC2-NEXT: ObjCInterfaceDecl:{TypedText Int4} // RUN: c-index-test -code-completion-at=%s:11:19 %s | FileCheck -check-prefix=CHECK-CC3 %s // CHECK-CC3: ObjCInterfaceDecl:{TypedText Int1} @@ -41,3 +42,6 @@ // CHECK-CC5: ObjCInterfaceDecl:{TypedText Int1} // CHECK-CC5-NEXT: ObjCInterfaceDecl:{TypedText Int3} // CHECK-CC5-NEXT: ObjCInterfaceDecl:{TypedText Int4} + + +// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:11:12 %s | FileCheck -check-prefix=CHECK-CC2 %s diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp index 9dbc7fa2a8..93571e0c35 100644 --- a/tools/libclang/CIndexCodeCompletion.cpp +++ b/tools/libclang/CIndexCodeCompletion.cpp @@ -438,7 +438,7 @@ static unsigned long long getContextsForContextKind( contexts = CXCompletionContext_ObjCClassMessage; break; } - case CodeCompletionContext::CCC_ObjCSuperclass: { + case CodeCompletionContext::CCC_ObjCInterfaceName: { contexts = CXCompletionContext_ObjCInterface; break; } -- 2.40.0