clang 19.0.0git
CodeCompleteConsumer.h
Go to the documentation of this file.
1//===- CodeCompleteConsumer.h - Code Completion Interface -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the CodeCompleteConsumer class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
14#define LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
15
16#include "clang-c/Index.h"
17#include "clang/AST/Type.h"
18#include "clang/Basic/LLVM.h"
19#include "clang/Lex/MacroInfo.h"
21#include "clang/Sema/DeclSpec.h"
22#include "llvm/ADT/ArrayRef.h"
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/SmallPtrSet.h"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/StringRef.h"
27#include "llvm/Support/Allocator.h"
28#include "llvm/Support/type_traits.h"
29#include <cassert>
30#include <memory>
31#include <optional>
32#include <string>
33#include <utility>
34
35namespace clang {
36
37class ASTContext;
38class Decl;
39class DeclContext;
40class FunctionDecl;
41class FunctionTemplateDecl;
42class IdentifierInfo;
43class LangOptions;
44class NamedDecl;
45class NestedNameSpecifier;
46class Preprocessor;
47class RawComment;
48class Sema;
49class UsingShadowDecl;
50
51/// Default priority values for code-completion results based
52/// on their kind.
53enum {
54 /// Priority for the next initialization in a constructor initializer
55 /// list.
57
58 /// Priority for an enumeration constant inside a switch whose
59 /// condition is of the enumeration type.
61
62 /// Priority for a send-to-super completion.
64
65 /// Priority for a declaration that is in the local scope.
67
68 /// Priority for a member declaration found from the current
69 /// method or member function.
71
72 /// Priority for a language keyword (that isn't any of the other
73 /// categories).
75
76 /// Priority for a code pattern.
78
79 /// Priority for a non-type declaration.
81
82 /// Priority for a type.
84
85 /// Priority for a constant value (e.g., enumerator).
87
88 /// Priority for a preprocessor macro.
90
91 /// Priority for a nested-name-specifier.
93
94 /// Priority for a result that isn't likely to be what the user wants,
95 /// but is included for completeness.
97
98 /// Priority for the Objective-C "_cmd" implicit parameter.
101
102/// Priority value deltas that are added to code-completion results
103/// based on the context of the result.
104enum {
105 /// The result is in a base class.
107
108 /// The result is a C++ non-static member function whose qualifiers
109 /// exactly match the object type on which the member function can be called.
111
112 /// The selector of the given message exactly matches the selector
113 /// of the current method, which might imply that some kind of delegation
114 /// is occurring.
116
117 /// Adjustment to the "bool" type in Objective-C, where the typedef
118 /// "BOOL" is preferred.
120
121 /// Adjustment for KVC code pattern priorities when it doesn't look
122 /// like the
124
125 /// An Objective-C method being used as a property.
127
128 /// An Objective-C block property completed as a setter with a
129 /// block placeholder.
132
133/// Priority value factors by which we will divide or multiply the
134/// priority of a code-completion result.
135enum {
136 /// Divide by this factor when a code-completion result's type exactly
137 /// matches the type we expect.
139
140 /// Divide by this factor when a code-completion result's type is
141 /// similar to the type we expect (e.g., both arithmetic types, both
142 /// Objective-C object pointer types).
145
146/// A simplified classification of types used when determining
147/// "similar" types for code completion.
159
160/// Determine the simplified type class of the given canonical type.
162
163/// Determine the type that this declaration will have if it is used
164/// as a type or in an expression.
165QualType getDeclUsageType(ASTContext &C, const NamedDecl *ND);
166
167/// Determine the priority to be given to a macro code completion result
168/// with the given name.
169///
170/// \param MacroName The name of the macro.
171///
172/// \param LangOpts Options describing the current language dialect.
173///
174/// \param PreferredTypeIsPointer Whether the preferred type for the context
175/// of this macro is a pointer type.
176unsigned getMacroUsagePriority(StringRef MacroName,
177 const LangOptions &LangOpts,
178 bool PreferredTypeIsPointer = false);
179
180/// Determine the libclang cursor kind associated with the given
181/// declaration.
183
184/// The context in which code completion occurred, so that the
185/// code-completion consumer can process the results accordingly.
187public:
188 enum Kind {
189 /// An unspecified code-completion context.
191
192 /// An unspecified code-completion context where we should also add
193 /// macro completions.
195
196 /// Code completion occurred within a "top-level" completion context,
197 /// e.g., at namespace or global scope.
199
200 /// Code completion occurred within an Objective-C interface,
201 /// protocol, or category interface.
203
204 /// Code completion occurred within an Objective-C implementation
205 /// or category implementation.
207
208 /// Code completion occurred within the instance variable list of
209 /// an Objective-C interface, implementation, or category implementation.
211
212 /// Code completion occurred within a class, struct, or union.
214
215 /// Code completion occurred where a statement (or declaration) is
216 /// expected in a function, method, or block.
218
219 /// Code completion occurred where an expression is expected.
221
222 /// Code completion occurred where an Objective-C message receiver
223 /// is expected.
225
226 /// Code completion occurred on the right-hand side of a member
227 /// access expression using the dot operator.
228 ///
229 /// The results of this completion are the members of the type being
230 /// accessed. The type itself is available via
231 /// \c CodeCompletionContext::getType().
233
234 /// Code completion occurred on the right-hand side of a member
235 /// access expression using the arrow operator.
236 ///
237 /// The results of this completion are the members of the type being
238 /// accessed. The type itself is available via
239 /// \c CodeCompletionContext::getType().
241
242 /// Code completion occurred on the right-hand side of an Objective-C
243 /// property access expression.
244 ///
245 /// The results of this completion are the members of the type being
246 /// accessed. The type itself is available via
247 /// \c CodeCompletionContext::getType().
249
250 /// Code completion occurred after the "enum" keyword, to indicate
251 /// an enumeration name.
253
254 /// Code completion occurred after the "union" keyword, to indicate
255 /// a union name.
257
258 /// Code completion occurred after the "struct" or "class" keyword,
259 /// to indicate a struct or class name.
261
262 /// Code completion occurred where a protocol name is expected.
264
265 /// Code completion occurred where a namespace or namespace alias
266 /// is expected.
268
269 /// Code completion occurred where a type name is expected.
271
272 /// Code completion occurred where a new name is expected.
274
275 /// Code completion occurred where both a new name and an existing symbol is
276 /// permissible.
278
279 /// Code completion occurred where an existing name(such as type, function
280 /// or variable) is expected.
282
283 /// Code completion occurred where an macro is being defined.
285
286 /// Code completion occurred where a macro name is expected
287 /// (without any arguments, in the case of a function-like macro).
289
290 /// Code completion occurred within a preprocessor expression.
292
293 /// Code completion occurred where a preprocessor directive is
294 /// expected.
296
297 /// Code completion occurred in a context where natural language is
298 /// expected, e.g., a comment or string literal.
299 ///
300 /// This context usually implies that no completions should be added,
301 /// unless they come from an appropriate natural-language dictionary.
303
304 /// Code completion for a selector, as in an \@selector expression.
306
307 /// Code completion within a type-qualifier list.
309
310 /// Code completion in a parenthesized expression, which means that
311 /// we may also have types here in C and Objective-C (as well as in C++).
313
314 /// Code completion where an Objective-C instance message is
315 /// expected.
317
318 /// Code completion where an Objective-C class message is expected.
320
321 /// Code completion where the name of an Objective-C class is
322 /// expected.
324
325 /// Code completion where an Objective-C category name is expected.
327
328 /// Code completion inside the filename part of a #include directive.
330
331 /// Code completion of an attribute name.
333
334 /// An unknown context, in which we are recovering from a parsing
335 /// error and don't know which completions we should give.
337
338 /// Code completion in a @class forward declaration.
340
341 /// Code completion at a top level, i.e. in a namespace or global scope,
342 /// but also in expression statements. This is because REPL inputs can be
343 /// declarations or expression statements.
345 };
346
348
349private:
350 Kind CCKind;
351
352 /// Indicates whether we are completing a name of a using declaration, e.g.
353 /// using ^;
354 /// using a::^;
355 bool IsUsingDeclaration;
356
357 /// The type that would prefer to see at this point (e.g., the type
358 /// of an initializer or function parameter).
359 QualType PreferredType;
360
361 /// The type of the base object in a member access expression.
362 QualType BaseType;
363
364 /// The identifiers for Objective-C selector parts.
366
367 /// The scope specifier that comes before the completion token e.g.
368 /// "a::b::"
369 std::optional<CXXScopeSpec> ScopeSpecifier;
370
371 /// A set of declaration contexts visited by Sema when doing lookup for
372 /// code completion.
373 VisitedContextSet VisitedContexts;
374
375public:
376 /// Construct a new code-completion context of the given kind.
378 : CCKind(CCKind), IsUsingDeclaration(false), SelIdents(std::nullopt) {}
379
380 /// Construct a new code-completion context of the given kind.
382 Kind CCKind, QualType T,
383 ArrayRef<const IdentifierInfo *> SelIdents = std::nullopt)
384 : CCKind(CCKind), IsUsingDeclaration(false), SelIdents(SelIdents) {
385 if (CCKind == CCC_DotMemberAccess || CCKind == CCC_ArrowMemberAccess ||
386 CCKind == CCC_ObjCPropertyAccess || CCKind == CCC_ObjCClassMessage ||
387 CCKind == CCC_ObjCInstanceMessage)
388 BaseType = T;
389 else
390 PreferredType = T;
391 }
392
393 bool isUsingDeclaration() const { return IsUsingDeclaration; }
394 void setIsUsingDeclaration(bool V) { IsUsingDeclaration = V; }
395
396 /// Retrieve the kind of code-completion context.
397 Kind getKind() const { return CCKind; }
398
399 /// Retrieve the type that this expression would prefer to have, e.g.,
400 /// if the expression is a variable initializer or a function argument, the
401 /// type of the corresponding variable or function parameter.
402 QualType getPreferredType() const { return PreferredType; }
403 void setPreferredType(QualType T) { PreferredType = T; }
404
405 /// Retrieve the type of the base object in a member-access
406 /// expression.
407 QualType getBaseType() const { return BaseType; }
408
409 /// Retrieve the Objective-C selector identifiers.
410 ArrayRef<const IdentifierInfo *> getSelIdents() const { return SelIdents; }
411
412 /// Determines whether we want C++ constructors as results within this
413 /// context.
414 bool wantConstructorResults() const;
415
416 /// Sets the scope specifier that comes before the completion token.
417 /// This is expected to be set in code completions on qualfied specifiers
418 /// (e.g. "a::b::").
420 this->ScopeSpecifier = std::move(SS);
421 }
422
423 /// Adds a visited context.
425 VisitedContexts.insert(Ctx);
426 }
427
428 /// Retrieves all visited contexts.
430 return VisitedContexts;
431 }
432
433 std::optional<const CXXScopeSpec *> getCXXScopeSpecifier() {
434 if (ScopeSpecifier)
435 return &*ScopeSpecifier;
436 return std::nullopt;
437 }
438};
439
440/// Get string representation of \p Kind, useful for debugging.
442
443/// A "string" used to describe how code completion can
444/// be performed for an entity.
445///
446/// A code completion string typically shows how a particular entity can be
447/// used. For example, the code completion string for a function would show
448/// the syntax to call it, including the parentheses, placeholders for the
449/// arguments, etc.
451public:
452 /// The different kinds of "chunks" that can occur within a code
453 /// completion string.
455 /// The piece of text that the user is expected to type to
456 /// match the code-completion string, typically a keyword or the name of a
457 /// declarator or macro.
459
460 /// A piece of text that should be placed in the buffer, e.g.,
461 /// parentheses or a comma in a function call.
463
464 /// A code completion string that is entirely optional. For example,
465 /// an optional code completion string that describes the default arguments
466 /// in a function call.
468
469 /// A string that acts as a placeholder for, e.g., a function
470 /// call argument.
472
473 /// A piece of text that describes something about the result but
474 /// should not be inserted into the buffer.
476 /// A piece of text that describes the type of an entity or, for
477 /// functions and methods, the return type.
479
480 /// A piece of text that describes the parameter that corresponds
481 /// to the code-completion location within a function call, message send,
482 /// macro invocation, etc.
484
485 /// A left parenthesis ('(').
487
488 /// A right parenthesis (')').
490
491 /// A left bracket ('[').
493
494 /// A right bracket (']').
496
497 /// A left brace ('{').
499
500 /// A right brace ('}').
502
503 /// A left angle bracket ('<').
505
506 /// A right angle bracket ('>').
508
509 /// A comma separator (',').
511
512 /// A colon (':').
514
515 /// A semicolon (';').
517
518 /// An '=' sign.
520
521 /// Horizontal whitespace (' ').
523
524 /// Vertical whitespace ('\\n' or '\\r\\n', depending on the
525 /// platform).
527 };
528
529 /// One piece of the code completion string.
530 struct Chunk {
531 /// The kind of data stored in this piece of the code completion
532 /// string.
534
535 union {
536 /// The text string associated with a CK_Text, CK_Placeholder,
537 /// CK_Informative, or CK_Comma chunk.
538 /// The string is owned by the chunk and will be deallocated
539 /// (with delete[]) when the chunk is destroyed.
540 const char *Text;
541
542 /// The code completion string associated with a CK_Optional chunk.
543 /// The optional code completion string is owned by the chunk, and will
544 /// be deallocated (with delete) when the chunk is destroyed.
546 };
547
548 Chunk() : Text(nullptr) {}
549
550 explicit Chunk(ChunkKind Kind, const char *Text = "");
551
552 /// Create a new text chunk.
553 static Chunk CreateText(const char *Text);
554
555 /// Create a new optional chunk.
557
558 /// Create a new placeholder chunk.
559 static Chunk CreatePlaceholder(const char *Placeholder);
560
561 /// Create a new informative chunk.
562 static Chunk CreateInformative(const char *Informative);
563
564 /// Create a new result type chunk.
565 static Chunk CreateResultType(const char *ResultType);
566
567 /// Create a new current-parameter chunk.
568 static Chunk CreateCurrentParameter(const char *CurrentParameter);
569 };
570
571private:
574
575 /// The number of chunks stored in this string.
576 unsigned NumChunks : 16;
577
578 /// The number of annotations for this code-completion result.
579 unsigned NumAnnotations : 16;
580
581 /// The priority of this code-completion string.
582 unsigned Priority : 16;
583
584 /// The availability of this code-completion result.
585 LLVM_PREFERRED_TYPE(CXAvailabilityKind)
586 unsigned Availability : 2;
587
588 /// The name of the parent context.
589 StringRef ParentName;
590
591 /// A brief documentation comment attached to the declaration of
592 /// entity being completed by this result.
593 const char *BriefComment;
594
595 CodeCompletionString(const Chunk *Chunks, unsigned NumChunks,
596 unsigned Priority, CXAvailabilityKind Availability,
597 const char **Annotations, unsigned NumAnnotations,
598 StringRef ParentName,
599 const char *BriefComment);
600 ~CodeCompletionString() = default;
601
602public:
605
606 using iterator = const Chunk *;
607
608 iterator begin() const { return reinterpret_cast<const Chunk *>(this + 1); }
609 iterator end() const { return begin() + NumChunks; }
610 bool empty() const { return NumChunks == 0; }
611 unsigned size() const { return NumChunks; }
612
613 const Chunk &operator[](unsigned I) const {
614 assert(I < size() && "Chunk index out-of-range");
615 return begin()[I];
616 }
617
618 /// Returns the text in the first TypedText chunk.
619 const char *getTypedText() const;
620
621 /// Returns the combined text from all TypedText chunks.
622 std::string getAllTypedText() const;
623
624 /// Retrieve the priority of this code completion result.
625 unsigned getPriority() const { return Priority; }
626
627 /// Retrieve the availability of this code completion result.
628 unsigned getAvailability() const { return Availability; }
629
630 /// Retrieve the number of annotations for this code completion result.
631 unsigned getAnnotationCount() const;
632
633 /// Retrieve the annotation string specified by \c AnnotationNr.
634 const char *getAnnotation(unsigned AnnotationNr) const;
635
636 /// Retrieve the name of the parent context.
637 StringRef getParentContextName() const {
638 return ParentName;
639 }
640
641 const char *getBriefComment() const {
642 return BriefComment;
643 }
644
645 /// Retrieve a string representation of the code completion string,
646 /// which is mainly useful for debugging.
647 std::string getAsString() const;
648};
649
650/// An allocator used specifically for the purpose of code completion.
651class CodeCompletionAllocator : public llvm::BumpPtrAllocator {
652public:
653 /// Copy the given string into this allocator.
654 const char *CopyString(const Twine &String);
655};
656
657/// Allocator for a cached set of global code completions.
659
661 llvm::DenseMap<const DeclContext *, StringRef> ParentNames;
662 std::shared_ptr<GlobalCodeCompletionAllocator> AllocatorRef;
663
664public:
666 std::shared_ptr<GlobalCodeCompletionAllocator> Allocator)
667 : AllocatorRef(std::move(Allocator)) {}
668
669 std::shared_ptr<GlobalCodeCompletionAllocator> getAllocatorRef() const {
670 return AllocatorRef;
671 }
672
674 assert(AllocatorRef);
675 return *AllocatorRef;
676 }
677
678 StringRef getParentName(const DeclContext *DC);
679};
680
681} // namespace clang
682
683namespace clang {
684
685/// A builder class used to construct new code-completion strings.
687public:
689
690private:
691 CodeCompletionAllocator &Allocator;
692 CodeCompletionTUInfo &CCTUInfo;
693 unsigned Priority = 0;
695 StringRef ParentName;
696 const char *BriefComment = nullptr;
697
698 /// The chunks stored in this string.
700
702
703public:
705 CodeCompletionTUInfo &CCTUInfo)
706 : Allocator(Allocator), CCTUInfo(CCTUInfo) {}
707
709 CodeCompletionTUInfo &CCTUInfo,
710 unsigned Priority, CXAvailabilityKind Availability)
711 : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority),
712 Availability(Availability) {}
713
714 /// Retrieve the allocator into which the code completion
715 /// strings should be allocated.
716 CodeCompletionAllocator &getAllocator() const { return Allocator; }
717
718 CodeCompletionTUInfo &getCodeCompletionTUInfo() const { return CCTUInfo; }
719
720 /// Take the resulting completion string.
721 ///
722 /// This operation can only be performed once.
724
725 /// Add a new typed-text chunk.
726 void AddTypedTextChunk(const char *Text);
727
728 /// Add a new text chunk.
729 void AddTextChunk(const char *Text);
730
731 /// Add a new optional chunk.
733
734 /// Add a new placeholder chunk.
735 void AddPlaceholderChunk(const char *Placeholder);
736
737 /// Add a new informative chunk.
738 void AddInformativeChunk(const char *Text);
739
740 /// Add a new result-type chunk.
741 void AddResultTypeChunk(const char *ResultType);
742
743 /// Add a new current-parameter chunk.
744 void AddCurrentParameterChunk(const char *CurrentParameter);
745
746 /// Add a new chunk.
747 void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text = "");
748
749 void AddAnnotation(const char *A) { Annotations.push_back(A); }
750
751 /// Add the parent context information to this code completion.
752 void addParentContext(const DeclContext *DC);
753
754 const char *getBriefComment() const { return BriefComment; }
755 void addBriefComment(StringRef Comment);
756
757 StringRef getParentName() const { return ParentName; }
758};
759
760/// Captures a result of code completion.
762public:
763 /// Describes the kind of result generated.
765 /// Refers to a declaration.
767
768 /// Refers to a keyword or symbol.
770
771 /// Refers to a macro.
773
774 /// Refers to a precomputed pattern.
776 };
777
778 /// When Kind == RK_Declaration or RK_Pattern, the declaration we are
779 /// referring to. In the latter case, the declaration might be NULL.
780 const NamedDecl *Declaration = nullptr;
781
782 union {
783 /// When Kind == RK_Keyword, the string representing the keyword
784 /// or symbol's spelling.
785 const char *Keyword;
786
787 /// When Kind == RK_Pattern, the code-completion string that
788 /// describes the completion text to insert.
790
791 /// When Kind == RK_Macro, the identifier that refers to a macro.
793 };
794
795 /// The priority of this particular code-completion result.
796 unsigned Priority;
797
798 /// Specifies which parameter (of a function, Objective-C method,
799 /// macro, etc.) we should start with when formatting the result.
800 unsigned StartParameter = 0;
801
802 /// The kind of result stored here.
804
805 /// The cursor kind that describes this result.
807
808 /// The availability of this result.
810
811 /// Fix-its that *must* be applied before inserting the text for the
812 /// corresponding completion.
813 ///
814 /// By default, CodeCompletionBuilder only returns completions with empty
815 /// fix-its. Extra completions with non-empty fix-its should be explicitly
816 /// requested by setting CompletionOptions::IncludeFixIts.
817 ///
818 /// For the clients to be able to compute position of the cursor after
819 /// applying fix-its, the following conditions are guaranteed to hold for
820 /// RemoveRange of the stored fix-its:
821 /// - Ranges in the fix-its are guaranteed to never contain the completion
822 /// point (or identifier under completion point, if any) inside them, except
823 /// at the start or at the end of the range.
824 /// - If a fix-it range starts or ends with completion point (or starts or
825 /// ends after the identifier under completion point), it will contain at
826 /// least one character. It allows to unambiguously recompute completion
827 /// point after applying the fix-it.
828 ///
829 /// The intuition is that provided fix-its change code around the identifier
830 /// we complete, but are not allowed to touch the identifier itself or the
831 /// completion point. One example of completions with corrections are the ones
832 /// replacing '.' with '->' and vice versa:
833 ///
834 /// std::unique_ptr<std::vector<int>> vec_ptr;
835 /// In 'vec_ptr.^', one of the completions is 'push_back', it requires
836 /// replacing '.' with '->'.
837 /// In 'vec_ptr->^', one of the completions is 'release', it requires
838 /// replacing '->' with '.'.
839 std::vector<FixItHint> FixIts;
840
841 /// Whether this result is hidden by another name.
842 bool Hidden : 1;
843
844 /// Whether this is a class member from base class.
845 bool InBaseClass : 1;
846
847 /// Whether this result was found via lookup into a base class.
849
850 /// Whether this declaration is the beginning of a
851 /// nested-name-specifier and, therefore, should be followed by '::'.
853
854 /// Whether all parameters (of a function, Objective-C
855 /// method, etc.) should be considered "informative".
857
858 /// Whether we're completing a declaration of the given entity,
859 /// rather than a use of that entity.
861
862 /// When completing a function, whether it can be a call. This will usually be
863 /// true, but we have some heuristics, e.g. when a pointer to a non-static
864 /// member function is completed outside of that class' scope, it can never
865 /// be a call.
867
868 /// If the result should have a nested-name-specifier, this is it.
869 /// When \c QualifierIsInformative, the nested-name-specifier is
870 /// informative rather than required.
872
873 /// If this Decl was unshadowed by using declaration, this can store a
874 /// pointer to the UsingShadowDecl which was used in the unshadowing process.
875 /// This information can be used to uprank CodeCompletionResults / which have
876 /// corresponding `using decl::qualified::name;` nearby.
877 const UsingShadowDecl *ShadowDecl = nullptr;
878
879 /// If the result is RK_Macro, this can store the information about the macro
880 /// definition. This should be set in most cases but can be missing when
881 /// the macro has been undefined.
882 const MacroInfo *MacroDefInfo = nullptr;
883
884 /// Build a result that refers to a declaration.
887 bool QualifierIsInformative = false,
888 bool Accessible = true,
889 std::vector<FixItHint> FixIts = std::vector<FixItHint>())
895 // FIXME: Add assert to check FixIts range requirements.
896 computeCursorKindAndAvailability(Accessible);
897 }
898
899 /// Build a result that refers to a keyword or symbol.
906
907 /// Build a result that refers to a macro.
909 const MacroInfo *MI = nullptr,
910 unsigned Priority = CCP_Macro)
916
917 /// Build a result that refers to a pattern.
922 const NamedDecl *D = nullptr)
928
929 /// Build a result that refers to a pattern with an associated
930 /// declaration.
932 unsigned Priority)
937 computeCursorKindAndAvailability();
938 }
939
940 /// Retrieve the declaration stored in this result. This might be nullptr if
941 /// Kind is RK_Pattern.
942 const NamedDecl *getDeclaration() const {
943 assert(((Kind == RK_Declaration) || (Kind == RK_Pattern)) &&
944 "Not a declaration or pattern result");
945 return Declaration;
946 }
947
948 /// Retrieve the keyword stored in this result.
949 const char *getKeyword() const {
950 assert(Kind == RK_Keyword && "Not a keyword result");
951 return Keyword;
952 }
953
954 /// Create a new code-completion string that describes how to insert
955 /// this result into a program.
956 ///
957 /// \param S The semantic analysis that created the result.
958 ///
959 /// \param Allocator The allocator that will be used to allocate the
960 /// string itself.
962 const CodeCompletionContext &CCContext,
963 CodeCompletionAllocator &Allocator,
964 CodeCompletionTUInfo &CCTUInfo,
965 bool IncludeBriefComments);
967 Preprocessor &PP,
968 const CodeCompletionContext &CCContext,
969 CodeCompletionAllocator &Allocator,
970 CodeCompletionTUInfo &CCTUInfo,
971 bool IncludeBriefComments);
972 /// Creates a new code-completion string for the macro result. Similar to the
973 /// above overloads, except this only requires preprocessor information.
974 /// The result kind must be `RK_Macro`.
977 CodeCompletionAllocator &Allocator,
978 CodeCompletionTUInfo &CCTUInfo);
979
982 bool IncludeBriefComments, const CodeCompletionContext &CCContext,
983 PrintingPolicy &Policy);
984
987 bool IncludeBriefComments, const CodeCompletionContext &CCContext,
988 PrintingPolicy &Policy);
989
990 /// Retrieve the name that should be used to order a result.
991 ///
992 /// If the name needs to be constructed as a string, that string will be
993 /// saved into Saved and the returned StringRef will refer to it.
994 StringRef getOrderedName(std::string &Saved) const;
995
996private:
997 void computeCursorKindAndAvailability(bool Accessible = true);
998};
999
1000bool operator<(const CodeCompletionResult &X, const CodeCompletionResult &Y);
1001
1003 const CodeCompletionResult &Y) {
1004 return Y < X;
1005}
1006
1008 const CodeCompletionResult &Y) {
1009 return !(Y < X);
1010}
1011
1013 const CodeCompletionResult &Y) {
1014 return !(X < Y);
1015}
1016
1017/// Abstract interface for a consumer of code-completion
1018/// information.
1020protected:
1022
1023public:
1025 public:
1026 /// Describes the type of overload candidate.
1028 /// The candidate is a function declaration.
1030
1031 /// The candidate is a function template, arguments are being completed.
1033
1034 /// The "candidate" is actually a variable, expression, or block
1035 /// for which we only have a function prototype.
1037
1038 /// The candidate is a variable or expression of function type
1039 /// for which we have the location of the prototype declaration.
1041
1042 /// The candidate is a template, template arguments are being completed.
1044
1045 /// The candidate is aggregate initialization of a record type.
1047 };
1048
1049 private:
1050 /// The kind of overload candidate.
1051 CandidateKind Kind;
1052
1053 union {
1054 /// The function overload candidate, available when
1055 /// Kind == CK_Function.
1057
1058 /// The function template overload candidate, available when
1059 /// Kind == CK_FunctionTemplate.
1061
1062 /// The function type that describes the entity being called,
1063 /// when Kind == CK_FunctionType.
1065
1066 /// The location of the function prototype that describes the entity being
1067 /// called, when Kind == CK_FunctionProtoTypeLoc.
1069
1070 /// The template overload candidate, available when
1071 /// Kind == CK_Template.
1073
1074 /// The class being aggregate-initialized,
1075 /// when Kind == CK_Aggregate
1077 };
1078
1079 public:
1081 : Kind(CK_Function), Function(Function) {
1082 assert(Function != nullptr);
1083 }
1084
1087 assert(FunctionTemplateDecl != nullptr);
1088 }
1089
1091 : Kind(CK_FunctionType), Type(Type) {
1092 assert(Type != nullptr);
1093 }
1094
1097 assert(!Prototype.isNull());
1098 }
1099
1102 assert(Aggregate != nullptr);
1103 }
1104
1106 : Kind(CK_Template), Template(Template) {}
1107
1108 /// Determine the kind of overload candidate.
1109 CandidateKind getKind() const { return Kind; }
1110
1111 /// Retrieve the function overload candidate or the templated
1112 /// function declaration for a function template.
1113 FunctionDecl *getFunction() const;
1114
1115 /// Retrieve the function template overload candidate.
1117 assert(getKind() == CK_FunctionTemplate && "Not a function template");
1118 return FunctionTemplate;
1119 }
1120
1121 /// Retrieve the function type of the entity, regardless of how the
1122 /// function is stored.
1123 const FunctionType *getFunctionType() const;
1124
1125 /// Retrieve the function ProtoTypeLoc candidate.
1126 /// This can be called for any Kind, but returns null for kinds
1127 /// other than CK_FunctionProtoTypeLoc.
1129
1130 const TemplateDecl *getTemplate() const {
1131 assert(getKind() == CK_Template && "Not a template");
1132 return Template;
1133 }
1134
1135 /// Retrieve the aggregate type being initialized.
1136 const RecordDecl *getAggregate() const {
1137 assert(getKind() == CK_Aggregate);
1138 return AggregateType;
1139 }
1140
1141 /// Get the number of parameters in this signature.
1142 unsigned getNumParams() const;
1143
1144 /// Get the type of the Nth parameter.
1145 /// Returns null if the type is unknown or N is out of range.
1146 QualType getParamType(unsigned N) const;
1147
1148 /// Get the declaration of the Nth parameter.
1149 /// Returns null if the decl is unknown or N is out of range.
1150 const NamedDecl *getParamDecl(unsigned N) const;
1151
1152 /// Create a new code-completion string that describes the function
1153 /// signature of this overload candidate.
1155 CreateSignatureString(unsigned CurrentArg, Sema &S,
1156 CodeCompletionAllocator &Allocator,
1157 CodeCompletionTUInfo &CCTUInfo,
1158 bool IncludeBriefComments, bool Braced) const;
1159 };
1160
1163
1164 /// Whether the code-completion consumer wants to see macros.
1165 bool includeMacros() const {
1167 }
1168
1169 /// Whether the code-completion consumer wants to see code patterns.
1170 bool includeCodePatterns() const {
1172 }
1173
1174 /// Whether to include global (top-level) declaration results.
1176
1177 /// Whether to include declarations in namespace contexts (including
1178 /// the global namespace). If this is false, `includeGlobals()` will be
1179 /// ignored.
1182 }
1183
1184 /// Whether to include brief documentation comments within the set of
1185 /// code completions returned.
1188 }
1189
1190 /// Whether to include completion items with small fix-its, e.g. change
1191 /// '.' to '->' on member access, etc.
1193
1194 /// Hint whether to load data from the external AST in order to provide
1195 /// full results. If false, declarations from the preamble may be omitted.
1196 bool loadExternal() const {
1198 }
1199
1200 /// Deregisters and destroys this code-completion consumer.
1202
1203 /// \name Code-completion filtering
1204 /// Check if the result should be filtered out.
1205 virtual bool isResultFilteredOut(StringRef Filter,
1206 CodeCompletionResult Results) {
1207 return false;
1208 }
1209
1210 /// \name Code-completion callbacks
1211 //@{
1212 /// Process the finalized code-completion results.
1214 CodeCompletionContext Context,
1215 CodeCompletionResult *Results,
1216 unsigned NumResults) {}
1217
1218 /// \param S the semantic-analyzer object for which code-completion is being
1219 /// done.
1220 ///
1221 /// \param CurrentArg the index of the current argument.
1222 ///
1223 /// \param Candidates an array of overload candidates.
1224 ///
1225 /// \param NumCandidates the number of overload candidates
1226 ///
1227 /// \param OpenParLoc location of the opening parenthesis of the argument
1228 /// list.
1229 virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
1230 OverloadCandidate *Candidates,
1231 unsigned NumCandidates,
1232 SourceLocation OpenParLoc,
1233 bool Braced) {}
1234 //@}
1235
1236 /// Retrieve the allocator that will be used to allocate
1237 /// code completion strings.
1239
1241};
1242
1243/// Get the documentation comment used to produce
1244/// CodeCompletionString::BriefComment for RK_Declaration.
1246 const NamedDecl *Decl);
1247
1248/// Get the documentation comment used to produce
1249/// CodeCompletionString::BriefComment for RK_Pattern.
1251 const NamedDecl *Decl);
1252
1253/// Get the documentation comment used to produce
1254/// CodeCompletionString::BriefComment for OverloadCandidate.
1255const RawComment *
1258 unsigned ArgIndex);
1259
1260/// A simple code-completion consumer that prints the results it
1261/// receives in a simple format.
1263 /// The raw output stream.
1264 raw_ostream &OS;
1265
1266 CodeCompletionTUInfo CCTUInfo;
1267
1268public:
1269 /// Create a new printing code-completion consumer that prints its
1270 /// results to the given raw output stream.
1272 raw_ostream &OS)
1274 CCTUInfo(std::make_shared<GlobalCodeCompletionAllocator>()) {}
1275
1276 /// Prints the finalized code-completion results.
1278 CodeCompletionResult *Results,
1279 unsigned NumResults) override;
1280
1281 void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
1282 OverloadCandidate *Candidates,
1283 unsigned NumCandidates,
1284 SourceLocation OpenParLoc,
1285 bool Braced) override;
1286
1287 bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results) override;
1288
1290 return CCTUInfo.getAllocator();
1291 }
1292
1293 CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo; }
1294};
1295
1296} // namespace clang
1297
1298#endif // LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
#define V(N, I)
Definition: ASTContext.h:3273
StringRef Text
Definition: Format.cpp:2973
int Priority
Definition: Format.cpp:2976
#define X(type, name)
Definition: Value.h:143
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::MacroInfo and clang::MacroDirective classes.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:73
const FunctionType * Type
The function type that describes the entity being called, when Kind == CK_FunctionType.
const RecordDecl * AggregateType
The class being aggregate-initialized, when Kind == CK_Aggregate.
FunctionProtoTypeLoc ProtoTypeLoc
The location of the function prototype that describes the entity being called, when Kind == CK_Functi...
CodeCompletionString * CreateSignatureString(unsigned CurrentArg, Sema &S, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments, bool Braced) const
Create a new code-completion string that describes the function signature of this overload candidate.
QualType getParamType(unsigned N) const
Get the type of the Nth parameter.
const FunctionType * getFunctionType() const
Retrieve the function type of the entity, regardless of how the function is stored.
CandidateKind getKind() const
Determine the kind of overload candidate.
const RecordDecl * getAggregate() const
Retrieve the aggregate type being initialized.
OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
FunctionDecl * getFunction() const
Retrieve the function overload candidate or the templated function declaration for a function templat...
FunctionDecl * Function
The function overload candidate, available when Kind == CK_Function.
const FunctionProtoTypeLoc getFunctionProtoTypeLoc() const
Retrieve the function ProtoTypeLoc candidate.
CandidateKind
Describes the type of overload candidate.
@ CK_Aggregate
The candidate is aggregate initialization of a record type.
@ CK_FunctionType
The "candidate" is actually a variable, expression, or block for which we only have a function protot...
@ CK_Function
The candidate is a function declaration.
@ CK_FunctionProtoTypeLoc
The candidate is a variable or expression of function type for which we have the location of the prot...
@ CK_Template
The candidate is a template, template arguments are being completed.
@ CK_FunctionTemplate
The candidate is a function template, arguments are being completed.
FunctionTemplateDecl * FunctionTemplate
The function template overload candidate, available when Kind == CK_FunctionTemplate.
const NamedDecl * getParamDecl(unsigned N) const
Get the declaration of the Nth parameter.
unsigned getNumParams() const
Get the number of parameters in this signature.
const TemplateDecl * Template
The template overload candidate, available when Kind == CK_Template.
FunctionTemplateDecl * getFunctionTemplate() const
Retrieve the function template overload candidate.
Abstract interface for a consumer of code-completion information.
CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts)
bool includeNamespaceLevelDecls() const
Whether to include declarations in namespace contexts (including the global namespace).
bool includeMacros() const
Whether the code-completion consumer wants to see macros.
virtual ~CodeCompleteConsumer()
Deregisters and destroys this code-completion consumer.
bool includeFixIts() const
Whether to include completion items with small fix-its, e.g.
virtual CodeCompletionAllocator & getAllocator()=0
Retrieve the allocator that will be used to allocate code completion strings.
virtual bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results)
bool includeGlobals() const
Whether to include global (top-level) declaration results.
virtual void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults)
Process the finalized code-completion results.
virtual CodeCompletionTUInfo & getCodeCompletionTUInfo()=0
bool includeCodePatterns() const
Whether the code-completion consumer wants to see code patterns.
bool loadExternal() const
Hint whether to load data from the external AST in order to provide full results.
const CodeCompleteOptions CodeCompleteOpts
bool includeBriefComments() const
Whether to include brief documentation comments within the set of code completions returned.
virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates, SourceLocation OpenParLoc, bool Braced)
Options controlling the behavior of code completion.
unsigned IncludeCodePatterns
Show code patterns in code completion results.
unsigned IncludeNamespaceLevelDecls
Show decls in namespace (including the global namespace) in code completion results.
unsigned IncludeFixIts
Include results after corrections (small fix-its), e.g.
unsigned LoadExternal
Hint whether to load data from the external AST to provide full results.
unsigned IncludeMacros
Show macros in code completion results.
unsigned IncludeBriefComments
Show brief documentation comments in code completion results.
unsigned IncludeGlobals
Show top-level decls in code completion results.
An allocator used specifically for the purpose of code completion.
const char * CopyString(const Twine &String)
Copy the given string into this allocator.
A builder class used to construct new code-completion strings.
CodeCompletionString * TakeString()
Take the resulting completion string.
CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, unsigned Priority, CXAvailabilityKind Availability)
void AddPlaceholderChunk(const char *Placeholder)
Add a new placeholder chunk.
CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo)
void AddTextChunk(const char *Text)
Add a new text chunk.
void addParentContext(const DeclContext *DC)
Add the parent context information to this code completion.
const char * getBriefComment() const
void addBriefComment(StringRef Comment)
void AddCurrentParameterChunk(const char *CurrentParameter)
Add a new current-parameter chunk.
CodeCompletionTUInfo & getCodeCompletionTUInfo() const
void AddResultTypeChunk(const char *ResultType)
Add a new result-type chunk.
void AddInformativeChunk(const char *Text)
Add a new informative chunk.
void AddOptionalChunk(CodeCompletionString *Optional)
Add a new optional chunk.
void AddTypedTextChunk(const char *Text)
Add a new typed-text chunk.
void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text="")
Add a new chunk.
CodeCompletionAllocator & getAllocator() const
Retrieve the allocator into which the code completion strings should be allocated.
The context in which code completion occurred, so that the code-completion consumer can process the r...
std::optional< const CXXScopeSpec * > getCXXScopeSpecifier()
Kind getKind() const
Retrieve the kind of code-completion context.
void setCXXScopeSpecifier(CXXScopeSpec SS)
Sets the scope specifier that comes before the completion token.
@ CCC_TypeQualifiers
Code completion within a type-qualifier list.
@ CCC_ObjCMessageReceiver
Code completion occurred where an Objective-C message receiver is expected.
@ CCC_PreprocessorExpression
Code completion occurred within a preprocessor expression.
@ CCC_ObjCCategoryName
Code completion where an Objective-C category name is expected.
@ CCC_ObjCIvarList
Code completion occurred within the instance variable list of an Objective-C interface,...
@ CCC_Statement
Code completion occurred where a statement (or declaration) is expected in a function,...
@ CCC_Type
Code completion occurred where a type name is expected.
@ CCC_ArrowMemberAccess
Code completion occurred on the right-hand side of a member access expression using the arrow operato...
@ CCC_ClassStructUnion
Code completion occurred within a class, struct, or union.
@ CCC_ObjCInterface
Code completion occurred within an Objective-C interface, protocol, or category interface.
@ CCC_ObjCPropertyAccess
Code completion occurred on the right-hand side of an Objective-C property access expression.
@ CCC_Expression
Code completion occurred where an expression is expected.
@ CCC_SelectorName
Code completion for a selector, as in an @selector expression.
@ CCC_TopLevelOrExpression
Code completion at a top level, i.e.
@ CCC_EnumTag
Code completion occurred after the "enum" keyword, to indicate an enumeration name.
@ CCC_UnionTag
Code completion occurred after the "union" keyword, to indicate a union name.
@ CCC_ParenthesizedExpression
Code completion in a parenthesized expression, which means that we may also have types here in C and ...
@ CCC_TopLevel
Code completion occurred within a "top-level" completion context, e.g., at namespace or global scope.
@ CCC_ClassOrStructTag
Code completion occurred after the "struct" or "class" keyword, to indicate a struct or class name.
@ CCC_ObjCClassMessage
Code completion where an Objective-C class message is expected.
@ CCC_ObjCImplementation
Code completion occurred within an Objective-C implementation or category implementation.
@ CCC_IncludedFile
Code completion inside the filename part of a #include directive.
@ CCC_ObjCInstanceMessage
Code completion where an Objective-C instance message is expected.
@ CCC_SymbolOrNewName
Code completion occurred where both a new name and an existing symbol is permissible.
@ CCC_Recovery
An unknown context, in which we are recovering from a parsing error and don't know which completions ...
@ CCC_ObjCProtocolName
Code completion occurred where a protocol name is expected.
@ CCC_OtherWithMacros
An unspecified code-completion context where we should also add macro completions.
@ CCC_NewName
Code completion occurred where a new name is expected.
@ CCC_MacroNameUse
Code completion occurred where a macro name is expected (without any arguments, in the case of a func...
@ CCC_Symbol
Code completion occurred where an existing name(such as type, function or variable) is expected.
@ CCC_Attribute
Code completion of an attribute name.
@ CCC_Other
An unspecified code-completion context.
@ CCC_DotMemberAccess
Code completion occurred on the right-hand side of a member access expression using the dot operator.
@ CCC_MacroName
Code completion occurred where an macro is being defined.
@ CCC_Namespace
Code completion occurred where a namespace or namespace alias is expected.
@ CCC_PreprocessorDirective
Code completion occurred where a preprocessor directive is expected.
@ CCC_NaturalLanguage
Code completion occurred in a context where natural language is expected, e.g., a comment or string l...
@ CCC_ObjCInterfaceName
Code completion where the name of an Objective-C class is expected.
QualType getBaseType() const
Retrieve the type of the base object in a member-access expression.
bool wantConstructorResults() const
Determines whether we want C++ constructors as results within this context.
QualType getPreferredType() const
Retrieve the type that this expression would prefer to have, e.g., if the expression is a variable in...
void addVisitedContext(DeclContext *Ctx)
Adds a visited context.
CodeCompletionContext(Kind CCKind, QualType T, ArrayRef< const IdentifierInfo * > SelIdents=std::nullopt)
Construct a new code-completion context of the given kind.
const VisitedContextSet & getVisitedContexts() const
Retrieves all visited contexts.
CodeCompletionContext(Kind CCKind)
Construct a new code-completion context of the given kind.
ArrayRef< const IdentifierInfo * > getSelIdents() const
Retrieve the Objective-C selector identifiers.
Captures a result of code completion.
bool DeclaringEntity
Whether we're completing a declaration of the given entity, rather than a use of that entity.
ResultKind Kind
The kind of result stored here.
const char * Keyword
When Kind == RK_Keyword, the string representing the keyword or symbol's spelling.
CXAvailabilityKind Availability
The availability of this result.
CodeCompletionResult(const char *Keyword, unsigned Priority=CCP_Keyword)
Build a result that refers to a keyword or symbol.
CodeCompletionResult(CodeCompletionString *Pattern, const NamedDecl *D, unsigned Priority)
Build a result that refers to a pattern with an associated declaration.
NestedNameSpecifier * Qualifier
If the result should have a nested-name-specifier, this is it.
CodeCompletionResult(const IdentifierInfo *Macro, const MacroInfo *MI=nullptr, unsigned Priority=CCP_Macro)
Build a result that refers to a macro.
const UsingShadowDecl * ShadowDecl
If this Decl was unshadowed by using declaration, this can store a pointer to the UsingShadowDecl whi...
CodeCompletionString * CreateCodeCompletionString(Sema &S, const CodeCompletionContext &CCContext, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments)
Create a new code-completion string that describes how to insert this result into a program.
bool QualifierIsInformative
Whether this result was found via lookup into a base class.
std::vector< FixItHint > FixIts
Fix-its that must be applied before inserting the text for the corresponding completion.
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.
const NamedDecl * Declaration
When Kind == RK_Declaration or RK_Pattern, the declaration we are referring to.
CodeCompletionString * createCodeCompletionStringForDecl(Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result, bool IncludeBriefComments, const CodeCompletionContext &CCContext, PrintingPolicy &Policy)
CodeCompletionString * CreateCodeCompletionStringForMacro(Preprocessor &PP, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo)
Creates a new code-completion string for the macro result.
unsigned StartParameter
Specifies which parameter (of a function, Objective-C method, macro, etc.) we should start with when ...
bool InBaseClass
Whether this is a class member from base class.
StringRef getOrderedName(std::string &Saved) const
Retrieve the name that should be used to order a result.
unsigned Priority
The priority of this particular code-completion result.
bool StartsNestedNameSpecifier
Whether this declaration is the beginning of a nested-name-specifier and, therefore,...
bool Hidden
Whether this result is hidden by another name.
CodeCompletionString * Pattern
When Kind == RK_Pattern, the code-completion string that describes the completion text to insert.
bool FunctionCanBeCall
When completing a function, whether it can be a call.
bool AllParametersAreInformative
Whether all parameters (of a function, Objective-C method, etc.) should be considered "informative".
const char * getKeyword() const
Retrieve the keyword stored in this result.
const NamedDecl * getDeclaration() const
Retrieve the declaration stored in this result.
CodeCompletionString * createCodeCompletionStringForOverride(Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result, bool IncludeBriefComments, const CodeCompletionContext &CCContext, PrintingPolicy &Policy)
const MacroInfo * MacroDefInfo
If the result is RK_Macro, this can store the information about the macro definition.
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.
CXCursorKind CursorKind
The cursor kind that describes this result.
const IdentifierInfo * Macro
When Kind == RK_Macro, the identifier that refers to a macro.
ResultKind
Describes the kind of result generated.
@ RK_Pattern
Refers to a precomputed pattern.
@ RK_Declaration
Refers to a declaration.
@ RK_Keyword
Refers to a keyword or symbol.
A "string" used to describe how code completion can be performed for an entity.
unsigned getPriority() const
Retrieve the priority of this code completion result.
CodeCompletionString(const CodeCompletionString &)=delete
ChunkKind
The different kinds of "chunks" that can occur within a code completion string.
@ CK_Optional
A code completion string that is entirely optional.
@ CK_CurrentParameter
A piece of text that describes the parameter that corresponds to the code-completion location within ...
@ CK_Comma
A comma separator (',').
@ CK_Text
A piece of text that should be placed in the buffer, e.g., parentheses or a comma in a function call.
@ CK_Placeholder
A string that acts as a placeholder for, e.g., a function call argument.
@ CK_LeftParen
A left parenthesis ('(').
@ CK_HorizontalSpace
Horizontal whitespace (' ').
@ CK_RightAngle
A right angle bracket ('>').
@ CK_Informative
A piece of text that describes something about the result but should not be inserted into the buffer.
@ CK_LeftBracket
A left bracket ('[').
@ CK_RightParen
A right parenthesis (')').
@ CK_RightBrace
A right brace ('}').
@ CK_VerticalSpace
Vertical whitespace ('\n' or '\r\n', depending on the platform).
@ CK_TypedText
The piece of text that the user is expected to type to match the code-completion string,...
@ CK_ResultType
A piece of text that describes the type of an entity or, for functions and methods,...
@ CK_RightBracket
A right bracket (']').
@ CK_LeftBrace
A left brace ('{').
@ CK_LeftAngle
A left angle bracket ('<').
const Chunk & operator[](unsigned I) const
std::string getAsString() const
Retrieve a string representation of the code completion string, which is mainly useful for debugging.
StringRef getParentContextName() const
Retrieve the name of the parent context.
std::string getAllTypedText() const
Returns the combined text from all TypedText chunks.
const char * getTypedText() const
Returns the text in the first TypedText chunk.
CodeCompletionString & operator=(const CodeCompletionString &)=delete
unsigned getAvailability() const
Retrieve the availability of this code completion result.
const char * getBriefComment() const
unsigned getAnnotationCount() const
Retrieve the number of annotations for this code completion result.
const char * getAnnotation(unsigned AnnotationNr) const
Retrieve the annotation string specified by AnnotationNr.
std::shared_ptr< GlobalCodeCompletionAllocator > getAllocatorRef() const
StringRef getParentName(const DeclContext *DC)
CodeCompletionTUInfo(std::shared_ptr< GlobalCodeCompletionAllocator > Allocator)
CodeCompletionAllocator & getAllocator() const
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1435
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
Represents a function declaration or definition.
Definition: Decl.h:1971
Declaration of a template function.
Definition: DeclTemplate.h:958
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:4046
Allocator for a cached set of global code completions.
One of these records is kept for each identifier that is lexed.
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
This represents a decl that may have a name.
Definition: Decl.h:249
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:128
A simple code-completion consumer that prints the results it receives in a simple format.
void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults) override
Prints the finalized code-completion results.
void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates, SourceLocation OpenParLoc, bool Braced) override
CodeCompletionTUInfo & getCodeCompletionTUInfo() override
CodeCompletionAllocator & getAllocator() override
Retrieve the allocator that will be used to allocate code completion strings.
bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results) override
PrintingCodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, raw_ostream &OS)
Create a new printing code-completion consumer that prints its results to the given raw output stream...
A (possibly-)qualified type.
Definition: Type.h:738
Represents a struct/union/class.
Definition: Decl.h:4169
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:434
Encodes a location in the source.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:394
The base class of the type hierarchy.
Definition: Type.h:1607
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3317
CXCursorKind
Describes the kind of entity that a cursor refers to.
Definition: Index.h:1186
CXAvailabilityKind
Describes the availability of a particular entity, which indicates whether the use of this entity wil...
Definition: Index.h:130
@ CXCursor_MacroDefinition
Definition: Index.h:2215
@ CXCursor_NotImplemented
Definition: Index.h:1384
@ CXAvailability_Available
The entity is available.
Definition: Index.h:134
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
The JSON file list parser is used to communicate input to InstallAPI.
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.
CXCursorKind getCursorKindForDecl(const Decl *D)
Determine the libclang cursor kind associated with the given declaration.
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.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
@ CCD_SelectorMatch
The selector of the given message exactly matches the selector of the current method,...
@ CCD_ObjectQualifierMatch
The result is a C++ non-static member function whose qualifiers exactly match the object type on whic...
@ CCD_bool_in_ObjC
Adjustment to the "bool" type in Objective-C, where the typedef "BOOL" is preferred.
@ CCD_InBaseClass
The result is in a base class.
@ CCD_ProbablyNotObjCCollection
Adjustment for KVC code pattern priorities when it doesn't look like the.
@ CCD_BlockPropertySetter
An Objective-C block property completed as a setter with a block placeholder.
@ CCD_MethodAsProperty
An Objective-C method being used as a property.
@ Result
The result type of a method or function.
SimplifiedTypeClass
A simplified classification of types used when determining "similar" types for code completion.
const RawComment * getPatternCompletionComment(const ASTContext &Ctx, const NamedDecl *Decl)
Get the documentation comment used to produce CodeCompletionString::BriefComment for RK_Pattern.
const RawComment * getCompletionComment(const ASTContext &Ctx, const NamedDecl *Decl)
Get the documentation comment used to produce CodeCompletionString::BriefComment for RK_Declaration.
SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T)
Determine the simplified type class of the given canonical type.
bool operator<=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
@ CCP_Type
Priority for a type.
@ CCP_ObjC_cmd
Priority for the Objective-C "_cmd" implicit parameter.
@ CCP_Keyword
Priority for a language keyword (that isn't any of the other categories).
@ CCP_Macro
Priority for a preprocessor macro.
@ CCP_LocalDeclaration
Priority for a declaration that is in the local scope.
@ CCP_Unlikely
Priority for a result that isn't likely to be what the user wants, but is included for completeness.
@ CCP_NestedNameSpecifier
Priority for a nested-name-specifier.
@ CCP_SuperCompletion
Priority for a send-to-super completion.
@ CCP_NextInitializer
Priority for the next initialization in a constructor initializer list.
@ CCP_Declaration
Priority for a non-type declaration.
@ CCP_Constant
Priority for a constant value (e.g., enumerator).
@ CCP_MemberDeclaration
Priority for a member declaration found from the current method or member function.
@ CCP_EnumInCase
Priority for an enumeration constant inside a switch whose condition is of the enumeration type.
@ CCP_CodePattern
Priority for a code pattern.
llvm::StringRef getCompletionKindString(CodeCompletionContext::Kind Kind)
Get string representation of Kind, useful for debugging.
bool operator>(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
@ CCF_ExactTypeMatch
Divide by this factor when a code-completion result's type exactly matches the type we expect.
@ CCF_SimilarTypeMatch
Divide by this factor when a code-completion result's type is similar to the type we expect (e....
const FunctionProtoType * T
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.
bool operator>=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
Definition: Format.h:5394
#define true
Definition: stdbool.h:21
#define false
Definition: stdbool.h:22
One piece of the code completion string.
static Chunk CreateOptional(CodeCompletionString *Optional)
Create a new optional chunk.
ChunkKind Kind
The kind of data stored in this piece of the code completion string.
static Chunk CreatePlaceholder(const char *Placeholder)
Create a new placeholder chunk.
static Chunk CreateCurrentParameter(const char *CurrentParameter)
Create a new current-parameter chunk.
static Chunk CreateInformative(const char *Informative)
Create a new informative chunk.
CodeCompletionString * Optional
The code completion string associated with a CK_Optional chunk.
static Chunk CreateResultType(const char *ResultType)
Create a new result type chunk.
const char * Text
The text string associated with a CK_Text, CK_Placeholder, CK_Informative, or CK_Comma chunk.
static Chunk CreateText(const char *Text)
Create a new text chunk.
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
Definition: Overload.h:849
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57