2017-12-04 21:49:59 +08:00
|
|
|
//===--- CodeComplete.h -----------------------------------------*- C++-*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Code completion provides suggestions for what the user might type next.
|
|
|
|
// After "std::string S; S." we might suggest members of std::string.
|
|
|
|
// Signature help describes the parameters of a function as you type them.
|
|
|
|
//
|
|
|
|
//===---------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETE_H
|
|
|
|
|
|
|
|
#include "Logger.h"
|
|
|
|
#include "Path.h"
|
|
|
|
#include "Protocol.h"
|
2017-12-20 00:50:37 +08:00
|
|
|
#include "index/Index.h"
|
2017-12-04 21:49:59 +08:00
|
|
|
#include "clang/Frontend/PrecompiledPreamble.h"
|
|
|
|
#include "clang/Sema/CodeCompleteOptions.h"
|
|
|
|
#include "clang/Tooling/CompilationDatabase.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
class PCHContainerOperations;
|
|
|
|
namespace clangd {
|
|
|
|
|
|
|
|
struct CodeCompleteOptions {
|
|
|
|
/// Returns options that can be passed to clang's completion engine.
|
|
|
|
clang::CodeCompleteOptions getClangCompleteOpts() const;
|
|
|
|
|
|
|
|
/// When true, completion items will contain expandable code snippets in
|
|
|
|
/// completion (e.g. `return ${1:expression}` or `foo(${1:int a}, ${2:int
|
|
|
|
/// b})).
|
|
|
|
bool EnableSnippets = false;
|
|
|
|
|
|
|
|
/// Add code patterns to completion results.
|
|
|
|
/// If EnableSnippets is false, this options is ignored and code patterns will
|
|
|
|
/// always be omitted.
|
|
|
|
bool IncludeCodePatterns = true;
|
|
|
|
|
|
|
|
/// Add macros to code completion results.
|
|
|
|
bool IncludeMacros = true;
|
|
|
|
|
|
|
|
/// Add brief comments to completion items, if available.
|
|
|
|
/// FIXME(ibiryukov): it looks like turning this option on significantly slows
|
|
|
|
/// down completion, investigate if it can be made faster.
|
|
|
|
bool IncludeBriefComments = true;
|
|
|
|
|
|
|
|
/// Include results that are not legal completions in the current context.
|
|
|
|
/// For example, private members are usually inaccessible.
|
|
|
|
bool IncludeIneligibleResults = false;
|
|
|
|
|
|
|
|
/// Limit the number of results returned (0 means no limit).
|
|
|
|
/// If more results are available, we set CompletionList.isIncomplete.
|
|
|
|
size_t Limit = 0;
|
2017-12-20 00:50:37 +08:00
|
|
|
|
|
|
|
// Populated internally by clangd, do not set.
|
|
|
|
/// If `Index` is set, it is used to augment the code completion
|
|
|
|
/// results.
|
|
|
|
/// FIXME(ioeric): we might want a better way to pass the index around inside
|
|
|
|
/// clangd.
|
|
|
|
const SymbolIndex *Index = nullptr;
|
2017-12-04 21:49:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Get code completions at a specified \p Pos in \p FileName.
|
[clangd] Pass Context implicitly using TLS.
Summary:
Instead of passing Context explicitly around, we now have a thread-local
Context object `Context::current()` which is an implicit argument to
every function.
Most manipulation of this should use the WithContextValue helper, which
augments the current Context to add a single KV pair, and restores the
old context on destruction.
Advantages are:
- less boilerplate in functions that just propagate contexts
- reading most code doesn't require understanding context at all, and
using context as values in fewer places still
- fewer options to pass the "wrong" context when it changes within a
scope (e.g. when using Span)
- contexts pass through interfaces we can't modify, such as VFS
- propagating contexts across threads was slightly tricky (e.g.
copy vs move, no move-init in lambdas), and is now encapsulated in
the threadpool
Disadvantages are all the usual TLS stuff - hidden magic, and
potential for higher memory usage on threads that don't use the
context. (In practice, it's just one pointer)
Reviewers: ilya-biryukov
Subscribers: klimek, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D42517
llvm-svn: 323872
2018-01-31 21:40:48 +08:00
|
|
|
CompletionList codeComplete(PathRef FileName,
|
2017-12-04 21:49:59 +08:00
|
|
|
const tooling::CompileCommand &Command,
|
|
|
|
PrecompiledPreamble const *Preamble,
|
|
|
|
StringRef Contents, Position Pos,
|
|
|
|
IntrusiveRefCntPtr<vfs::FileSystem> VFS,
|
|
|
|
std::shared_ptr<PCHContainerOperations> PCHs,
|
2017-12-13 20:51:22 +08:00
|
|
|
CodeCompleteOptions Opts);
|
2017-12-04 21:49:59 +08:00
|
|
|
|
|
|
|
/// Get signature help at a specified \p Pos in \p FileName.
|
[clangd] Pass Context implicitly using TLS.
Summary:
Instead of passing Context explicitly around, we now have a thread-local
Context object `Context::current()` which is an implicit argument to
every function.
Most manipulation of this should use the WithContextValue helper, which
augments the current Context to add a single KV pair, and restores the
old context on destruction.
Advantages are:
- less boilerplate in functions that just propagate contexts
- reading most code doesn't require understanding context at all, and
using context as values in fewer places still
- fewer options to pass the "wrong" context when it changes within a
scope (e.g. when using Span)
- contexts pass through interfaces we can't modify, such as VFS
- propagating contexts across threads was slightly tricky (e.g.
copy vs move, no move-init in lambdas), and is now encapsulated in
the threadpool
Disadvantages are all the usual TLS stuff - hidden magic, and
potential for higher memory usage on threads that don't use the
context. (In practice, it's just one pointer)
Reviewers: ilya-biryukov
Subscribers: klimek, jkorous-apple, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D42517
llvm-svn: 323872
2018-01-31 21:40:48 +08:00
|
|
|
SignatureHelp signatureHelp(PathRef FileName,
|
2017-12-13 20:51:22 +08:00
|
|
|
const tooling::CompileCommand &Command,
|
|
|
|
PrecompiledPreamble const *Preamble,
|
|
|
|
StringRef Contents, Position Pos,
|
|
|
|
IntrusiveRefCntPtr<vfs::FileSystem> VFS,
|
|
|
|
std::shared_ptr<PCHContainerOperations> PCHs);
|
2017-12-04 21:49:59 +08:00
|
|
|
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif
|