blob: 83f178b5703f029523d97e837cb2a686bf35a819 [file] [log] [blame]
Sam McCall98775c52017-12-04 13:49:59 +00001//===--- 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"
Eric Liu6f648df2017-12-19 16:50:37 +000021#include "index/Index.h"
Sam McCall98775c52017-12-04 13:49:59 +000022#include "clang/Frontend/PrecompiledPreamble.h"
23#include "clang/Sema/CodeCompleteOptions.h"
24#include "clang/Tooling/CompilationDatabase.h"
25
26namespace clang {
27class PCHContainerOperations;
28namespace clangd {
29
30struct 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
Sam McCall98775c52017-12-04 13:49:59 +000047 /// 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;
Eric Liu6f648df2017-12-19 16:50:37 +000059
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;
Sam McCall98775c52017-12-04 13:49:59 +000066};
67
68/// Get code completions at a specified \p Pos in \p FileName.
Sam McCalld1a7a372018-01-31 13:40:48 +000069CompletionList codeComplete(PathRef FileName,
Sam McCall98775c52017-12-04 13:49:59 +000070 const tooling::CompileCommand &Command,
71 PrecompiledPreamble const *Preamble,
72 StringRef Contents, Position Pos,
73 IntrusiveRefCntPtr<vfs::FileSystem> VFS,
74 std::shared_ptr<PCHContainerOperations> PCHs,
Ilya Biryukov940901e2017-12-13 12:51:22 +000075 CodeCompleteOptions Opts);
Sam McCall98775c52017-12-04 13:49:59 +000076
77/// Get signature help at a specified \p Pos in \p FileName.
Sam McCalld1a7a372018-01-31 13:40:48 +000078SignatureHelp signatureHelp(PathRef FileName,
Ilya Biryukov940901e2017-12-13 12:51:22 +000079 const tooling::CompileCommand &Command,
80 PrecompiledPreamble const *Preamble,
81 StringRef Contents, Position Pos,
82 IntrusiveRefCntPtr<vfs::FileSystem> VFS,
83 std::shared_ptr<PCHContainerOperations> PCHs);
Sam McCall98775c52017-12-04 13:49:59 +000084
85} // namespace clangd
86} // namespace clang
87
88#endif