clang  8.0.0svn
CodeCompleteConsumer.h
Go to the documentation of this file.
1 //===- CodeCompleteConsumer.h - Code Completion Interface -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the CodeCompleteConsumer class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
15 #define LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
16 
17 #include "clang-c/Index.h"
18 #include "clang/AST/Type.h"
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Lex/MacroInfo.h"
22 #include "clang/Sema/DeclSpec.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/None.h"
26 #include "llvm/ADT/Optional.h"
27 #include "llvm/ADT/SmallPtrSet.h"
28 #include "llvm/ADT/SmallVector.h"
29 #include "llvm/ADT/StringRef.h"
30 #include "llvm/Support/Allocator.h"
31 #include "llvm/Support/type_traits.h"
32 #include <cassert>
33 #include <memory>
34 #include <string>
35 #include <utility>
36 
37 namespace clang {
38 
39 class ASTContext;
40 class Decl;
41 class DeclContext;
42 class FunctionDecl;
43 class FunctionTemplateDecl;
44 class IdentifierInfo;
45 class LangOptions;
46 class NamedDecl;
47 class NestedNameSpecifier;
48 class Preprocessor;
49 class RawComment;
50 class Sema;
51 class UsingShadowDecl;
52 
53 /// Default priority values for code-completion results based
54 /// on their kind.
55 enum {
56  /// Priority for the next initialization in a constructor initializer
57  /// list.
59 
60  /// Priority for an enumeration constant inside a switch whose
61  /// condition is of the enumeration type.
63 
64  /// Priority for a send-to-super completion.
66 
67  /// Priority for a declaration that is in the local scope.
69 
70  /// Priority for a member declaration found from the current
71  /// method or member function.
73 
74  /// Priority for a language keyword (that isn't any of the other
75  /// categories).
77 
78  /// Priority for a code pattern.
80 
81  /// Priority for a non-type declaration.
83 
84  /// Priority for a type.
86 
87  /// Priority for a constant value (e.g., enumerator).
89 
90  /// Priority for a preprocessor macro.
91  CCP_Macro = 70,
92 
93  /// Priority for a nested-name-specifier.
95 
96  /// Priority for a result that isn't likely to be what the user wants,
97  /// but is included for completeness.
99 
100  /// Priority for the Objective-C "_cmd" implicit parameter.
102 };
103 
104 /// Priority value deltas that are added to code-completion results
105 /// based on the context of the result.
106 enum {
107  /// The result is in a base class.
109 
110  /// The result is a C++ non-static member function whose qualifiers
111  /// exactly match the object type on which the member function can be called.
113 
114  /// The selector of the given message exactly matches the selector
115  /// of the current method, which might imply that some kind of delegation
116  /// is occurring.
118 
119  /// Adjustment to the "bool" type in Objective-C, where the typedef
120  /// "BOOL" is preferred.
122 
123  /// Adjustment for KVC code pattern priorities when it doesn't look
124  /// like the
126 
127  /// An Objective-C method being used as a property.
129 
130  /// An Objective-C block property completed as a setter with a
131  /// block placeholder.
133 };
134 
135 /// Priority value factors by which we will divide or multiply the
136 /// priority of a code-completion result.
137 enum {
138  /// Divide by this factor when a code-completion result's type exactly
139  /// matches the type we expect.
141 
142  /// Divide by this factor when a code-completion result's type is
143  /// similar to the type we expect (e.g., both arithmetic types, both
144  /// Objective-C object pointer types).
146 };
147 
148 /// A simplified classification of types used when determining
149 /// "similar" types for code completion.
160 };
161 
162 /// Determine the simplified type class of the given canonical type.
164 
165 /// Determine the type that this declaration will have if it is used
166 /// as a type or in an expression.
168 
169 /// Determine the priority to be given to a macro code completion result
170 /// with the given name.
171 ///
172 /// \param MacroName The name of the macro.
173 ///
174 /// \param LangOpts Options describing the current language dialect.
175 ///
176 /// \param PreferredTypeIsPointer Whether the preferred type for the context
177 /// of this macro is a pointer type.
178 unsigned getMacroUsagePriority(StringRef MacroName,
179  const LangOptions &LangOpts,
180  bool PreferredTypeIsPointer = false);
181 
182 /// Determine the libclang cursor kind associated with the given
183 /// declaration.
185 
186 /// The context in which code completion occurred, so that the
187 /// code-completion consumer can process the results accordingly.
189 public:
190  enum Kind {
191  /// An unspecified code-completion context.
193 
194  /// An unspecified code-completion context where we should also add
195  /// macro completions.
197 
198  /// Code completion occurred within a "top-level" completion context,
199  /// e.g., at namespace or global scope.
201 
202  /// Code completion occurred within an Objective-C interface,
203  /// protocol, or category interface.
205 
206  /// Code completion occurred within an Objective-C implementation
207  /// or category implementation.
209 
210  /// Code completion occurred within the instance variable list of
211  /// an Objective-C interface, implementation, or category implementation.
213 
214  /// Code completion occurred within a class, struct, or union.
216 
217  /// Code completion occurred where a statement (or declaration) is
218  /// expected in a function, method, or block.
220 
221  /// Code completion occurred where an expression is expected.
223 
224  /// Code completion occurred where an Objective-C message receiver
225  /// is expected.
227 
228  /// Code completion occurred on the right-hand side of a member
229  /// access expression using the dot operator.
230  ///
231  /// The results of this completion are the members of the type being
232  /// accessed. The type itself is available via
233  /// \c CodeCompletionContext::getType().
235 
236  /// Code completion occurred on the right-hand side of a member
237  /// access expression using the arrow operator.
238  ///
239  /// The results of this completion are the members of the type being
240  /// accessed. The type itself is available via
241  /// \c CodeCompletionContext::getType().
243 
244  /// Code completion occurred on the right-hand side of an Objective-C
245  /// property access expression.
246  ///
247  /// The results of this completion are the members of the type being
248  /// accessed. The type itself is available via
249  /// \c CodeCompletionContext::getType().
251 
252  /// Code completion occurred after the "enum" keyword, to indicate
253  /// an enumeration name.
255 
256  /// Code completion occurred after the "union" keyword, to indicate
257  /// a union name.
259 
260  /// Code completion occurred after the "struct" or "class" keyword,
261  /// to indicate a struct or class name.
263 
264  /// Code completion occurred where a protocol name is expected.
266 
267  /// Code completion occurred where a namespace or namespace alias
268  /// is expected.
270 
271  /// Code completion occurred where a type name is expected.
273 
274  /// Code completion occurred where a new name is expected.
276 
277  /// Code completion occurred where a new name is expected and a
278  /// qualified name is permissible.
280 
281  /// Code completion occurred where an macro is being defined.
283 
284  /// Code completion occurred where a macro name is expected
285  /// (without any arguments, in the case of a function-like macro).
287 
288  /// Code completion occurred within a preprocessor expression.
290 
291  /// Code completion occurred where a preprocessor directive is
292  /// expected.
294 
295  /// Code completion occurred in a context where natural language is
296  /// expected, e.g., a comment or string literal.
297  ///
298  /// This context usually implies that no completions should be added,
299  /// unless they come from an appropriate natural-language dictionary.
301 
302  /// Code completion for a selector, as in an \@selector expression.
304 
305  /// Code completion within a type-qualifier list.
307 
308  /// Code completion in a parenthesized expression, which means that
309  /// we may also have types here in C and Objective-C (as well as in C++).
311 
312  /// Code completion where an Objective-C instance message is
313  /// expected.
315 
316  /// Code completion where an Objective-C class message is expected.
318 
319  /// Code completion where the name of an Objective-C class is
320  /// expected.
322 
323  /// Code completion where an Objective-C category name is expected.
325 
326  /// Code completion inside the filename part of a #include directive.
328 
329  /// An unknown context, in which we are recovering from a parsing
330  /// error and don't know which completions we should give.
332  };
333 
334  using VisitedContextSet = llvm::SmallPtrSet<DeclContext *, 8>;
335 
336 private:
337  Kind CCKind;
338 
339  /// The type that would prefer to see at this point (e.g., the type
340  /// of an initializer or function parameter).
341  QualType PreferredType;
342 
343  /// The type of the base object in a member access expression.
344  QualType BaseType;
345 
346  /// The identifiers for Objective-C selector parts.
347  ArrayRef<IdentifierInfo *> SelIdents;
348 
349  /// The scope specifier that comes before the completion token e.g.
350  /// "a::b::"
351  llvm::Optional<CXXScopeSpec> ScopeSpecifier;
352 
353  /// A set of declaration contexts visited by Sema when doing lookup for
354  /// code completion.
355  VisitedContextSet VisitedContexts;
356 
357 public:
358  /// Construct a new code-completion context of the given kind.
359  CodeCompletionContext(Kind CCKind) : CCKind(CCKind), SelIdents(None) {}
360 
361  /// Construct a new code-completion context of the given kind.
363  ArrayRef<IdentifierInfo *> SelIdents = None)
364  : CCKind(CCKind), SelIdents(SelIdents) {
365  if (CCKind == CCC_DotMemberAccess || CCKind == CCC_ArrowMemberAccess ||
366  CCKind == CCC_ObjCPropertyAccess || CCKind == CCC_ObjCClassMessage ||
367  CCKind == CCC_ObjCInstanceMessage)
368  BaseType = T;
369  else
370  PreferredType = T;
371  }
372 
373  /// Retrieve the kind of code-completion context.
374  Kind getKind() const { return CCKind; }
375 
376  /// Retrieve the type that this expression would prefer to have, e.g.,
377  /// if the expression is a variable initializer or a function argument, the
378  /// type of the corresponding variable or function parameter.
379  QualType getPreferredType() const { return PreferredType; }
380 
381  /// Retrieve the type of the base object in a member-access
382  /// expression.
383  QualType getBaseType() const { return BaseType; }
384 
385  /// Retrieve the Objective-C selector identifiers.
386  ArrayRef<IdentifierInfo *> getSelIdents() const { return SelIdents; }
387 
388  /// Determines whether we want C++ constructors as results within this
389  /// context.
390  bool wantConstructorResults() const;
391 
392  /// Sets the scope specifier that comes before the completion token.
393  /// This is expected to be set in code completions on qualfied specifiers
394  /// (e.g. "a::b::").
396  this->ScopeSpecifier = std::move(SS);
397  }
398 
399  /// Adds a visited context.
401  VisitedContexts.insert(Ctx);
402  }
403 
404  /// Retrieves all visited contexts.
406  return VisitedContexts;
407  }
408 
410  if (ScopeSpecifier)
411  return ScopeSpecifier.getPointer();
412  return llvm::None;
413  }
414 };
415 
416 /// Get string representation of \p Kind, useful for for debugging.
418 
419 /// A "string" used to describe how code completion can
420 /// be performed for an entity.
421 ///
422 /// A code completion string typically shows how a particular entity can be
423 /// used. For example, the code completion string for a function would show
424 /// the syntax to call it, including the parentheses, placeholders for the
425 /// arguments, etc.
427 public:
428  /// The different kinds of "chunks" that can occur within a code
429  /// completion string.
430  enum ChunkKind {
431  /// The piece of text that the user is expected to type to
432  /// match the code-completion string, typically a keyword or the name of a
433  /// declarator or macro.
435 
436  /// A piece of text that should be placed in the buffer, e.g.,
437  /// parentheses or a comma in a function call.
439 
440  /// A code completion string that is entirely optional. For example,
441  /// an optional code completion string that describes the default arguments
442  /// in a function call.
444 
445  /// A string that acts as a placeholder for, e.g., a function
446  /// call argument.
448 
449  /// A piece of text that describes something about the result but
450  /// should not be inserted into the buffer.
452  /// A piece of text that describes the type of an entity or, for
453  /// functions and methods, the return type.
455 
456  /// A piece of text that describes the parameter that corresponds
457  /// to the code-completion location within a function call, message send,
458  /// macro invocation, etc.
460 
461  /// A left parenthesis ('(').
463 
464  /// A right parenthesis (')').
466 
467  /// A left bracket ('[').
469 
470  /// A right bracket (']').
472 
473  /// A left brace ('{').
475 
476  /// A right brace ('}').
478 
479  /// A left angle bracket ('<').
481 
482  /// A right angle bracket ('>').
484 
485  /// A comma separator (',').
487 
488  /// A colon (':').
490 
491  /// A semicolon (';').
493 
494  /// An '=' sign.
496 
497  /// Horizontal whitespace (' ').
499 
500  /// Vertical whitespace ('\\n' or '\\r\\n', depending on the
501  /// platform).
502  CK_VerticalSpace
503  };
504 
505  /// One piece of the code completion string.
506  struct Chunk {
507  /// The kind of data stored in this piece of the code completion
508  /// string.
509  ChunkKind Kind = CK_Text;
510 
511  union {
512  /// The text string associated with a CK_Text, CK_Placeholder,
513  /// CK_Informative, or CK_Comma chunk.
514  /// The string is owned by the chunk and will be deallocated
515  /// (with delete[]) when the chunk is destroyed.
516  const char *Text;
517 
518  /// The code completion string associated with a CK_Optional chunk.
519  /// The optional code completion string is owned by the chunk, and will
520  /// be deallocated (with delete) when the chunk is destroyed.
522  };
523 
524  Chunk() : Text(nullptr) {}
525 
526  explicit Chunk(ChunkKind Kind, const char *Text = "");
527 
528  /// Create a new text chunk.
529  static Chunk CreateText(const char *Text);
530 
531  /// Create a new optional chunk.
532  static Chunk CreateOptional(CodeCompletionString *Optional);
533 
534  /// Create a new placeholder chunk.
535  static Chunk CreatePlaceholder(const char *Placeholder);
536 
537  /// Create a new informative chunk.
538  static Chunk CreateInformative(const char *Informative);
539 
540  /// Create a new result type chunk.
541  static Chunk CreateResultType(const char *ResultType);
542 
543  /// Create a new current-parameter chunk.
544  static Chunk CreateCurrentParameter(const char *CurrentParameter);
545  };
546 
547 private:
548  friend class CodeCompletionBuilder;
549  friend class CodeCompletionResult;
550 
551  /// The number of chunks stored in this string.
552  unsigned NumChunks : 16;
553 
554  /// The number of annotations for this code-completion result.
555  unsigned NumAnnotations : 16;
556 
557  /// The priority of this code-completion string.
558  unsigned Priority : 16;
559 
560  /// The availability of this code-completion result.
561  unsigned Availability : 2;
562 
563  /// The name of the parent context.
564  StringRef ParentName;
565 
566  /// A brief documentation comment attached to the declaration of
567  /// entity being completed by this result.
568  const char *BriefComment;
569 
570  CodeCompletionString(const Chunk *Chunks, unsigned NumChunks,
571  unsigned Priority, CXAvailabilityKind Availability,
572  const char **Annotations, unsigned NumAnnotations,
573  StringRef ParentName,
574  const char *BriefComment);
575  ~CodeCompletionString() = default;
576 
577 public:
578  CodeCompletionString(const CodeCompletionString &) = delete;
579  CodeCompletionString &operator=(const CodeCompletionString &) = delete;
580 
581  using iterator = const Chunk *;
582 
583  iterator begin() const { return reinterpret_cast<const Chunk *>(this + 1); }
584  iterator end() const { return begin() + NumChunks; }
585  bool empty() const { return NumChunks == 0; }
586  unsigned size() const { return NumChunks; }
587 
588  const Chunk &operator[](unsigned I) const {
589  assert(I < size() && "Chunk index out-of-range");
590  return begin()[I];
591  }
592 
593  /// Returns the text in the TypedText chunk.
594  const char *getTypedText() const;
595 
596  /// Retrieve the priority of this code completion result.
597  unsigned getPriority() const { return Priority; }
598 
599  /// Retrieve the availability of this code completion result.
600  unsigned getAvailability() const { return Availability; }
601 
602  /// Retrieve the number of annotations for this code completion result.
603  unsigned getAnnotationCount() const;
604 
605  /// Retrieve the annotation string specified by \c AnnotationNr.
606  const char *getAnnotation(unsigned AnnotationNr) const;
607 
608  /// Retrieve the name of the parent context.
609  StringRef getParentContextName() const {
610  return ParentName;
611  }
612 
613  const char *getBriefComment() const {
614  return BriefComment;
615  }
616 
617  /// Retrieve a string representation of the code completion string,
618  /// which is mainly useful for debugging.
619  std::string getAsString() const;
620 };
621 
622 /// An allocator used specifically for the purpose of code completion.
623 class CodeCompletionAllocator : public llvm::BumpPtrAllocator {
624 public:
625  /// Copy the given string into this allocator.
626  const char *CopyString(const Twine &String);
627 };
628 
629 /// Allocator for a cached set of global code completions.
631 
633  llvm::DenseMap<const DeclContext *, StringRef> ParentNames;
634  std::shared_ptr<GlobalCodeCompletionAllocator> AllocatorRef;
635 
636 public:
638  std::shared_ptr<GlobalCodeCompletionAllocator> Allocator)
639  : AllocatorRef(std::move(Allocator)) {}
640 
641  std::shared_ptr<GlobalCodeCompletionAllocator> getAllocatorRef() const {
642  return AllocatorRef;
643  }
644 
646  assert(AllocatorRef);
647  return *AllocatorRef;
648  }
649 
650  StringRef getParentName(const DeclContext *DC);
651 };
652 
653 } // namespace clang
654 
655 namespace llvm {
656 
657 template <> struct isPodLike<clang::CodeCompletionString::Chunk> {
658  static const bool value = true;
659 };
660 
661 } // namespace llvm
662 
663 namespace clang {
664 
665 /// A builder class used to construct new code-completion strings.
667 public:
669 
670 private:
671  CodeCompletionAllocator &Allocator;
672  CodeCompletionTUInfo &CCTUInfo;
673  unsigned Priority = 0;
675  StringRef ParentName;
676  const char *BriefComment = nullptr;
677 
678  /// The chunks stored in this string.
679  SmallVector<Chunk, 4> Chunks;
680 
681  SmallVector<const char *, 2> Annotations;
682 
683 public:
685  CodeCompletionTUInfo &CCTUInfo)
686  : Allocator(Allocator), CCTUInfo(CCTUInfo) {}
687 
689  CodeCompletionTUInfo &CCTUInfo,
690  unsigned Priority, CXAvailabilityKind Availability)
691  : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority),
692  Availability(Availability) {}
693 
694  /// Retrieve the allocator into which the code completion
695  /// strings should be allocated.
696  CodeCompletionAllocator &getAllocator() const { return Allocator; }
697 
698  CodeCompletionTUInfo &getCodeCompletionTUInfo() const { return CCTUInfo; }
699 
700  /// Take the resulting completion string.
701  ///
702  /// This operation can only be performed once.
703  CodeCompletionString *TakeString();
704 
705  /// Add a new typed-text chunk.
706  void AddTypedTextChunk(const char *Text);
707 
708  /// Add a new text chunk.
709  void AddTextChunk(const char *Text);
710 
711  /// Add a new optional chunk.
712  void AddOptionalChunk(CodeCompletionString *Optional);
713 
714  /// Add a new placeholder chunk.
715  void AddPlaceholderChunk(const char *Placeholder);
716 
717  /// Add a new informative chunk.
718  void AddInformativeChunk(const char *Text);
719 
720  /// Add a new result-type chunk.
721  void AddResultTypeChunk(const char *ResultType);
722 
723  /// Add a new current-parameter chunk.
724  void AddCurrentParameterChunk(const char *CurrentParameter);
725 
726  /// Add a new chunk.
727  void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text = "");
728 
729  void AddAnnotation(const char *A) { Annotations.push_back(A); }
730 
731  /// Add the parent context information to this code completion.
732  void addParentContext(const DeclContext *DC);
733 
734  const char *getBriefComment() const { return BriefComment; }
735  void addBriefComment(StringRef Comment);
736 
737  StringRef getParentName() const { return ParentName; }
738 };
739 
740 /// Captures a result of code completion.
742 public:
743  /// Describes the kind of result generated.
744  enum ResultKind {
745  /// Refers to a declaration.
746  RK_Declaration = 0,
747 
748  /// Refers to a keyword or symbol.
750 
751  /// Refers to a macro.
753 
754  /// Refers to a precomputed pattern.
755  RK_Pattern
756  };
757 
758  /// When Kind == RK_Declaration or RK_Pattern, the declaration we are
759  /// referring to. In the latter case, the declaration might be NULL.
760  const NamedDecl *Declaration = nullptr;
761 
762  union {
763  /// When Kind == RK_Keyword, the string representing the keyword
764  /// or symbol's spelling.
765  const char *Keyword;
766 
767  /// When Kind == RK_Pattern, the code-completion string that
768  /// describes the completion text to insert.
770 
771  /// When Kind == RK_Macro, the identifier that refers to a macro.
773  };
774 
775  /// The priority of this particular code-completion result.
776  unsigned Priority;
777 
778  /// Specifies which parameter (of a function, Objective-C method,
779  /// macro, etc.) we should start with when formatting the result.
780  unsigned StartParameter = 0;
781 
782  /// The kind of result stored here.
784 
785  /// The cursor kind that describes this result.
787 
788  /// The availability of this result.
790 
791  /// Fix-its that *must* be applied before inserting the text for the
792  /// corresponding completion.
793  ///
794  /// By default, CodeCompletionBuilder only returns completions with empty
795  /// fix-its. Extra completions with non-empty fix-its should be explicitly
796  /// requested by setting CompletionOptions::IncludeFixIts.
797  ///
798  /// For the clients to be able to compute position of the cursor after
799  /// applying fix-its, the following conditions are guaranteed to hold for
800  /// RemoveRange of the stored fix-its:
801  /// - Ranges in the fix-its are guaranteed to never contain the completion
802  /// point (or identifier under completion point, if any) inside them, except
803  /// at the start or at the end of the range.
804  /// - If a fix-it range starts or ends with completion point (or starts or
805  /// ends after the identifier under completion point), it will contain at
806  /// least one character. It allows to unambiguously recompute completion
807  /// point after applying the fix-it.
808  ///
809  /// The intuition is that provided fix-its change code around the identifier
810  /// we complete, but are not allowed to touch the identifier itself or the
811  /// completion point. One example of completions with corrections are the ones
812  /// replacing '.' with '->' and vice versa:
813  ///
814  /// std::unique_ptr<std::vector<int>> vec_ptr;
815  /// In 'vec_ptr.^', one of the completions is 'push_back', it requires
816  /// replacing '.' with '->'.
817  /// In 'vec_ptr->^', one of the completions is 'release', it requires
818  /// replacing '->' with '.'.
819  std::vector<FixItHint> FixIts;
820 
821  /// Whether this result is hidden by another name.
822  bool Hidden : 1;
823 
824  /// Whether this result was found via lookup into a base class.
826 
827  /// Whether this declaration is the beginning of a
828  /// nested-name-specifier and, therefore, should be followed by '::'.
830 
831  /// Whether all parameters (of a function, Objective-C
832  /// method, etc.) should be considered "informative".
834 
835  /// Whether we're completing a declaration of the given entity,
836  /// rather than a use of that entity.
837  bool DeclaringEntity : 1;
838 
839  /// If the result should have a nested-name-specifier, this is it.
840  /// When \c QualifierIsInformative, the nested-name-specifier is
841  /// informative rather than required.
842  NestedNameSpecifier *Qualifier = nullptr;
843 
844  /// If this Decl was unshadowed by using declaration, this can store a
845  /// pointer to the UsingShadowDecl which was used in the unshadowing process.
846  /// This information can be used to uprank CodeCompletionResults / which have
847  /// corresponding `using decl::qualified::name;` nearby.
848  const UsingShadowDecl *ShadowDecl = nullptr;
849 
850  /// If the result is RK_Macro, this can store the information about the macro
851  /// definition. This should be set in most cases but can be missing when
852  /// the macro has been undefined.
853  const MacroInfo *MacroDefInfo = nullptr;
854 
855  /// Build a result that refers to a declaration.
856  CodeCompletionResult(const NamedDecl *Declaration, unsigned Priority,
857  NestedNameSpecifier *Qualifier = nullptr,
858  bool QualifierIsInformative = false,
859  bool Accessible = true,
860  std::vector<FixItHint> FixIts = std::vector<FixItHint>())
861  : Declaration(Declaration), Priority(Priority), Kind(RK_Declaration),
862  FixIts(std::move(FixIts)), Hidden(false),
863  QualifierIsInformative(QualifierIsInformative),
864  StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
865  DeclaringEntity(false), Qualifier(Qualifier) {
866  // FIXME: Add assert to check FixIts range requirements.
867  computeCursorKindAndAvailability(Accessible);
868  }
869 
870  /// Build a result that refers to a keyword or symbol.
871  CodeCompletionResult(const char *Keyword, unsigned Priority = CCP_Keyword)
872  : Keyword(Keyword), Priority(Priority), Kind(RK_Keyword),
873  CursorKind(CXCursor_NotImplemented), Hidden(false),
874  QualifierIsInformative(false), StartsNestedNameSpecifier(false),
875  AllParametersAreInformative(false), DeclaringEntity(false) {}
876 
877  /// Build a result that refers to a macro.
879  const MacroInfo *MI = nullptr,
880  unsigned Priority = CCP_Macro)
881  : Macro(Macro), Priority(Priority), Kind(RK_Macro),
882  CursorKind(CXCursor_MacroDefinition), Hidden(false),
883  QualifierIsInformative(false), StartsNestedNameSpecifier(false),
884  AllParametersAreInformative(false), DeclaringEntity(false),
885  MacroDefInfo(MI) {}
886 
887  /// Build a result that refers to a pattern.
889  unsigned Priority = CCP_CodePattern,
892  const NamedDecl *D = nullptr)
893  : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
894  CursorKind(CursorKind), Availability(Availability), Hidden(false),
895  QualifierIsInformative(false), StartsNestedNameSpecifier(false),
896  AllParametersAreInformative(false), DeclaringEntity(false) {}
897 
898  /// Build a result that refers to a pattern with an associated
899  /// declaration.
901  unsigned Priority)
902  : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
903  Hidden(false), QualifierIsInformative(false),
904  StartsNestedNameSpecifier(false), AllParametersAreInformative(false),
905  DeclaringEntity(false) {
906  computeCursorKindAndAvailability();
907  }
908 
909  /// Retrieve the declaration stored in this result. This might be nullptr if
910  /// Kind is RK_Pattern.
911  const NamedDecl *getDeclaration() const {
912  assert(((Kind == RK_Declaration) || (Kind == RK_Pattern)) &&
913  "Not a declaration or pattern result");
914  return Declaration;
915  }
916 
917  /// Retrieve the keyword stored in this result.
918  const char *getKeyword() const {
919  assert(Kind == RK_Keyword && "Not a keyword result");
920  return Keyword;
921  }
922 
923  /// Create a new code-completion string that describes how to insert
924  /// this result into a program.
925  ///
926  /// \param S The semantic analysis that created the result.
927  ///
928  /// \param Allocator The allocator that will be used to allocate the
929  /// string itself.
930  CodeCompletionString *CreateCodeCompletionString(Sema &S,
931  const CodeCompletionContext &CCContext,
932  CodeCompletionAllocator &Allocator,
933  CodeCompletionTUInfo &CCTUInfo,
934  bool IncludeBriefComments);
935  CodeCompletionString *CreateCodeCompletionString(ASTContext &Ctx,
936  Preprocessor &PP,
937  const CodeCompletionContext &CCContext,
938  CodeCompletionAllocator &Allocator,
939  CodeCompletionTUInfo &CCTUInfo,
940  bool IncludeBriefComments);
941  /// Creates a new code-completion string for the macro result. Similar to the
942  /// above overloads, except this only requires preprocessor information.
943  /// The result kind must be `RK_Macro`.
945  CreateCodeCompletionStringForMacro(Preprocessor &PP,
946  CodeCompletionAllocator &Allocator,
947  CodeCompletionTUInfo &CCTUInfo);
948 
949  CodeCompletionString *createCodeCompletionStringForDecl(
951  bool IncludeBriefComments, const CodeCompletionContext &CCContext,
952  PrintingPolicy &Policy);
953 
954  CodeCompletionString *createCodeCompletionStringForOverride(
955  Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
956  bool IncludeBriefComments, const CodeCompletionContext &CCContext,
957  PrintingPolicy &Policy);
958 
959  /// Retrieve the name that should be used to order a result.
960  ///
961  /// If the name needs to be constructed as a string, that string will be
962  /// saved into Saved and the returned StringRef will refer to it.
963  StringRef getOrderedName(std::string &Saved) const;
964 
965 private:
966  void computeCursorKindAndAvailability(bool Accessible = true);
967 };
968 
970 
971 inline bool operator>(const CodeCompletionResult &X,
972  const CodeCompletionResult &Y) {
973  return Y < X;
974 }
975 
976 inline bool operator<=(const CodeCompletionResult &X,
977  const CodeCompletionResult &Y) {
978  return !(Y < X);
979 }
980 
981 inline bool operator>=(const CodeCompletionResult &X,
982  const CodeCompletionResult &Y) {
983  return !(X < Y);
984 }
985 
986 raw_ostream &operator<<(raw_ostream &OS,
987  const CodeCompletionString &CCS);
988 
989 /// Abstract interface for a consumer of code-completion
990 /// information.
992 protected:
994 
995  /// Whether the output format for the code-completion consumer is
996  /// binary.
998 
999 public:
1001  public:
1002  /// Describes the type of overload candidate.
1004  /// The candidate is a function declaration.
1006 
1007  /// The candidate is a function template.
1009 
1010  /// The "candidate" is actually a variable, expression, or block
1011  /// for which we only have a function prototype.
1012  CK_FunctionType
1013  };
1014 
1015  private:
1016  /// The kind of overload candidate.
1018 
1019  union {
1020  /// The function overload candidate, available when
1021  /// Kind == CK_Function.
1023 
1024  /// The function template overload candidate, available when
1025  /// Kind == CK_FunctionTemplate.
1027 
1028  /// The function type that describes the entity being called,
1029  /// when Kind == CK_FunctionType.
1031  };
1032 
1033  public:
1035  : Kind(CK_Function), Function(Function) {}
1036 
1038  : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {}
1039 
1041  : Kind(CK_FunctionType), Type(Type) {}
1042 
1043  /// Determine the kind of overload candidate.
1044  CandidateKind getKind() const { return Kind; }
1045 
1046  /// Retrieve the function overload candidate or the templated
1047  /// function declaration for a function template.
1048  FunctionDecl *getFunction() const;
1049 
1050  /// Retrieve the function template overload candidate.
1052  assert(getKind() == CK_FunctionTemplate && "Not a function template");
1053  return FunctionTemplate;
1054  }
1055 
1056  /// Retrieve the function type of the entity, regardless of how the
1057  /// function is stored.
1058  const FunctionType *getFunctionType() const;
1059 
1060  /// Create a new code-completion string that describes the function
1061  /// signature of this overload candidate.
1062  CodeCompletionString *CreateSignatureString(unsigned CurrentArg,
1063  Sema &S,
1064  CodeCompletionAllocator &Allocator,
1065  CodeCompletionTUInfo &CCTUInfo,
1066  bool IncludeBriefComments) const;
1067  };
1068 
1070  bool OutputIsBinary)
1071  : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary) {}
1072 
1073  /// Whether the code-completion consumer wants to see macros.
1074  bool includeMacros() const {
1075  return CodeCompleteOpts.IncludeMacros;
1076  }
1077 
1078  /// Whether the code-completion consumer wants to see code patterns.
1079  bool includeCodePatterns() const {
1080  return CodeCompleteOpts.IncludeCodePatterns;
1081  }
1082 
1083  /// Whether to include global (top-level) declaration results.
1084  bool includeGlobals() const { return CodeCompleteOpts.IncludeGlobals; }
1085 
1086  /// Whether to include declarations in namespace contexts (including
1087  /// the global namespace). If this is false, `includeGlobals()` will be
1088  /// ignored.
1090  return CodeCompleteOpts.IncludeNamespaceLevelDecls;
1091  }
1092 
1093  /// Whether to include brief documentation comments within the set of
1094  /// code completions returned.
1095  bool includeBriefComments() const {
1096  return CodeCompleteOpts.IncludeBriefComments;
1097  }
1098 
1099  /// Whether to include completion items with small fix-its, e.g. change
1100  /// '.' to '->' on member access, etc.
1101  bool includeFixIts() const { return CodeCompleteOpts.IncludeFixIts; }
1102 
1103  /// Hint whether to load data from the external AST in order to provide
1104  /// full results. If false, declarations from the preamble may be omitted.
1105  bool loadExternal() const {
1106  return CodeCompleteOpts.LoadExternal;
1107  }
1108 
1109  /// Determine whether the output of this consumer is binary.
1110  bool isOutputBinary() const { return OutputIsBinary; }
1111 
1112  /// Deregisters and destroys this code-completion consumer.
1113  virtual ~CodeCompleteConsumer();
1114 
1115  /// \name Code-completion filtering
1116  /// Check if the result should be filtered out.
1117  virtual bool isResultFilteredOut(StringRef Filter,
1118  CodeCompletionResult Results) {
1119  return false;
1120  }
1121 
1122  /// \name Code-completion callbacks
1123  //@{
1124  /// Process the finalized code-completion results.
1126  CodeCompletionContext Context,
1127  CodeCompletionResult *Results,
1128  unsigned NumResults) {}
1129 
1130  /// \param S the semantic-analyzer object for which code-completion is being
1131  /// done.
1132  ///
1133  /// \param CurrentArg the index of the current argument.
1134  ///
1135  /// \param Candidates an array of overload candidates.
1136  ///
1137  /// \param NumCandidates the number of overload candidates
1138  ///
1139  /// \param OpenParLoc location of the opening parenthesis of the argument
1140  /// list.
1141  virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
1142  OverloadCandidate *Candidates,
1143  unsigned NumCandidates,
1144  SourceLocation OpenParLoc) {}
1145  //@}
1146 
1147  /// Retrieve the allocator that will be used to allocate
1148  /// code completion strings.
1149  virtual CodeCompletionAllocator &getAllocator() = 0;
1150 
1151  virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() = 0;
1152 };
1153 
1154 /// Get the documentation comment used to produce
1155 /// CodeCompletionString::BriefComment for RK_Declaration.
1156 const RawComment *getCompletionComment(const ASTContext &Ctx,
1157  const NamedDecl *Decl);
1158 
1159 /// Get the documentation comment used to produce
1160 /// CodeCompletionString::BriefComment for RK_Pattern.
1162  const NamedDecl *Decl);
1163 
1164 /// Get the documentation comment used to produce
1165 /// CodeCompletionString::BriefComment for OverloadCandidate.
1166 const RawComment *
1167 getParameterComment(const ASTContext &Ctx,
1169  unsigned ArgIndex);
1170 
1171 /// A simple code-completion consumer that prints the results it
1172 /// receives in a simple format.
1174  /// The raw output stream.
1175  raw_ostream &OS;
1176 
1177  CodeCompletionTUInfo CCTUInfo;
1178 
1179 public:
1180  /// Create a new printing code-completion consumer that prints its
1181  /// results to the given raw output stream.
1183  raw_ostream &OS)
1184  : CodeCompleteConsumer(CodeCompleteOpts, false), OS(OS),
1185  CCTUInfo(std::make_shared<GlobalCodeCompletionAllocator>()) {}
1186 
1187  /// Prints the finalized code-completion results.
1188  void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context,
1189  CodeCompletionResult *Results,
1190  unsigned NumResults) override;
1191 
1192  void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
1193  OverloadCandidate *Candidates,
1194  unsigned NumCandidates,
1195  SourceLocation OpenParLoc) override;
1196 
1197  bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results) override;
1198 
1200  return CCTUInfo.getAllocator();
1201  }
1202 
1203  CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; }
1204 };
1205 
1206 } // namespace clang
1207 
1208 #endif // LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
One piece of the code completion string.
An unknown context, in which we are recovering from a parsing error and don&#39;t know which completions ...
A code completion string that is entirely optional.
Priority for the next initialization in a constructor initializer list.
CXAvailabilityKind
Describes the availability of a particular entity, which indicates whether the use of this entity wil...
Definition: Index.h:131
CodeCompletionAllocator & getAllocator() const
Represents a function declaration or definition.
Definition: Decl.h:1732
llvm::SmallPtrSet< DeclContext *, 8 > VisitedContextSet
ResultKind Kind
The kind of result stored here.
std::vector< FixItHint > FixIts
Fix-its that must be applied before inserting the text for the corresponding completion.
const FunctionType * Type
The function type that describes the entity being called, when Kind == CK_FunctionType.
CXCursorKind CursorKind
The cursor kind that describes this result.
A (possibly-)qualified type.
Definition: Type.h:642
unsigned IncludeBriefComments
Show brief documentation comments in code completion results.
llvm::Optional< const CXXScopeSpec * > getCXXScopeSpecifier()
Code completion for a selector, as in an @selector expression.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
unsigned IncludeGlobals
Show top-level decls in code completion results.
unsigned getMacroUsagePriority(StringRef MacroName, const LangOptions &LangOpts, bool PreferredTypeIsPointer=false)
Determine the priority to be given to a macro code completion result with the given name...
Code completion where an Objective-C class message is expected.
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3351
CodeCompletionResult(const NamedDecl *Declaration, unsigned Priority, NestedNameSpecifier *Qualifier=nullptr, bool QualifierIsInformative=false, bool Accessible=true, std::vector< FixItHint > FixIts=std::vector< FixItHint >())
Build a result that refers to a declaration.
C Language Family Type Representation.
Code completion within a type-qualifier list.
static void AddResultTypeChunk(ASTContext &Context, const PrintingPolicy &Policy, const NamedDecl *ND, QualType BaseType, CodeCompletionBuilder &Result)
If the given declaration has an associated type, add it as a result type chunk.
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:87
Priority for a language keyword (that isn&#39;t any of the other categories).
CandidateKind
Describes the type of overload candidate.
Defines the clang::MacroInfo and clang::MacroDirective classes.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
Definition: Attr.h:335
The base class of the type hierarchy.
Definition: Type.h:1415
The selector of the given message exactly matches the selector of the current method, which might imply that some kind of delegation is occurring.
An unspecified code-completion context.
Allocator for a cached set of global code completions.
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool loadExternal() const
Hint whether to load data from the external AST in order to provide full results. ...
Code completion occurred where an Objective-C message receiver is expected.
Priority for a preprocessor macro.
unsigned Priority
The priority of this particular code-completion result.
Code completion occurred on the right-hand side of a member access expression using the arrow operato...
ChunkKind
The different kinds of "chunks" that can occur within a code completion string.
Code completion occurred after the "enum" keyword, to indicate an enumeration name.
bool isOutputBinary() const
Determine whether the output of this consumer is binary.
A piece of text that describes the type of an entity or, for functions and methods, the return type.
bool StartsNestedNameSpecifier
Whether this declaration is the beginning of a nested-name-specifier and, therefore, should be followed by &#39;::&#39;.
const char * Keyword
When Kind == RK_Keyword, the string representing the keyword or symbol&#39;s spelling.
Code completion occurred within the instance variable list of an Objective-C interface, implementation, or category implementation.
Describes how types, statements, expressions, and declarations should be printed. ...
Definition: PrettyPrinter.h:38
bool operator<=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, unsigned Priority, CXAvailabilityKind Availability)
One of these records is kept for each identifier that is lexed.
OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
Priority for a type.
CodeCompletionResult(const IdentifierInfo *Macro, const MacroInfo *MI=nullptr, unsigned Priority=CCP_Macro)
Build a result that refers to a macro.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:154
A "string" used to describe how code completion can be performed for an entity.
Definition: Format.h:2073
Priority for an enumeration constant inside a switch whose condition is of the enumeration type...
Kind getKind() const
Retrieve the kind of code-completion context.
Adjustment to the "bool" type in Objective-C, where the typedef "BOOL" is preferred.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
bool operator>(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
unsigned IncludeCodePatterns
Show code patterns in code completion results.
An allocator used specifically for the purpose of code completion.
CodeCompletionString * Pattern
When Kind == RK_Pattern, the code-completion string that describes the completion text to insert...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Code completion occurred where a preprocessor directive is expected.
An Objective-C method being used as a property.
Code completion occurred within an Objective-C implementation or category implementation.
bool QualifierIsInformative
Whether this result was found via lookup into a base class.
FunctionTemplateDecl * FunctionTemplate
The function template overload candidate, available when Kind == CK_FunctionTemplate.
QualType getDeclUsageType(ASTContext &C, const NamedDecl *ND)
Determine the type that this declaration will have if it is used as a type or in an expression...
Code completion occurred where a namespace or namespace alias is expected.
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
The piece of text that the user is expected to type to match the code-completion string, typically a keyword or the name of a declarator or macro.
A comma separator (&#39;,&#39;).
bool wantConstructorResults() const
Determines whether we want C++ constructors as results within this context.
virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates, SourceLocation OpenParLoc)
CXCursorKind
Describes the kind of entity that a cursor refers to.
Definition: Index.h:1714
FunctionTemplateDecl * getFunctionTemplate() const
Retrieve the function template overload candidate.
CodeCompletionAllocator & getAllocator() const
Retrieve the allocator into which the code completion strings should be allocated.
A right parenthesis (&#39;)&#39;).
Code completion where an Objective-C category name is expected.
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:278
Code completion occurred within a "top-level" completion context, e.g., at namespace or global scope...
CodeCompletionTUInfo & getCodeCompletionTUInfo() override
Priority for the Objective-C "_cmd" implicit parameter.
Priority for a member declaration found from the current method or member function.
Priority for a result that isn&#39;t likely to be what the user wants, but is included for completeness...
Code completion occurred where a protocol name is expected.
CXCursorKind getCursorKindForDecl(const Decl *D)
Determine the libclang cursor kind associated with the given declaration.
const RawComment * getCompletionComment(const ASTContext &Ctx, const NamedDecl *Decl)
Get the documentation comment used to produce CodeCompletionString::BriefComment for RK_Declaration...
A simple code-completion consumer that prints the results it receives in a simple format...
QualType getPreferredType() const
Retrieve the type that this expression would prefer to have, e.g., if the expression is a variable in...
llvm::StringRef getCompletionKindString(CodeCompletionContext::Kind Kind)
Get string representation of Kind, useful for for debugging.
Code completion occurred where a new name is expected.
llvm::StringRef getAsString(SyncScope S)
Definition: SyncScope.h:51
CodeCompletionResult(CodeCompletionString *Pattern, const NamedDecl *D, unsigned Priority)
Build a result that refers to a pattern with an associated declaration.
const char * Text
The text string associated with a CK_Text, CK_Placeholder, CK_Informative, or CK_Comma chunk...
This file defines the classes used to store parsed information about declaration-specifiers and decla...
virtual void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults)
Process the finalized code-completion results.
void addVisitedContext(DeclContext *Ctx)
Adds a visited context.
unsigned IncludeNamespaceLevelDecls
Show decls in namespace (including the global namespace) in code completion results.
Captures a result of code completion.
ArrayRef< IdentifierInfo * > getSelIdents() const
Retrieve the Objective-C selector identifiers.
Code completion occurred where a new name is expected and a qualified name is permissible.
CodeCompletionContext(Kind CCKind)
Construct a new code-completion context of the given kind.
std::shared_ptr< GlobalCodeCompletionAllocator > getAllocatorRef() const
An Objective-C block property completed as a setter with a block placeholder.
Code completion in a parenthesized expression, which means that we may also have types here in C and ...
Code completion occurred in a context where natural language is expected, e.g., a comment or string l...
virtual bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results)
FunctionDecl * Function
The function overload candidate, available when Kind == CK_Function.
A piece of text that should be placed in the buffer, e.g., parentheses or a comma in a function call...
The result type of a method or function.
StringRef getParentContextName() const
Retrieve the name of the parent context.
CandidateKind getKind() const
Determine the kind of overload candidate.
CodeCompletionString * Optional
The code completion string associated with a CK_Optional chunk.
The context in which code completion occurred, so that the code-completion consumer can process the r...
const IdentifierInfo * Macro
When Kind == RK_Macro, the identifier that refers to a macro.
PrintingCodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, raw_ostream &OS)
Create a new printing code-completion consumer that prints its results to the given raw output stream...
The result is a C++ non-static member function whose qualifiers exactly match the object type on whic...
Code completion occurred within a class, struct, or union.
const VisitedContextSet & getVisitedContexts() const
Retrieves all visited contexts.
#define false
Definition: stdbool.h:33
Encodes a location in the source.
Divide by this factor when a code-completion result&#39;s type exactly matches the type we expect...
Priority for a non-type declaration.
const char * getBriefComment() const
Code completion where the name of an Objective-C class is expected.
const Chunk & operator[](unsigned I) const
Code completion occurred within an Objective-C interface, protocol, or category interface.
CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, bool OutputIsBinary)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Represents a canonical, potentially-qualified type.
Definition: CanonicalType.h:66
The entity is available.
Definition: Index.h:135
SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T)
Determine the simplified type class of the given canonical type.
const RawComment * getParameterComment(const ASTContext &Ctx, const CodeCompleteConsumer::OverloadCandidate &Result, unsigned ArgIndex)
Get the documentation comment used to produce CodeCompletionString::BriefComment for OverloadCandidat...
bool operator>=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
const char * getBriefComment() const
bool includeMacros() const
Whether the code-completion consumer wants to see macros.
CodeCompletionTUInfo & getCodeCompletionTUInfo() const
Abstract interface for a consumer of code-completion information.
Options controlling the behavior of code completion.
Priority for a nested-name-specifier.
Dataflow Directional Tag Classes.
Code completion occurred where an macro is being defined.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1261
A piece of text that describes something about the result but should not be inserted into the buffer...
Code completion occurred after the "struct" or "class" keyword, to indicate a struct or class name...
Adjustment for KVC code pattern priorities when it doesn&#39;t look like the.
CodeCompletionResult(CodeCompletionString *Pattern, unsigned Priority=CCP_CodePattern, CXCursorKind CursorKind=CXCursor_NotImplemented, CXAvailabilityKind Availability=CXAvailability_Available, const NamedDecl *D=nullptr)
Build a result that refers to a pattern.
Code completion occurred after the "union" keyword, to indicate a union name.
Code completion occurred where a macro name is expected (without any arguments, in the case of a func...
bool includeFixIts() const
Whether to include completion items with small fix-its, e.g.
A builder class used to construct new code-completion strings.
Code completion where an Objective-C instance message is expected.
Divide by this factor when a code-completion result&#39;s type is similar to the type we expect (e...
const RawComment * getPatternCompletionComment(const ASTContext &Ctx, const NamedDecl *Decl)
Get the documentation comment used to produce CodeCompletionString::BriefComment for RK_Pattern...
const char * getKeyword() const
Retrieve the keyword stored in this result.
Code completion occurred where a statement (or declaration) is expected in a function, method, or block.
Code completion occurred on the right-hand side of an Objective-C property access expression...
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:40
const CodeCompleteOptions CodeCompleteOpts
CodeCompletionResult(const char *Keyword, unsigned Priority=CCP_Keyword)
Build a result that refers to a keyword or symbol.
const NamedDecl * getDeclaration() const
Retrieve the declaration stored in this result.
QualType getBaseType() const
Retrieve the type of the base object in a member-access expression.
bool includeBriefComments() const
Whether to include brief documentation comments within the set of code completions returned...
A piece of text that describes the parameter that corresponds to the code-completion location within ...
A string that acts as a placeholder for, e.g., a function call argument.
The result is in a base class.
CodeCompletionContext(Kind CCKind, QualType T, ArrayRef< IdentifierInfo *> SelIdents=None)
Construct a new code-completion context of the given kind.
bool Hidden
Whether this result is hidden by another name.
unsigned getAvailability() const
Retrieve the availability of this code completion result.
A left parenthesis (&#39;(&#39;).
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:13803
Code completion occurred within a preprocessor expression.
Code completion occurred where an expression is expected.
Code completion inside the filename part of a #include directive.
Priority for a code pattern.
bool AllParametersAreInformative
Whether all parameters (of a function, Objective-C method, etc.) should be considered "informative"...
An unspecified code-completion context where we should also add macro completions.
CodeCompletionAllocator & getAllocator() override
Retrieve the allocator that will be used to allocate code completion strings.
unsigned IncludeFixIts
Include results after corrections (small fix-its), e.g.
A left angle bracket (&#39;<&#39;).
void setCXXScopeSpecifier(CXXScopeSpec SS)
Sets the scope specifier that comes before the completion token.
A right angle bracket (&#39;>&#39;).
bool OutputIsBinary
Whether the output format for the code-completion consumer is binary.
ResultKind
Describes the kind of result generated.
CodeCompletionTUInfo(std::shared_ptr< GlobalCodeCompletionAllocator > Allocator)
unsigned LoadExternal
Hint whether to load data from the external AST to provide full results.
Code completion occurred on the right-hand side of a member access expression using the dot operator...
SimplifiedTypeClass
A simplified classification of types used when determining "similar" types for code completion...
Priority for a declaration that is in the local scope.
Code completion occurred where a type name is expected.
Horizontal whitespace (&#39; &#39;).
bool includeCodePatterns() const
Whether the code-completion consumer wants to see code patterns.
StringRef Text
Definition: Format.cpp:1621
Priority for a send-to-super completion.
bool DeclaringEntity
Whether we&#39;re completing a declaration of the given entity, rather than a use of that entity...
unsigned getPriority() const
Retrieve the priority of this code completion result.
unsigned IncludeMacros
Show macros in code completion results.
CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo)
This represents a decl that may have a name.
Definition: Decl.h:248
bool includeNamespaceLevelDecls() const
Whether to include declarations in namespace contexts (including the global namespace).
Priority for a constant value (e.g., enumerator).
Declaration of a template function.
Definition: DeclTemplate.h:968
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
Definition: DeclCXX.h:3133
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:127
bool includeGlobals() const
Whether to include global (top-level) declaration results.