LCOV - code coverage report
Current view: top level - clang/tools/extra/clangd - CodeComplete.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 0 5 0.0 %
Date: 2018-07-13 00:08:38 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===--- CodeComplete.h -----------------------------------------*- 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             : // Code completion provides suggestions for what the user might type next.
      11             : // After "std::string S; S." we might suggest members of std::string.
      12             : // Signature help describes the parameters of a function as you type them.
      13             : //
      14             : //===---------------------------------------------------------------------===//
      15             : #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
      16             : #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
      17             : 
      18             : #include "Headers.h"
      19             : #include "Logger.h"
      20             : #include "Path.h"
      21             : #include "Protocol.h"
      22             : #include "index/Index.h"
      23             : #include "clang/Frontend/PrecompiledPreamble.h"
      24             : #include "clang/Sema/CodeCompleteOptions.h"
      25             : #include "clang/Tooling/CompilationDatabase.h"
      26             : 
      27             : namespace clang {
      28             : class NamedDecl;
      29             : class PCHContainerOperations;
      30             : namespace clangd {
      31             : 
      32           0 : struct CodeCompleteOptions {
      33             :   /// Returns options that can be passed to clang's completion engine.
      34             :   clang::CodeCompleteOptions getClangCompleteOpts() const;
      35             : 
      36             :   /// When true, completion items will contain expandable code snippets in
      37             :   /// completion (e.g.  `return ${1:expression}` or `foo(${1:int a}, ${2:int
      38             :   /// b})).
      39             :   bool EnableSnippets = false;
      40             : 
      41             :   /// Add code patterns to completion results.
      42             :   /// If EnableSnippets is false, this options is ignored and code patterns will
      43             :   /// always be omitted.
      44             :   bool IncludeCodePatterns = true;
      45             : 
      46             :   /// Add macros to code completion results.
      47             :   bool IncludeMacros = true;
      48             : 
      49             :   /// Add comments to code completion results, if available.
      50             :   bool IncludeComments = true;
      51             : 
      52             :   /// Include results that are not legal completions in the current context.
      53             :   /// For example, private members are usually inaccessible.
      54             :   bool IncludeIneligibleResults = false;
      55             : 
      56             :   /// Combine overloads into a single completion item where possible.
      57             :   bool BundleOverloads = false;
      58             : 
      59             :   /// Limit the number of results returned (0 means no limit).
      60             :   /// If more results are available, we set CompletionList.isIncomplete.
      61             :   size_t Limit = 0;
      62             : 
      63             :   /// A visual indicator to prepend to the completion label to indicate whether
      64             :   /// completion result would trigger an #include insertion or not.
      65           0 :   struct IncludeInsertionIndicator {
      66             :     std::string Insert = "•";
      67             :     std::string NoInsert = " ";
      68             :   } IncludeIndicator;
      69             : 
      70             :   /// Expose origins of completion items in the label (for debugging).
      71             :   bool ShowOrigins = false;
      72             : 
      73             :   // Populated internally by clangd, do not set.
      74             :   /// If `Index` is set, it is used to augment the code completion
      75             :   /// results.
      76             :   /// FIXME(ioeric): we might want a better way to pass the index around inside
      77             :   /// clangd.
      78             :   const SymbolIndex *Index = nullptr;
      79             : };
      80             : 
      81             : // Semi-structured representation of a code-complete suggestion for our C++ API.
      82             : // We don't use the LSP structures here (unlike most features) as we want
      83             : // to expose more data to allow for more precise testing and evaluation.
      84           0 : struct CodeCompletion {
      85             :   // The unqualified name of the symbol or other completion item.
      86             :   std::string Name;
      87             :   // The scope qualifier for the symbol name. e.g. "ns1::ns2::"
      88             :   // Empty for non-symbol completions. Not inserted, but may be displayed.
      89             :   std::string Scope;
      90             :   // Text that must be inserted before the name, and displayed (e.g. base::).
      91             :   std::string RequiredQualifier;
      92             :   // Details to be displayed following the name. Not inserted.
      93             :   std::string Signature;
      94             :   // Text to be inserted following the name, in snippet format.
      95             :   std::string SnippetSuffix;
      96             :   // Type to be displayed for this completion.
      97             :   std::string ReturnType;
      98             :   std::string Documentation;
      99             :   CompletionItemKind Kind = CompletionItemKind::Missing;
     100             :   // This completion item may represent several symbols that can be inserted in
     101             :   // the same way, such as function overloads. In this case BundleSize > 1, and
     102             :   // the following fields are summaries:
     103             :   //  - Signature is e.g. "(...)" for functions.
     104             :   //  - SnippetSuffix is similarly e.g. "(${0})".
     105             :   //  - ReturnType may be empty
     106             :   //  - Documentation may be from one symbol, or a combination of several
     107             :   // Other fields should apply equally to all bundled completions.
     108             :   unsigned BundleSize = 1;
     109             :   SymbolOrigin Origin = SymbolOrigin::Unknown;
     110             :   // The header through which this symbol could be included.
     111             :   // Quoted string as expected by an #include directive, e.g. "<memory>".
     112             :   // Empty for non-symbol completions, or when not known.
     113             :   std::string Header;
     114             :   // Present if Header is set and should be inserted to use this item.
     115             :   llvm::Optional<TextEdit> HeaderInsertion;
     116             : 
     117             :   // Scores are used to rank completion items.
     118           0 :   struct Scores {
     119             :     // The score that items are ranked by.
     120             :     float Total = 0.f;
     121             : 
     122             :     // The finalScore with the fuzzy name match score excluded.
     123             :     // When filtering client-side, editors should calculate the new fuzzy score,
     124             :     // whose scale is 0-1 (with 1 = prefix match, special case 2 = exact match),
     125             :     // and recompute finalScore = fuzzyScore * symbolScore.
     126             :     float ExcludingName = 0.f;
     127             : 
     128             :     // Component scores that contributed to the final score:
     129             : 
     130             :     // Quality describes how important we think this candidate is,
     131             :     // independent of the query.
     132             :     // e.g. symbols with lots of incoming references have higher quality.
     133             :     float Quality = 0.f;
     134             :     // Relevance describes how well this candidate matched the query.
     135             :     // e.g. symbols from nearby files have higher relevance.
     136             :     float Relevance = 0.f;
     137             :   };
     138             :   Scores Score;
     139             : 
     140             :   // Serialize this to an LSP completion item. This is a lossy operation.
     141             :   CompletionItem render(const CodeCompleteOptions &) const;
     142             : };
     143             : raw_ostream &operator<<(raw_ostream &, const CodeCompletion &);
     144           0 : struct CodeCompleteResult {
     145             :   std::vector<CodeCompletion> Completions;
     146             :   bool HasMore = false;
     147             : };
     148             : raw_ostream &operator<<(raw_ostream &, const CodeCompleteResult &);
     149             : 
     150             : /// Get code completions at a specified \p Pos in \p FileName.
     151             : CodeCompleteResult codeComplete(PathRef FileName,
     152             :                                 const tooling::CompileCommand &Command,
     153             :                                 PrecompiledPreamble const *Preamble,
     154             :                                 const IncludeStructure &PreambleInclusions,
     155             :                                 StringRef Contents, Position Pos,
     156             :                                 IntrusiveRefCntPtr<vfs::FileSystem> VFS,
     157             :                                 std::shared_ptr<PCHContainerOperations> PCHs,
     158             :                                 CodeCompleteOptions Opts);
     159             : 
     160             : /// Get signature help at a specified \p Pos in \p FileName.
     161             : SignatureHelp signatureHelp(PathRef FileName,
     162             :                             const tooling::CompileCommand &Command,
     163             :                             PrecompiledPreamble const *Preamble,
     164             :                             StringRef Contents, Position Pos,
     165             :                             IntrusiveRefCntPtr<vfs::FileSystem> VFS,
     166             :                             std::shared_ptr<PCHContainerOperations> PCHs);
     167             : 
     168             : // For index-based completion, we only consider:
     169             : //   * symbols in namespaces or translation unit scopes (e.g. no class
     170             : //     members, no locals)
     171             : //   * enum constants in unscoped enum decl (e.g. "red" in "enum {red};")
     172             : //   * primary templates (no specializations)
     173             : // For the other cases, we let Clang do the completion because it does not
     174             : // need any non-local information and it will be much better at following
     175             : // lookup rules. Other symbols still appear in the index for other purposes,
     176             : // like workspace/symbols or textDocument/definition, but are not used for code
     177             : // completion.
     178             : bool isIndexedForCodeCompletion(const NamedDecl &ND, ASTContext &ASTCtx);
     179             : } // namespace clangd
     180             : } // namespace clang
     181             : 
     182             : #endif

Generated by: LCOV version 1.13