diff options
Diffstat (limited to 'include/clang/Sema/CodeCompleteConsumer.h')
-rw-r--r-- | include/clang/Sema/CodeCompleteConsumer.h | 142 |
1 files changed, 77 insertions, 65 deletions
diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index fe9bed5..d43aaaf 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -15,6 +15,7 @@ #include "clang/AST/Type.h" #include "clang/AST/CanonicalType.h" +#include "clang/Sema/CodeCompleteOptions.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Allocator.h" @@ -237,7 +238,7 @@ public: /// This context usually implies that no completions should be added, /// unless they come from an appropriate natural-language dictionary. CCC_NaturalLanguage, - /// \brief Code completion for a selector, as in an @selector expression. + /// \brief Code completion for a selector, as in an \@selector expression. CCC_SelectorName, /// \brief Code completion within a type-qualifier list. CCC_TypeQualifiers, @@ -379,7 +380,7 @@ public: CK_Equal, /// \brief Horizontal whitespace (' '). CK_HorizontalSpace, - /// \brief Verticle whitespace ('\n' or '\r\n', depending on the + /// \brief Vertical whitespace ('\\n' or '\\r\\n', depending on the /// platform). CK_VerticalSpace }; @@ -444,6 +445,10 @@ private: /// \brief The name of the parent context. StringRef ParentName; + + /// \brief A brief documentation comment attached to the declaration of + /// entity being completed by this result. + const char *BriefComment; CodeCompletionString(const CodeCompletionString &); // DO NOT IMPLEMENT CodeCompletionString &operator=(const CodeCompletionString &); // DITTO @@ -451,7 +456,8 @@ private: CodeCompletionString(const Chunk *Chunks, unsigned NumChunks, unsigned Priority, CXAvailabilityKind Availability, const char **Annotations, unsigned NumAnnotations, - CXCursorKind ParentKind, StringRef ParentName); + CXCursorKind ParentKind, StringRef ParentName, + const char *BriefComment); ~CodeCompletionString() { } friend class CodeCompletionBuilder; @@ -493,6 +499,10 @@ public: StringRef getParentContextName() const { return ParentName; } + + const char *getBriefComment() const { + return BriefComment; + } /// \brief Retrieve a string representation of the code completion string, /// which is mainly useful for debugging. @@ -569,6 +579,7 @@ private: CXAvailabilityKind Availability; CXCursorKind ParentKind; StringRef ParentName; + const char *BriefComment; /// \brief The chunks stored in this string. SmallVector<Chunk, 4> Chunks; @@ -580,14 +591,14 @@ public: CodeCompletionTUInfo &CCTUInfo) : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(0), Availability(CXAvailability_Available), - ParentKind(CXCursor_NotImplemented) { } + ParentKind(CXCursor_NotImplemented), BriefComment(NULL) { } CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, unsigned Priority, CXAvailabilityKind Availability) : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority), Availability(Availability), - ParentKind(CXCursor_NotImplemented) { } + ParentKind(CXCursor_NotImplemented), BriefComment(NULL) { } /// \brief Retrieve the allocator into which the code completion /// strings should be allocated. @@ -628,6 +639,8 @@ public: /// \brief Add the parent context information to this code completion. void addParentContext(DeclContext *DC); + + void addBriefComment(StringRef Comment); CXCursorKind getParentKind() const { return ParentKind; } StringRef getParentName() const { return ParentName; } @@ -638,15 +651,12 @@ class CodeCompletionResult { public: /// \brief Describes the kind of result generated. enum ResultKind { - RK_Declaration = 0, //< Refers to a declaration - RK_Keyword, //< Refers to a keyword or symbol. - RK_Macro, //< Refers to a macro - RK_Pattern //< Refers to a precomputed pattern. + RK_Declaration = 0, ///< Refers to a declaration + RK_Keyword, ///< Refers to a keyword or symbol. + RK_Macro, ///< Refers to a macro + RK_Pattern ///< Refers to a precomputed pattern. }; - /// \brief The kind of result stored here. - ResultKind Kind; - /// \brief When Kind == RK_Declaration or RK_Pattern, the declaration we are /// referring to. In the latter case, the declaration might be NULL. NamedDecl *Declaration; @@ -667,16 +677,19 @@ public: /// \brief The priority of this particular code-completion result. unsigned Priority; + /// \brief Specifies which parameter (of a function, Objective-C method, + /// macro, etc.) we should start with when formatting the result. + unsigned StartParameter; + + /// \brief The kind of result stored here. + ResultKind Kind; + /// \brief The cursor kind that describes this result. CXCursorKind CursorKind; /// \brief The availability of this result. CXAvailabilityKind Availability; - /// \brief Specifies which parameter (of a function, Objective-C method, - /// macro, etc.) we should start with when formatting the result. - unsigned StartParameter; - /// \brief Whether this result is hidden by another name. bool Hidden : 1; @@ -705,10 +718,10 @@ public: NestedNameSpecifier *Qualifier = 0, bool QualifierIsInformative = false, bool Accessible = true) - : Kind(RK_Declaration), Declaration(Declaration), - Priority(getPriorityFromDecl(Declaration)), - Availability(CXAvailability_Available), StartParameter(0), - Hidden(false), QualifierIsInformative(QualifierIsInformative), + : Declaration(Declaration), Priority(getPriorityFromDecl(Declaration)), + StartParameter(0), Kind(RK_Declaration), + Availability(CXAvailability_Available), Hidden(false), + QualifierIsInformative(QualifierIsInformative), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(Qualifier) { computeCursorKindAndAvailability(Accessible); @@ -716,22 +729,22 @@ public: /// \brief Build a result that refers to a keyword or symbol. CodeCompletionResult(const char *Keyword, unsigned Priority = CCP_Keyword) - : Kind(RK_Keyword), Declaration(0), Keyword(Keyword), Priority(Priority), - Availability(CXAvailability_Available), - StartParameter(0), Hidden(false), QualifierIsInformative(0), - StartsNestedNameSpecifier(false), AllParametersAreInformative(false), - DeclaringEntity(false), Qualifier(0) { - computeCursorKindAndAvailability(); + : Declaration(0), Keyword(Keyword), Priority(Priority), StartParameter(0), + Kind(RK_Keyword), CursorKind(CXCursor_NotImplemented), + Availability(CXAvailability_Available), Hidden(false), + QualifierIsInformative(0), StartsNestedNameSpecifier(false), + AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(0) + { } /// \brief Build a result that refers to a macro. CodeCompletionResult(IdentifierInfo *Macro, unsigned Priority = CCP_Macro) - : Kind(RK_Macro), Declaration(0), Macro(Macro), Priority(Priority), - Availability(CXAvailability_Available), StartParameter(0), - Hidden(false), QualifierIsInformative(0), - StartsNestedNameSpecifier(false), AllParametersAreInformative(false), - DeclaringEntity(false), Qualifier(0) { - computeCursorKindAndAvailability(); + : Declaration(0), Macro(Macro), Priority(Priority), StartParameter(0), + Kind(RK_Macro), CursorKind(CXCursor_MacroDefinition), + Availability(CXAvailability_Available), Hidden(false), + QualifierIsInformative(0), StartsNestedNameSpecifier(false), + AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(0) + { } /// \brief Build a result that refers to a pattern. @@ -740,8 +753,8 @@ public: CXCursorKind CursorKind = CXCursor_NotImplemented, CXAvailabilityKind Availability = CXAvailability_Available, NamedDecl *D = 0) - : Kind(RK_Pattern), Declaration(D), Pattern(Pattern), Priority(Priority), - CursorKind(CursorKind), Availability(Availability), StartParameter(0), + : Declaration(D), Pattern(Pattern), Priority(Priority), StartParameter(0), + Kind(RK_Pattern), CursorKind(CursorKind), Availability(Availability), Hidden(false), QualifierIsInformative(0), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(0) @@ -752,11 +765,10 @@ public: /// declaration. CodeCompletionResult(CodeCompletionString *Pattern, NamedDecl *D, unsigned Priority) - : Kind(RK_Pattern), Declaration(D), Pattern(Pattern), Priority(Priority), - Availability(CXAvailability_Available), StartParameter(0), - Hidden(false), QualifierIsInformative(false), - StartsNestedNameSpecifier(false), AllParametersAreInformative(false), - DeclaringEntity(false), Qualifier(0) { + : Declaration(D), Pattern(Pattern), Priority(Priority), StartParameter(0), + Kind(RK_Pattern), Availability(CXAvailability_Available), Hidden(false), + QualifierIsInformative(false), StartsNestedNameSpecifier(false), + AllParametersAreInformative(false), DeclaringEntity(false), Qualifier(0) { computeCursorKindAndAvailability(); } @@ -781,11 +793,13 @@ public: /// string itself. CodeCompletionString *CreateCodeCompletionString(Sema &S, CodeCompletionAllocator &Allocator, - CodeCompletionTUInfo &CCTUInfo); + CodeCompletionTUInfo &CCTUInfo, + bool IncludeBriefComments); CodeCompletionString *CreateCodeCompletionString(ASTContext &Ctx, Preprocessor &PP, CodeCompletionAllocator &Allocator, - CodeCompletionTUInfo &CCTUInfo); + CodeCompletionTUInfo &CCTUInfo, + bool IncludeBriefComments); /// \brief Determine a base priority for the given declaration. static unsigned getPriorityFromDecl(NamedDecl *ND); @@ -819,16 +833,7 @@ raw_ostream &operator<<(raw_ostream &OS, /// information. class CodeCompleteConsumer { protected: - /// \brief Whether to include macros in the code-completion results. - bool IncludeMacros; - - /// \brief Whether to include code patterns (such as for loops) within - /// the completion results. - bool IncludeCodePatterns; - - /// \brief Whether to include global (top-level) declarations and names in - /// the completion results. - bool IncludeGlobals; + const CodeCompleteOptions CodeCompleteOpts; /// \brief Whether the output format for the code-completion consumer is /// binary. @@ -901,22 +906,31 @@ public: CodeCompletionTUInfo &CCTUInfo) const; }; - CodeCompleteConsumer() : IncludeMacros(false), IncludeCodePatterns(false), - IncludeGlobals(true), OutputIsBinary(false) { } - - CodeCompleteConsumer(bool IncludeMacros, bool IncludeCodePatterns, - bool IncludeGlobals, bool OutputIsBinary) - : IncludeMacros(IncludeMacros), IncludeCodePatterns(IncludeCodePatterns), - IncludeGlobals(IncludeGlobals), OutputIsBinary(OutputIsBinary) { } + CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, + bool OutputIsBinary) + : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary) + { } /// \brief Whether the code-completion consumer wants to see macros. - bool includeMacros() const { return IncludeMacros; } + bool includeMacros() const { + return CodeCompleteOpts.IncludeMacros; + } /// \brief Whether the code-completion consumer wants to see code patterns. - bool includeCodePatterns() const { return IncludeCodePatterns; } + bool includeCodePatterns() const { + return CodeCompleteOpts.IncludeCodePatterns; + } /// \brief Whether to include global (top-level) declaration results. - bool includeGlobals() const { return IncludeGlobals; } + bool includeGlobals() const { + return CodeCompleteOpts.IncludeGlobals; + } + + /// \brief Whether to include brief documentation comments within the set of + /// code completions returned. + bool includeBriefComments() const { + return CodeCompleteOpts.IncludeBriefComments; + } /// \brief Determine whether the output of this consumer is binary. bool isOutputBinary() const { return OutputIsBinary; } @@ -963,11 +977,9 @@ class PrintingCodeCompleteConsumer : public CodeCompleteConsumer { public: /// \brief Create a new printing code-completion consumer that prints its /// results to the given raw output stream. - PrintingCodeCompleteConsumer(bool IncludeMacros, bool IncludeCodePatterns, - bool IncludeGlobals, + PrintingCodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, raw_ostream &OS) - : CodeCompleteConsumer(IncludeMacros, IncludeCodePatterns, IncludeGlobals, - false), OS(OS), + : CodeCompleteConsumer(CodeCompleteOpts, false), OS(OS), CCTUInfo(new GlobalCodeCompletionAllocator) {} /// \brief Prints the finalized code-completion results. |