15
15
16
16
#include " clang/AST/Type.h"
17
17
#include " clang/AST/CanonicalType.h"
18
+ #include " clang/Sema/CodeCompleteOptions.h"
18
19
#include " llvm/ADT/SmallVector.h"
19
20
#include " llvm/ADT/StringRef.h"
20
21
#include " llvm/Support/Allocator.h"
@@ -444,14 +445,19 @@ class CodeCompletionString {
444
445
445
446
// / \brief The name of the parent context.
446
447
StringRef ParentName;
448
+
449
+ // / \brief A brief documentation comment attached to the declaration of
450
+ // / entity being completed by this result.
451
+ const char *BriefComment;
447
452
448
453
CodeCompletionString (const CodeCompletionString &); // DO NOT IMPLEMENT
449
454
CodeCompletionString &operator =(const CodeCompletionString &); // DITTO
450
455
451
456
CodeCompletionString (const Chunk *Chunks, unsigned NumChunks,
452
457
unsigned Priority, CXAvailabilityKind Availability,
453
458
const char **Annotations, unsigned NumAnnotations,
454
- CXCursorKind ParentKind, StringRef ParentName);
459
+ CXCursorKind ParentKind, StringRef ParentName,
460
+ const char *BriefComment);
455
461
~CodeCompletionString () { }
456
462
457
463
friend class CodeCompletionBuilder ;
@@ -493,6 +499,10 @@ class CodeCompletionString {
493
499
StringRef getParentContextName () const {
494
500
return ParentName;
495
501
}
502
+
503
+ const char *getBriefComment () const {
504
+ return BriefComment;
505
+ }
496
506
497
507
// / \brief Retrieve a string representation of the code completion string,
498
508
// / which is mainly useful for debugging.
@@ -569,6 +579,7 @@ class CodeCompletionBuilder {
569
579
CXAvailabilityKind Availability;
570
580
CXCursorKind ParentKind;
571
581
StringRef ParentName;
582
+ const char *BriefComment;
572
583
573
584
// / \brief The chunks stored in this string.
574
585
SmallVector<Chunk, 4 > Chunks;
@@ -580,14 +591,14 @@ class CodeCompletionBuilder {
580
591
CodeCompletionTUInfo &CCTUInfo)
581
592
: Allocator(Allocator), CCTUInfo(CCTUInfo),
582
593
Priority (0 ), Availability(CXAvailability_Available),
583
- ParentKind(CXCursor_NotImplemented) { }
594
+ ParentKind(CXCursor_NotImplemented), BriefComment( NULL ) { }
584
595
585
596
CodeCompletionBuilder (CodeCompletionAllocator &Allocator,
586
597
CodeCompletionTUInfo &CCTUInfo,
587
598
unsigned Priority, CXAvailabilityKind Availability)
588
599
: Allocator(Allocator), CCTUInfo(CCTUInfo),
589
600
Priority(Priority), Availability(Availability),
590
- ParentKind(CXCursor_NotImplemented) { }
601
+ ParentKind(CXCursor_NotImplemented), BriefComment( NULL ) { }
591
602
592
603
// / \brief Retrieve the allocator into which the code completion
593
604
// / strings should be allocated.
@@ -628,6 +639,8 @@ class CodeCompletionBuilder {
628
639
629
640
// / \brief Add the parent context information to this code completion.
630
641
void addParentContext (DeclContext *DC);
642
+
643
+ void addBriefComment (StringRef Comment);
631
644
632
645
CXCursorKind getParentKind () const { return ParentKind; }
633
646
StringRef getParentName () const { return ParentName; }
@@ -780,11 +793,13 @@ class CodeCompletionResult {
780
793
// / string itself.
781
794
CodeCompletionString *CreateCodeCompletionString (Sema &S,
782
795
CodeCompletionAllocator &Allocator,
783
- CodeCompletionTUInfo &CCTUInfo);
796
+ CodeCompletionTUInfo &CCTUInfo,
797
+ bool IncludeBriefComments);
784
798
CodeCompletionString *CreateCodeCompletionString (ASTContext &Ctx,
785
799
Preprocessor &PP,
786
800
CodeCompletionAllocator &Allocator,
787
- CodeCompletionTUInfo &CCTUInfo);
801
+ CodeCompletionTUInfo &CCTUInfo,
802
+ bool IncludeBriefComments);
788
803
789
804
// / \brief Determine a base priority for the given declaration.
790
805
static unsigned getPriorityFromDecl (NamedDecl *ND);
@@ -818,16 +833,7 @@ raw_ostream &operator<<(raw_ostream &OS,
818
833
// / information.
819
834
class CodeCompleteConsumer {
820
835
protected:
821
- // / \brief Whether to include macros in the code-completion results.
822
- bool IncludeMacros;
823
-
824
- // / \brief Whether to include code patterns (such as for loops) within
825
- // / the completion results.
826
- bool IncludeCodePatterns;
827
-
828
- // / \brief Whether to include global (top-level) declarations and names in
829
- // / the completion results.
830
- bool IncludeGlobals;
836
+ const CodeCompleteOptions CodeCompleteOpts;
831
837
832
838
// / \brief Whether the output format for the code-completion consumer is
833
839
// / binary.
@@ -900,22 +906,31 @@ class CodeCompleteConsumer {
900
906
CodeCompletionTUInfo &CCTUInfo) const ;
901
907
};
902
908
903
- CodeCompleteConsumer () : IncludeMacros(false ), IncludeCodePatterns(false ),
904
- IncludeGlobals (true ), OutputIsBinary(false ) { }
905
-
906
- CodeCompleteConsumer (bool IncludeMacros, bool IncludeCodePatterns,
907
- bool IncludeGlobals, bool OutputIsBinary)
908
- : IncludeMacros(IncludeMacros), IncludeCodePatterns(IncludeCodePatterns),
909
- IncludeGlobals(IncludeGlobals), OutputIsBinary(OutputIsBinary) { }
909
+ CodeCompleteConsumer (const CodeCompleteOptions &CodeCompleteOpts,
910
+ bool OutputIsBinary)
911
+ : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary)
912
+ { }
910
913
911
914
// / \brief Whether the code-completion consumer wants to see macros.
912
- bool includeMacros () const { return IncludeMacros; }
915
+ bool includeMacros () const {
916
+ return CodeCompleteOpts.IncludeMacros ;
917
+ }
913
918
914
919
// / \brief Whether the code-completion consumer wants to see code patterns.
915
- bool includeCodePatterns () const { return IncludeCodePatterns; }
920
+ bool includeCodePatterns () const {
921
+ return CodeCompleteOpts.IncludeCodePatterns ;
922
+ }
916
923
917
924
// / \brief Whether to include global (top-level) declaration results.
918
- bool includeGlobals () const { return IncludeGlobals; }
925
+ bool includeGlobals () const {
926
+ return CodeCompleteOpts.IncludeGlobals ;
927
+ }
928
+
929
+ // / \brief Whether to include brief documentation comments within the set of
930
+ // / code completions returned.
931
+ bool includeBriefComments () const {
932
+ return CodeCompleteOpts.IncludeBriefComments ;
933
+ }
919
934
920
935
// / \brief Determine whether the output of this consumer is binary.
921
936
bool isOutputBinary () const { return OutputIsBinary; }
@@ -962,11 +977,9 @@ class PrintingCodeCompleteConsumer : public CodeCompleteConsumer {
962
977
public:
963
978
// / \brief Create a new printing code-completion consumer that prints its
964
979
// / results to the given raw output stream.
965
- PrintingCodeCompleteConsumer (bool IncludeMacros, bool IncludeCodePatterns,
966
- bool IncludeGlobals,
980
+ PrintingCodeCompleteConsumer (const CodeCompleteOptions &CodeCompleteOpts,
967
981
raw_ostream &OS)
968
- : CodeCompleteConsumer(IncludeMacros, IncludeCodePatterns, IncludeGlobals,
969
- false ), OS(OS),
982
+ : CodeCompleteConsumer(CodeCompleteOpts, false ), OS(OS),
970
983
CCTUInfo (new GlobalCodeCompletionAllocator) {}
971
984
972
985
// / \brief Prints the finalized code-completion results.
0 commit comments