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 "Logger.h" 19 #include "Path.h" 20 #include "Protocol.h" 21 #include "index/Index.h" 22 #include "clang/Frontend/PrecompiledPreamble.h" 23 #include "clang/Sema/CodeCompleteOptions.h" 24 #include "clang/Tooling/CompilationDatabase.h" 25 26 namespace clang { 27 class PCHContainerOperations; 28 namespace clangd { 29 30 struct CodeCompleteOptions { 31 /// Returns options that can be passed to clang's completion engine. 32 clang::CodeCompleteOptions getClangCompleteOpts() const; 33 34 /// When true, completion items will contain expandable code snippets in 35 /// completion (e.g. `return ${1:expression}` or `foo(${1:int a}, ${2:int 36 /// b})). 37 bool EnableSnippets = false; 38 39 /// Add code patterns to completion results. 40 /// If EnableSnippets is false, this options is ignored and code patterns will 41 /// always be omitted. 42 bool IncludeCodePatterns = true; 43 44 /// Add macros to code completion results. 45 bool IncludeMacros = true; 46 47 /// Add brief comments to completion items, if available. 48 /// FIXME(ibiryukov): it looks like turning this option on significantly slows 49 /// down completion, investigate if it can be made faster. 50 bool IncludeBriefComments = 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 /// Limit the number of results returned (0 means no limit). 57 /// If more results are available, we set CompletionList.isIncomplete. 58 size_t Limit = 0; 59 60 // Populated internally by clangd, do not set. 61 /// If `Index` is set, it is used to augment the code completion 62 /// results. 63 /// FIXME(ioeric): we might want a better way to pass the index around inside 64 /// clangd. 65 const SymbolIndex *Index = nullptr; 66 }; 67 68 /// Get code completions at a specified \p Pos in \p FileName. 69 CompletionList codeComplete(PathRef FileName, 70 const tooling::CompileCommand &Command, 71 PrecompiledPreamble const *Preamble, 72 StringRef Contents, Position Pos, 73 IntrusiveRefCntPtr<vfs::FileSystem> VFS, 74 std::shared_ptr<PCHContainerOperations> PCHs, 75 CodeCompleteOptions Opts); 76 77 /// Get signature help at a specified \p Pos in \p FileName. 78 SignatureHelp signatureHelp(PathRef FileName, 79 const tooling::CompileCommand &Command, 80 PrecompiledPreamble const *Preamble, 81 StringRef Contents, Position Pos, 82 IntrusiveRefCntPtr<vfs::FileSystem> VFS, 83 std::shared_ptr<PCHContainerOperations> PCHs); 84 85 } // namespace clangd 86 } // namespace clang 87 88 #endif 89