blob: 52ec01880c54029752f5a96c38aa58712178d085 [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
Ilya Biryukov940901e2017-12-13 12:51:22 +000018#include "Context.h"
Sam McCall98775c52017-12-04 13:49:59 +000019#include "Logger.h"
20#include "Path.h"
21#include "Protocol.h"
Eric Liu6f648df2017-12-19 16:50:37 +000022#include "index/Index.h"
Sam McCall98775c52017-12-04 13:49:59 +000023#include "clang/Frontend/PrecompiledPreamble.h"
24#include "clang/Sema/CodeCompleteOptions.h"
25#include "clang/Tooling/CompilationDatabase.h"
26
27namespace clang {
28class PCHContainerOperations;
29namespace clangd {
30
31struct CodeCompleteOptions {
32 /// Returns options that can be passed to clang's completion engine.
33 clang::CodeCompleteOptions getClangCompleteOpts() const;
34
35 /// When true, completion items will contain expandable code snippets in
36 /// completion (e.g. `return ${1:expression}` or `foo(${1:int a}, ${2:int
37 /// b})).
38 bool EnableSnippets = false;
39
40 /// Add code patterns to completion results.
41 /// If EnableSnippets is false, this options is ignored and code patterns will
42 /// always be omitted.
43 bool IncludeCodePatterns = true;
44
45 /// Add macros to code completion results.
46 bool IncludeMacros = true;
47
48 /// Add globals to code completion results.
49 bool IncludeGlobals = true;
50
51 /// Add brief comments to completion items, if available.
52 /// FIXME(ibiryukov): it looks like turning this option on significantly slows
53 /// down completion, investigate if it can be made faster.
54 bool IncludeBriefComments = true;
55
56 /// Include results that are not legal completions in the current context.
57 /// For example, private members are usually inaccessible.
58 bool IncludeIneligibleResults = false;
59
60 /// Limit the number of results returned (0 means no limit).
61 /// If more results are available, we set CompletionList.isIncomplete.
62 size_t Limit = 0;
Eric Liu6f648df2017-12-19 16:50:37 +000063
64 // Populated internally by clangd, do not set.
65 /// If `Index` is set, it is used to augment the code completion
66 /// results.
67 /// FIXME(ioeric): we might want a better way to pass the index around inside
68 /// clangd.
69 const SymbolIndex *Index = nullptr;
Sam McCall98775c52017-12-04 13:49:59 +000070};
71
72/// Get code completions at a specified \p Pos in \p FileName.
Ilya Biryukov940901e2017-12-13 12:51:22 +000073CompletionList codeComplete(const Context &Ctx, PathRef FileName,
Sam McCall98775c52017-12-04 13:49:59 +000074 const tooling::CompileCommand &Command,
75 PrecompiledPreamble const *Preamble,
76 StringRef Contents, Position Pos,
77 IntrusiveRefCntPtr<vfs::FileSystem> VFS,
78 std::shared_ptr<PCHContainerOperations> PCHs,
Ilya Biryukov940901e2017-12-13 12:51:22 +000079 CodeCompleteOptions Opts);
Sam McCall98775c52017-12-04 13:49:59 +000080
81/// Get signature help at a specified \p Pos in \p FileName.
Ilya Biryukov940901e2017-12-13 12:51:22 +000082SignatureHelp signatureHelp(const Context &Ctx, PathRef FileName,
83 const tooling::CompileCommand &Command,
84 PrecompiledPreamble const *Preamble,
85 StringRef Contents, Position Pos,
86 IntrusiveRefCntPtr<vfs::FileSystem> VFS,
87 std::shared_ptr<PCHContainerOperations> PCHs);
Sam McCall98775c52017-12-04 13:49:59 +000088
89} // namespace clangd
90} // namespace clang
91
92#endif