From: Douglas Gregor Date: Fri, 18 Dec 2009 18:53:37 +0000 (+0000) Subject: Extend code-completion results with the type of each result X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ff5ce6eefc7c253ef6edf4d4bfc996fdd82d09aa;p=clang Extend code-completion results with the type of each result git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91702 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 574ea2403c..03b4df1259 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -556,7 +556,15 @@ enum CXCompletionChunkKind { /** * \brief A comma separator (','). */ - CXCompletionChunk_Comma + CXCompletionChunk_Comma, + /** + * \brief Text that specifies the result type of a given result. + * + * This special kind of informative chunk is not meant to be inserted into + * the text buffer. Rather, it is meant to illustrate the type that an + * expression using the given completion string would have. + */ + CXCompletionChunk_ResultType }; /** diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index 84c179f789..aec10f32fe 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -61,6 +61,9 @@ public: /// \brief A piece of text that describes something about the result but /// should not be inserted into the buffer. CK_Informative, + /// \brief A piece of text that describes the type of an entity or, for + /// functions and methods, the return type. + CK_ResultType, /// \brief A piece of text that describes the parameter that corresponds /// to the code-completion location within a function call, message send, /// macro invocation, etc. @@ -120,6 +123,9 @@ public: /// \brief Create a new informative chunk. static Chunk CreateInformative(llvm::StringRef Informative); + /// \brief Create a new result type chunk. + static Chunk CreateResultType(llvm::StringRef ResultType); + /// \brief Create a new current-parameter chunk. static Chunk CreateCurrentParameter(llvm::StringRef CurrentParameter); @@ -186,6 +192,12 @@ public: Chunks.push_back(Chunk::CreateInformative(Text)); } + /// \brief Add a new result-type chunk. + /// The text will be copied. + void AddResultTypeChunk(llvm::StringRef ResultType) { + Chunks.push_back(Chunk::CreateResultType(ResultType)); + } + /// \brief Add a new current-parameter chunk. /// The text will be copied. void AddCurrentParameterChunk(llvm::StringRef CurrentParameter) { diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index d8ed8949cb..b9b85dfb80 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/lib/Sema/CodeCompleteConsumer.cpp @@ -37,6 +37,7 @@ CodeCompletionString::Chunk::Chunk(ChunkKind Kind, llvm::StringRef Text) case CK_Text: case CK_Placeholder: case CK_Informative: + case CK_ResultType: case CK_CurrentParameter: { char *New = new char [Text.size() + 1]; std::memcpy(New, Text.data(), Text.size()); @@ -111,6 +112,11 @@ CodeCompletionString::Chunk::CreateInformative(StringRef Informative) { return Chunk(CK_Informative, Informative); } +CodeCompletionString::Chunk +CodeCompletionString::Chunk::CreateResultType(StringRef ResultType) { + return Chunk(CK_ResultType, ResultType); +} + CodeCompletionString::Chunk CodeCompletionString::Chunk::CreateCurrentParameter( StringRef CurrentParameter) { @@ -123,6 +129,7 @@ CodeCompletionString::Chunk CodeCompletionString::Chunk::Clone() const { case CK_Text: case CK_Placeholder: case CK_Informative: + case CK_ResultType: case CK_CurrentParameter: case CK_LeftParen: case CK_RightParen: @@ -156,6 +163,7 @@ CodeCompletionString::Chunk::Destroy() { case CK_Text: case CK_Placeholder: case CK_Informative: + case CK_ResultType: case CK_CurrentParameter: delete [] Text; break; @@ -186,7 +194,12 @@ std::string CodeCompletionString::getAsString() const { switch (C->Kind) { case CK_Optional: OS << "{#" << C->Optional->getAsString() << "#}"; break; case CK_Placeholder: OS << "<#" << C->Text << "#>"; break; - case CK_Informative: OS << "[#" << C->Text << "#]"; break; + + case CK_Informative: + case CK_ResultType: + OS << "[#" << C->Text << "#]"; + break; + case CK_CurrentParameter: OS << "<#" << C->Text << "#>"; break; default: OS << C->Text; break; } @@ -236,6 +249,7 @@ void CodeCompletionString::Serialize(llvm::raw_ostream &OS) const { case CK_Text: case CK_Placeholder: case CK_Informative: + case CK_ResultType: case CK_CurrentParameter: { const char *Text = C->Text; unsigned StrLen = strlen(Text); @@ -286,6 +300,7 @@ CodeCompletionString *CodeCompletionString::Deserialize(const char *&Str, case CK_Text: case CK_Placeholder: case CK_Informative: + case CK_ResultType: case CK_CurrentParameter: { unsigned StrLen; if (ReadUnsigned(Str, StrEnd, StrLen) || (Str + StrLen > StrEnd)) diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 6b485ba7a9..1391adfd48 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -829,6 +829,39 @@ static void AddTypeSpecifierResults(const LangOptions &LangOpts, unsigned Rank, } } +/// \brief If the given declaration has an associated type, add it as a result +/// type chunk. +static void AddResultTypeChunk(ASTContext &Context, + NamedDecl *ND, + CodeCompletionString *Result) { + if (!ND) + return; + + // Determine the type of the declaration (if it has a type). + QualType T; + if (FunctionDecl *Function = dyn_cast(ND)) + T = Function->getResultType(); + else if (ObjCMethodDecl *Method = dyn_cast(ND)) + T = Method->getResultType(); + else if (FunctionTemplateDecl *FunTmpl = dyn_cast(ND)) + T = FunTmpl->getTemplatedDecl()->getResultType(); + else if (EnumConstantDecl *Enumerator = dyn_cast(ND)) + T = Context.getTypeDeclType(cast(Enumerator->getDeclContext())); + else if (isa(ND)) { + /* Do nothing: ignore unresolved using declarations*/ + } else if (ValueDecl *Value = dyn_cast(ND)) + T = Value->getType(); + else if (ObjCPropertyDecl *Property = dyn_cast(ND)) + T = Property->getType(); + + if (T.isNull() || Context.hasSameType(T, Context.DependentTy)) + return; + + std::string TypeStr; + T.getAsStringInternal(TypeStr, Context.PrintingPolicy); + Result->AddResultTypeChunk(TypeStr); +} + /// \brief Add function parameter chunks to the given code completion string. static void AddFunctionParameterChunks(ASTContext &Context, FunctionDecl *Function, @@ -1042,6 +1075,8 @@ CodeCompleteConsumer::Result::CreateCodeCompletionString(Sema &S) { return Result; } + AddResultTypeChunk(S.Context, ND, Result); + if (FunctionDecl *Function = dyn_cast(ND)) { AddQualifierToCompletionString(Result, Qualifier, QualifierIsInformative, S.Context); @@ -1189,6 +1224,7 @@ CodeCompleteConsumer::OverloadCandidate::CreateSignatureString( CodeCompletionString *Result = new CodeCompletionString; FunctionDecl *FDecl = getFunction(); + AddResultTypeChunk(S.Context, FDecl, Result); const FunctionProtoType *Proto = dyn_cast(getFunctionType()); if (!FDecl && !Proto) { diff --git a/test/CodeCompletion/enum-switch-case-qualified.cpp b/test/CodeCompletion/enum-switch-case-qualified.cpp index 2c0569b4eb..d441269336 100644 --- a/test/CodeCompletion/enum-switch-case-qualified.cpp +++ b/test/CodeCompletion/enum-switch-case-qualified.cpp @@ -22,11 +22,11 @@ void test(enum N::C::Color color) { switch (color) { case // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:23:8 %s -o - | FileCheck -check-prefix=CC1 %s - // CHECK-CC1: Blue : 0 : N::C::Blue - // CHECK-CC1-NEXT: Green : 0 : N::C::Green - // CHECK-CC1-NEXT: Indigo : 0 : N::C::Indigo - // CHECK-CC1-NEXT: Orange : 0 : N::C::Orange - // CHECK-CC1-NEXT: Red : 0 : N::C::Red - // CHECK-CC1-NEXT: Violet : 0 : N::C::Violet - // CHECK-CC1: Yellow : 0 : N::C::Yellow + // CHECK-CC1: Blue : 0 : [#enum M::N::C::Color#]N::C::Blue + // CHECK-CC1-NEXT: Green : 0 : [#enum M::N::C::Color#]N::C::Green + // CHECK-CC1-NEXT: Indigo : 0 : [#enum M::N::C::Color#]N::C::Indigo + // CHECK-CC1-NEXT: Orange : 0 : [#enum M::N::C::Color#]N::C::Orange + // CHECK-CC1-NEXT: Red : 0 : [#enum M::N::C::Color#]N::C::Red + // CHECK-CC1-NEXT: Violet : 0 : [#enum M::N::C::Color#]N::C::Violet + // CHECK-CC1: Yellow : 0 : [#enum M::N::C::Color#]N::C::Yellow diff --git a/test/CodeCompletion/enum-switch-case.cpp b/test/CodeCompletion/enum-switch-case.cpp index d6b6cc2a80..ee8facae0d 100644 --- a/test/CodeCompletion/enum-switch-case.cpp +++ b/test/CodeCompletion/enum-switch-case.cpp @@ -20,9 +20,9 @@ void test(enum N::Color color) { case // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:21:8 %s -o - | FileCheck -check-prefix=CC1 %s - // CHECK-CC1: Blue : 0 : N::Blue - // CHECK-CC1-NEXT: Green : 0 : N::Green - // CHECK-CC1-NEXT: Indigo : 0 : N::Indigo - // CHECK-CC1-NEXT: Orange : 0 : N::Orange - // CHECK-CC1-NEXT: Violet : 0 : N::Violet + // CHECK-CC1: Blue : 0 : [#enum N::Color#]N::Blue + // CHECK-CC1-NEXT: Green : 0 : [#enum N::Color#]N::Green + // CHECK-CC1-NEXT: Indigo : 0 : [#enum N::Color#]N::Indigo + // CHECK-CC1-NEXT: Orange : 0 : [#enum N::Color#]N::Orange + // CHECK-CC1-NEXT: Violet : 0 : [#enum N::Color#]N::Violet diff --git a/test/CodeCompletion/member-access.cpp b/test/CodeCompletion/member-access.cpp index 271e9a0f1e..7d1637c272 100644 --- a/test/CodeCompletion/member-access.cpp +++ b/test/CodeCompletion/member-access.cpp @@ -28,15 +28,15 @@ public: void test(const Proxy &p) { p-> // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:29:6 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s - // CHECK-CC1: member1 : 0 : [#Base1::#]member1 - // CHECK-CC1: member1 : 0 : [#Base2::#]member1 - // CHECK-CC1: member2 : 0 : [#Base1::#]member2 + // CHECK-CC1: member1 : 0 : [#int#][#Base1::#]member1 + // CHECK-CC1: member1 : 0 : [#int#][#Base2::#]member1 + // CHECK-CC1: member2 : 0 : [#float#][#Base1::#]member2 // CHECK-CC1: member3 : 0 // CHECK-CC1: member4 : 0 - // CHECK-CC1: memfun1 : 0 : [#Base3::#]memfun1(<#float#>) - // CHECK-CC1: memfun1 : 0 : [#Base3::#]memfun1(<#double#>)[# const#] - // CHECK-CC1: memfun2 : 0 : [#Base3::#]memfun2(<#int#>) - // CHECK-CC1: memfun3 : 0 : memfun3(<#int#>) - // CHECK-CC1: memfun1 : 0 (Hidden) : Base2::memfun1(<#int#>) + // CHECK-CC1: memfun1 : 0 : [#void#][#Base3::#]memfun1(<#float#>) + // CHECK-CC1: memfun1 : 0 : [#void#][#Base3::#]memfun1(<#double#>)[# const#] + // CHECK-CC1: memfun2 : 0 : [#void#][#Base3::#]memfun2(<#int#>) + // CHECK-CC1: memfun3 : 0 : [#int#]memfun3(<#int#>) + // CHECK-CC1: memfun1 : 0 (Hidden) : [#void#]Base2::memfun1(<#int#>) // CHECK-CC1: Base1 : 3 : Base1:: diff --git a/test/Index/code-completion.cpp b/test/Index/code-completion.cpp index c286c82d04..55d068a166 100644 --- a/test/Index/code-completion.cpp +++ b/test/Index/code-completion.cpp @@ -33,20 +33,22 @@ void test_overloaded() { overloaded(Z(), 0); } -// CHECK-MEMBER: FieldDecl:{TypedText member} -// CHECK-MEMBER: FunctionDecl:{Informative Y::}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )} -// CHECK-MEMBER: EnumConstantDecl:{Informative E::}{TypedText Val1} -// CHECK-MEMBER: FunctionDecl:{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} -// CHECK-MEMBER: FunctionDecl:{TypedText operator int}{LeftParen (}{RightParen )} -// CHECK-MEMBER: FunctionDecl:{TypedText operator=}{LeftParen (}{Placeholder struct Z const &}{RightParen )} -// CHECK-MEMBER: FieldDecl:{Text X::}{TypedText member} -// CHECK-MEMBER: FieldDecl:{Text Y::}{TypedText member} -// CHECK-MEMBER: FunctionDecl:{Text X::}{TypedText operator=}{LeftParen (}{Placeholder struct X const &}{RightParen )} -// CHECK-MEMBER: FunctionDecl:{Text Y::}{TypedText operator=}{LeftParen (}{Placeholder struct Y const &}{RightParen )} +// CHECK-MEMBER: FieldDecl:{ResultType double}{TypedText member} +// CHECK-MEMBER: FunctionDecl:{ResultType void}{Informative Y::}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )} +// CHECK-MEMBER: EnumConstantDecl:{ResultType enum X::E}{Informative E::}{TypedText Val1} +// CHECK-MEMBER: FunctionDecl:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} +// CHECK-MEMBER: FunctionDecl:{ResultType void}{Informative Y::}{TypedText ~Y}{LeftParen (}{RightParen )} +// CHECK-MEMBER: FunctionDecl:{ResultType void}{TypedText ~Z}{LeftParen (}{RightParen )} +// CHECK-MEMBER: FunctionDecl:{ResultType int}{TypedText operator int}{LeftParen (}{RightParen )}{Informative const} +// CHECK-MEMBER: FunctionDecl:{ResultType struct Z &}{TypedText operator=}{LeftParen (}{Placeholder struct Z const &}{RightParen )} +// CHECK-MEMBER: FieldDecl:{ResultType int}{Text X::}{TypedText member} +// CHECK-MEMBER: FieldDecl:{ResultType float}{Text Y::}{TypedText member} +// CHECK-MEMBER: FunctionDecl:{ResultType struct X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder struct X const &}{RightParen )} +// CHECK-MEMBER: FunctionDecl:{ResultType struct Y &}{Text Y::}{TypedText operator=}{LeftParen (}{Placeholder struct Y const &}{RightParen )} // CHECK-MEMBER: StructDecl:{TypedText X}{Text ::} // CHECK-MEMBER: StructDecl:{TypedText Y}{Text ::} // CHECK-MEMBER: StructDecl:{TypedText Z}{Text ::} -// CHECK-OVERLOAD: NotImplemented:{Text overloaded}{LeftParen (}{Text struct Z z}{Comma , }{CurrentParameter int second}{RightParen )} -// CHECK-OVERLOAD: NotImplemented:{Text overloaded}{LeftParen (}{Text int i}{Comma , }{CurrentParameter long second}{RightParen )} -// CHECK-OVERLOAD: NotImplemented:{Text overloaded}{LeftParen (}{Text float f}{Comma , }{CurrentParameter int second}{RightParen )} +// CHECK-OVERLOAD: NotImplemented:{ResultType int &}{Text overloaded}{LeftParen (}{Text struct Z z}{Comma , }{CurrentParameter int second}{RightParen )} +// CHECK-OVERLOAD: NotImplemented:{ResultType float &}{Text overloaded}{LeftParen (}{Text int i}{Comma , }{CurrentParameter long second}{RightParen )} +// CHECK-OVERLOAD: NotImplemented:{ResultType double &}{Text overloaded}{LeftParen (}{Text float f}{Comma , }{CurrentParameter int second}{RightParen )} diff --git a/test/Index/complete-member-access.m b/test/Index/complete-member-access.m index 9202d0522f..2502d7705b 100644 --- a/test/Index/complete-member-access.m +++ b/test/Index/complete-member-access.m @@ -23,8 +23,8 @@ void test_props(Int* ptr) { } // RUN: c-index-test -code-completion-at=%s:21:7 %s | FileCheck -check-prefix=CHECK-CC1 %s -// CHECK-CC1: ObjCPropertyDecl:{TypedText prop1} -// CHECK-CC1: ObjCPropertyDecl:{TypedText ProtoProp} +// CHECK-CC1: ObjCPropertyDecl:{ResultType int}{TypedText prop1} +// CHECK-CC1: ObjCPropertyDecl:{ResultType float}{TypedText ProtoProp} // RUN: c-index-test -code-completion-at=%s:22:8 %s | FileCheck -check-prefix=CHECK-CC2 %s -// CHECK-CC2: ObjCIvarDecl:{TypedText IVar} -// CHECK-CC2: ObjCIvarDecl:{TypedText SuperIVar} +// CHECK-CC2: ObjCIvarDecl:{ResultType int}{TypedText IVar} +// CHECK-CC2: ObjCIvarDecl:{ResultType int}{TypedText SuperIVar} diff --git a/test/Index/complete-objc-message.m b/test/Index/complete-objc-message.m index 1c03095e2a..740b498126 100644 --- a/test/Index/complete-objc-message.m +++ b/test/Index/complete-objc-message.m @@ -106,38 +106,38 @@ void test_overload(Overload *ovl) { // CHECK-CC2: {TypedText instanceMethod1} // CHECK-CC2: {TypedText protocolInstanceMethod:}{Placeholder (int)value} // RUN: c-index-test -code-completion-at=%s:61:16 %s | FileCheck -check-prefix=CHECK-CC3 %s -// CHECK-CC3: ObjCClassMethodDecl:{TypedText MyClassMethod:}{Placeholder (id)obj} -// CHECK-CC3: ObjCClassMethodDecl:{TypedText MyPrivateMethod} +// CHECK-CC3: ObjCClassMethodDecl:{ResultType int}{TypedText MyClassMethod:}{Placeholder (id)obj} +// CHECK-CC3: ObjCClassMethodDecl:{ResultType int}{TypedText MyPrivateMethod} // RUN: c-index-test -code-completion-at=%s:65:16 %s | FileCheck -check-prefix=CHECK-CC4 %s -// CHECK-CC4: ObjCInstanceMethodDecl:{TypedText MyInstMethod:}{Placeholder (id)x}{Text second:}{Placeholder (id)y} -// CHECK-CC4: ObjCInstanceMethodDecl:{TypedText MyPrivateInstMethod} +// CHECK-CC4: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyInstMethod:}{Placeholder (id)x}{Text second:}{Placeholder (id)y} +// CHECK-CC4: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyPrivateInstMethod} // RUN: c-index-test -code-completion-at=%s:74:9 %s | FileCheck -check-prefix=CHECK-CC5 %s -// CHECK-CC5: ObjCInstanceMethodDecl:{TypedText MyInstMethod:}{Placeholder (id)x}{Text second:}{Placeholder (id)y} -// CHECK-CC5: ObjCInstanceMethodDecl:{TypedText MySubInstMethod} +// CHECK-CC5: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyInstMethod:}{Placeholder (id)x}{Text second:}{Placeholder (id)y} +// CHECK-CC5: ObjCInstanceMethodDecl:{ResultType int}{TypedText MySubInstMethod} // RUN: c-index-test -code-completion-at=%s:82:8 %s | FileCheck -check-prefix=CHECK-CC6 %s -// CHECK-CC6: ObjCInstanceMethodDecl:{TypedText protocolInstanceMethod:}{Placeholder (int)value} -// CHECK-CC6: ObjCInstanceMethodDecl:{TypedText secondProtocolInstanceMethod} +// CHECK-CC6: ObjCInstanceMethodDecl:{ResultType id}{TypedText protocolInstanceMethod:}{Placeholder (int)value} +// CHECK-CC6: ObjCInstanceMethodDecl:{ResultType int}{TypedText secondProtocolInstanceMethod} // RUN: c-index-test -code-completion-at=%s:95:8 %s | FileCheck -check-prefix=CHECK-CC7 %s -// CHECK-CC7: ObjCInstanceMethodDecl:{TypedText Method} -// CHECK-CC7: ObjCInstanceMethodDecl:{TypedText Method:}{Placeholder (int)i} -// CHECK-CC7: ObjCInstanceMethodDecl:{TypedText Method:}{Placeholder (float)f}{Text Arg1:}{Placeholder (int)i1}{Text Arg2:}{Placeholder (int)i2} -// CHECK-CC7: ObjCInstanceMethodDecl:{TypedText Method:}{Placeholder (float)f}{Text Arg1:}{Placeholder (int)i1}{Text OtherArg:}{Placeholder (id)obj} -// CHECK-CC7: ObjCInstanceMethodDecl:{TypedText Method:}{Placeholder (float)f}{Text SomeArg:}{Placeholder (int)i1}{Text OtherArg:}{Placeholder (id)obj} -// CHECK-CC7: ObjCInstanceMethodDecl:{TypedText OtherMethod:}{Placeholder (float)f}{Text Arg1:}{Placeholder (int)i1}{Text Arg2:}{Placeholder (int)i2} +// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method} +// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int)i} +// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)f}{Text Arg1:}{Placeholder (int)i1}{Text Arg2:}{Placeholder (int)i2} +// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)f}{Text Arg1:}{Placeholder (int)i1}{Text OtherArg:}{Placeholder (id)obj} +// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)f}{Text SomeArg:}{Placeholder (int)i1}{Text OtherArg:}{Placeholder (id)obj} +// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText OtherMethod:}{Placeholder (float)f}{Text Arg1:}{Placeholder (int)i1}{Text Arg2:}{Placeholder (int)i2} // RUN: c-index-test -code-completion-at=%s:95:17 %s | FileCheck -check-prefix=CHECK-CC8 %s -// CHECK-CC8: ObjCInstanceMethodDecl:{Informative Method:}{TypedText } -// CHECK-CC8: ObjCInstanceMethodDecl:{Informative Method:}{TypedText Arg1:}{Placeholder (int)i1}{Text Arg2:}{Placeholder (int)i2} -// CHECK-CC8: ObjCInstanceMethodDecl:{Informative Method:}{TypedText Arg1:}{Placeholder (int)i1}{Text OtherArg:}{Placeholder (id)obj} -// CHECK-CC8: ObjCInstanceMethodDecl:{Informative Method:}{TypedText SomeArg:}{Placeholder (int)i1}{Text OtherArg:}{Placeholder (id)obj} +// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText } +// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)i1}{Text Arg2:}{Placeholder (int)i2} +// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)i1}{Text OtherArg:}{Placeholder (id)obj} +// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText SomeArg:}{Placeholder (int)i1}{Text OtherArg:}{Placeholder (id)obj} // RUN: c-index-test -code-completion-at=%s:95:24 %s | FileCheck -check-prefix=CHECK-CC9 %s -// CHECK-CC9: ObjCInstanceMethodDecl:{Informative Method:}{Informative Arg1:}{TypedText Arg2:}{Placeholder (int)i2} -// CHECK-CC9: ObjCInstanceMethodDecl:{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)obj} +// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText Arg2:}{Placeholder (int)i2} +// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)obj} // RUN: c-index-test -code-completion-at=%s:61:11 %s | FileCheck -check-prefix=CHECK-CCA %s -// CHECK-CCA: {TypedText _cmd} -// CHECK-CCA: {TypedText self} +// CHECK-CCA: {ResultType SEL}{TypedText _cmd} +// CHECK-CCA: {ResultType Class}{TypedText self} // CHECK-CCA: TypedefDecl:{TypedText Class} // CHECK-CCA: ObjCInterfaceDecl:{TypedText Foo} -// CHECK-CCA: FunctionDecl:{TypedText func}{LeftParen (}{RightParen )} +// CHECK-CCA: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )} // CHECK-CCA: TypedefDecl:{TypedText id} // CHECK-CCA: ObjCInterfaceDecl:{TypedText MyClass} // CHECK-CCA: ObjCInterfaceDecl:{TypedText MySubClass} diff --git a/test/Index/complete-properties.m b/test/Index/complete-properties.m index a99b1d1413..80e10e7822 100644 --- a/test/Index/complete-properties.m +++ b/test/Index/complete-properties.m @@ -22,19 +22,19 @@ @end // RUN: c-index-test -code-completion-at=%s:20:13 %s | FileCheck -check-prefix=CHECK-CC1 %s -// CHECK-CC1: ObjCPropertyDecl:{TypedText Prop0} -// CHECK-CC1: ObjCPropertyDecl:{TypedText Prop1} -// CHECK-CC1: ObjCPropertyDecl:{TypedText Prop2} -// CHECK-CC1: ObjCPropertyDecl:{TypedText Prop3} -// CHECK-CC1: ObjCPropertyDecl:{TypedText Prop4} +// CHECK-CC1: ObjCPropertyDecl:{ResultType int}{TypedText Prop0} +// CHECK-CC1: ObjCPropertyDecl:{ResultType int}{TypedText Prop1} +// CHECK-CC1: ObjCPropertyDecl:{ResultType float}{TypedText Prop2} +// CHECK-CC1: ObjCPropertyDecl:{ResultType id}{TypedText Prop3} +// CHECK-CC1: ObjCPropertyDecl:{ResultType id}{TypedText Prop4} // RUN: c-index-test -code-completion-at=%s:20:20 %s | FileCheck -check-prefix=CHECK-CC2 %s -// CHECK-CC2: ObjCPropertyDecl:{TypedText Prop0} -// CHECK-CC2: ObjCPropertyDecl:{TypedText Prop1} -// CHECK-CC2-NEXT: ObjCPropertyDecl:{TypedText Prop3} -// CHECK-CC2: ObjCPropertyDecl:{TypedText Prop4} +// CHECK-CC2: ObjCPropertyDecl:{ResultType int}{TypedText Prop0} +// CHECK-CC2: ObjCPropertyDecl:{ResultType int}{TypedText Prop1} +// CHECK-CC2-NEXT: ObjCPropertyDecl:{ResultType id}{TypedText Prop3} +// CHECK-CC2: ObjCPropertyDecl:{ResultType id}{TypedText Prop4} // RUN: c-index-test -code-completion-at=%s:20:35 %s | FileCheck -check-prefix=CHECK-CC3 %s -// CHECK-CC3: ObjCIvarDecl:{TypedText RandomIVar} -// CHECK-CC3: ObjCIvarDecl:{TypedText StoredProp3} +// CHECK-CC3: ObjCIvarDecl:{ResultType int}{TypedText RandomIVar} +// CHECK-CC3: ObjCIvarDecl:{ResultType id}{TypedText StoredProp3} // RUN: c-index-test -code-completion-at=%s:21:10 %s | FileCheck -check-prefix=CHECK-CC4 %s -// CHECK-CC4: ObjCPropertyDecl:{TypedText Prop0} -// CHECK-CC4-NEXT: ObjCPropertyDecl:{TypedText Prop4} +// CHECK-CC4: ObjCPropertyDecl:{ResultType int}{TypedText Prop0} +// CHECK-CC4-NEXT: ObjCPropertyDecl:{ResultType id}{TypedText Prop4} diff --git a/test/Index/complete-property-getset.m b/test/Index/complete-property-getset.m index a2a80533a3..f4424ced08 100644 --- a/test/Index/complete-property-getset.m +++ b/test/Index/complete-property-getset.m @@ -20,22 +20,22 @@ @end // RUN: c-index-test -code-completion-at=%s:13:21 %s | FileCheck -check-prefix=CHECK-CC1 %s -// CHECK-CC1: ObjCInstanceMethodDecl:{TypedText getter1} +// CHECK-CC1: ObjCInstanceMethodDecl:{ResultType int}{TypedText getter1} // CHECK-CC1-NOT: getter2 -// CHECK-CC1: ObjCInstanceMethodDecl:{TypedText getter3} +// CHECK-CC1: ObjCInstanceMethodDecl:{ResultType int}{TypedText getter3} // RUN: c-index-test -code-completion-at=%s:13:39 %s | FileCheck -check-prefix=CHECK-CC2 %s -// CHECK-CC2: ObjCInstanceMethodDecl:{TypedText getter2_not:} -// CHECK-CC2: ObjCInstanceMethodDecl:{TypedText setter1:} +// CHECK-CC2: ObjCInstanceMethodDecl:{ResultType int}{TypedText getter2_not:} +// CHECK-CC2: ObjCInstanceMethodDecl:{ResultType void}{TypedText setter1:} // CHECK-CC2-NOT: setter2 -// CHECK-CC2: ObjCInstanceMethodDecl:{TypedText setter3:} +// CHECK-CC2: ObjCInstanceMethodDecl:{ResultType void}{TypedText setter3:} // RUN: c-index-test -code-completion-at=%s:19:21 %s | FileCheck -check-prefix=CHECK-CC3 %s -// CHECK-CC3: ObjCInstanceMethodDecl:{TypedText getter1} +// CHECK-CC3: ObjCInstanceMethodDecl:{ResultType int}{TypedText getter1} // CHECK-CC3-NOT: getter2 -// CHECK-CC3: ObjCInstanceMethodDecl:{TypedText getter3} -// CHECK-CC3: ObjCInstanceMethodDecl:{TypedText getter4} +// CHECK-CC3: ObjCInstanceMethodDecl:{ResultType int}{TypedText getter3} +// CHECK-CC3: ObjCInstanceMethodDecl:{ResultType int}{TypedText getter4} // RUN: c-index-test -code-completion-at=%s:19:39 %s | FileCheck -check-prefix=CHECK-CC4 %s -// CHECK-CC4: ObjCInstanceMethodDecl:{TypedText getter2_not:}{Informative (int)x} -// CHECK-CC4: ObjCInstanceMethodDecl:{TypedText setter1:}{Informative (int)x} +// CHECK-CC4: ObjCInstanceMethodDecl:{ResultType int}{TypedText getter2_not:}{Informative (int)x} +// CHECK-CC4: ObjCInstanceMethodDecl:{ResultType void}{TypedText setter1:}{Informative (int)x} // CHECK-CC4-NOT: setter2 -// CHECK-CC4: ObjCInstanceMethodDecl:{TypedText setter3:}{Informative (int)y} -// CHECK-CC4: ObjCInstanceMethodDecl:{TypedText setter4:}{Informative (int)x} +// CHECK-CC4: ObjCInstanceMethodDecl:{ResultType void}{TypedText setter3:}{Informative (int)y} +// CHECK-CC4: ObjCInstanceMethodDecl:{ResultType void}{TypedText setter4:}{Informative (int)x} diff --git a/test/Index/remap-complete.c b/test/Index/remap-complete.c index cfafd3051d..9b7de0699d 100644 --- a/test/Index/remap-complete.c +++ b/test/Index/remap-complete.c @@ -1,5 +1,5 @@ // RUN: c-index-test -code-completion-at=%s:1:12 -remap-file="%s;%S/Inputs/remap-complete-to.c" %s | FileCheck %s // XFAIL: win32 -// CHECK: FunctionDecl:{TypedText f0}{LeftParen (}{RightParen )} +// CHECK: FunctionDecl:{ResultType void}{TypedText f0}{LeftParen (}{RightParen )} void f() { } diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index c4a616689a..9b2355dc0a 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -1114,6 +1114,8 @@ clang_getCompletionChunkKind(CXCompletionString completion_string, return CXCompletionChunk_Placeholder; case CodeCompletionString::CK_Informative: return CXCompletionChunk_Informative; + case CodeCompletionString::CK_ResultType: + return CXCompletionChunk_ResultType; case CodeCompletionString::CK_CurrentParameter: return CXCompletionChunk_CurrentParameter; case CodeCompletionString::CK_LeftParen: @@ -1161,6 +1163,7 @@ const char *clang_getCompletionChunkText(CXCompletionString completion_string, case CodeCompletionString::CK_LeftAngle: case CodeCompletionString::CK_RightAngle: case CodeCompletionString::CK_Comma: + case CodeCompletionString::CK_ResultType: return (*CCStr)[chunk_number].Text; case CodeCompletionString::CK_Optional: @@ -1194,6 +1197,7 @@ clang_getCompletionChunkCompletionString(CXCompletionString completion_string, case CodeCompletionString::CK_LeftAngle: case CodeCompletionString::CK_RightAngle: case CodeCompletionString::CK_Comma: + case CodeCompletionString::CK_ResultType: return 0; case CodeCompletionString::CK_Optional: diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index f3458adda8..33013f3b66 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -355,6 +355,7 @@ clang_getCompletionChunkKindSpelling(enum CXCompletionChunkKind Kind) { case CXCompletionChunk_LeftAngle: return "LeftAngle"; case CXCompletionChunk_RightAngle: return "RightAngle"; case CXCompletionChunk_Comma: return "Comma"; + case CXCompletionChunk_ResultType: return "ResultType"; } return "Unknown";