clang-tools  8.0.0
ClangdMain.cpp
Go to the documentation of this file.
1 //===--- ClangdMain.cpp - clangd server loop ------------------------------===//
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 #include "Features.inc"
11 #include "ClangdLSPServer.h"
12 #include "Path.h"
13 #include "Trace.h"
14 #include "Transport.h"
15 #include "index/Serialization.h"
16 #include "clang/Basic/Version.h"
17 #include "llvm/Support/CommandLine.h"
18 #include "llvm/Support/FileSystem.h"
19 #include "llvm/Support/Path.h"
20 #include "llvm/Support/Program.h"
21 #include "llvm/Support/Signals.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include <cstdlib>
24 #include <iostream>
25 #include <memory>
26 #include <string>
27 #include <thread>
28 
29 namespace clang {
30 namespace clangd {
31 // FIXME: remove this option when Dex is cheap enough.
32 static llvm::cl::opt<bool>
33  UseDex("use-dex-index",
34  llvm::cl::desc("Use experimental Dex dynamic index."),
35  llvm::cl::init(false), llvm::cl::Hidden);
36 
37 static llvm::cl::opt<Path> CompileCommandsDir(
38  "compile-commands-dir",
39  llvm::cl::desc("Specify a path to look for compile_commands.json. If path "
40  "is invalid, clangd will look in the current directory and "
41  "parent paths of each source file."));
42 
43 static llvm::cl::opt<unsigned>
45  llvm::cl::desc("Number of async workers used by clangd"),
46  llvm::cl::init(getDefaultAsyncThreadsCount()));
47 
48 // FIXME: also support "plain" style where signatures are always omitted.
50 static llvm::cl::opt<CompletionStyleFlag> CompletionStyle(
51  "completion-style",
52  llvm::cl::desc("Granularity of code completion suggestions"),
53  llvm::cl::values(
54  clEnumValN(Detailed, "detailed",
55  "One completion item for each semantically distinct "
56  "completion, with full type information."),
57  clEnumValN(Bundled, "bundled",
58  "Similar completion items (e.g. function overloads) are "
59  "combined. Type information shown where possible.")),
60  llvm::cl::init(Detailed));
61 
62 // FIXME: Flags are the wrong mechanism for user preferences.
63 // We should probably read a dotfile or similar.
64 static llvm::cl::opt<bool> IncludeIneligibleResults(
65  "include-ineligible-results",
66  llvm::cl::desc(
67  "Include ineligible completion results (e.g. private members)"),
69  llvm::cl::Hidden);
70 
71 static llvm::cl::opt<JSONStreamStyle> InputStyle(
72  "input-style", llvm::cl::desc("Input JSON stream encoding"),
73  llvm::cl::values(
74  clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP protocol"),
75  clEnumValN(JSONStreamStyle::Delimited, "delimited",
76  "messages delimited by --- lines, with # comment support")),
77  llvm::cl::init(JSONStreamStyle::Standard));
78 
79 static llvm::cl::opt<bool>
80  PrettyPrint("pretty", llvm::cl::desc("Pretty-print JSON output"),
81  llvm::cl::init(false));
82 
83 static llvm::cl::opt<Logger::Level> LogLevel(
84  "log", llvm::cl::desc("Verbosity of log messages written to stderr"),
85  llvm::cl::values(clEnumValN(Logger::Error, "error", "Error messages only"),
86  clEnumValN(Logger::Info, "info",
87  "High level execution tracing"),
88  clEnumValN(Logger::Debug, "verbose", "Low level details")),
89  llvm::cl::init(Logger::Info));
90 
91 static llvm::cl::opt<bool>
92  Test("lit-test",
93  llvm::cl::desc("Abbreviation for -input-style=delimited -pretty "
94  "-run-synchronously -enable-test-scheme. "
95  "Intended to simplify lit tests."),
96  llvm::cl::init(false), llvm::cl::Hidden);
97 
98 static llvm::cl::opt<bool> EnableTestScheme(
99  "enable-test-uri-scheme",
100  llvm::cl::desc("Enable 'test:' URI scheme. Only use in lit tests."),
101  llvm::cl::init(false), llvm::cl::Hidden);
102 
104 static llvm::cl::opt<PCHStorageFlag> PCHStorage(
105  "pch-storage",
106  llvm::cl::desc("Storing PCHs in memory increases memory usages, but may "
107  "improve performance"),
108  llvm::cl::values(
109  clEnumValN(PCHStorageFlag::Disk, "disk", "store PCHs on disk"),
110  clEnumValN(PCHStorageFlag::Memory, "memory", "store PCHs in memory")),
111  llvm::cl::init(PCHStorageFlag::Disk));
112 
113 static llvm::cl::opt<int> LimitResults(
114  "limit-results",
115  llvm::cl::desc("Limit the number of results returned by clangd. "
116  "0 means no limit."),
117  llvm::cl::init(100));
118 
119 static llvm::cl::opt<bool> RunSynchronously(
120  "run-synchronously",
121  llvm::cl::desc("Parse on main thread. If set, -j is ignored"),
122  llvm::cl::init(false), llvm::cl::Hidden);
123 
124 static llvm::cl::opt<Path>
125  ResourceDir("resource-dir",
126  llvm::cl::desc("Directory for system clang headers"),
127  llvm::cl::init(""), llvm::cl::Hidden);
128 
129 static llvm::cl::opt<Path> InputMirrorFile(
130  "input-mirror-file",
131  llvm::cl::desc(
132  "Mirror all LSP input to the specified file. Useful for debugging."),
133  llvm::cl::init(""), llvm::cl::Hidden);
134 
135 static llvm::cl::opt<bool> EnableIndex(
136  "index",
137  llvm::cl::desc(
138  "Enable index-based features. By default, clangd maintains an index "
139  "built from symbols in opened files. Global index support needs to "
140  "enabled separatedly."),
141  llvm::cl::init(true), llvm::cl::Hidden);
142 
143 static llvm::cl::opt<bool> AllScopesCompletion(
144  "all-scopes-completion",
145  llvm::cl::desc(
146  "If set to true, code completion will include index symbols that are "
147  "not defined in the scopes (e.g. "
148  "namespaces) visible from the code completion point. Such completions "
149  "can insert scope qualifiers."),
150  llvm::cl::init(true));
151 
152 static llvm::cl::opt<bool> ShowOrigins(
153  "debug-origin", llvm::cl::desc("Show origins of completion items"),
154  llvm::cl::init(CodeCompleteOptions().ShowOrigins), llvm::cl::Hidden);
155 
156 static llvm::cl::opt<bool> HeaderInsertionDecorators(
157  "header-insertion-decorators",
158  llvm::cl::desc("Prepend a circular dot or space before the completion "
159  "label, depending on whether "
160  "an include line will be inserted or not."),
161  llvm::cl::init(true));
162 
163 static llvm::cl::opt<Path> IndexFile(
164  "index-file",
165  llvm::cl::desc(
166  "Index file to build the static index. The file must have been created "
167  "by a compatible clangd-index.\n"
168  "WARNING: This option is experimental only, and will be removed "
169  "eventually. Don't rely on it."),
170  llvm::cl::init(""), llvm::cl::Hidden);
171 
172 static llvm::cl::opt<bool> EnableBackgroundIndex(
173  "background-index",
174  llvm::cl::desc(
175  "Index project code in the background and persist index on disk. "
176  "Experimental"),
177  llvm::cl::init(false), llvm::cl::Hidden);
178 
179 static llvm::cl::opt<int> BackgroundIndexRebuildPeriod(
180  "background-index-rebuild-period",
181  llvm::cl::desc(
182  "If set to non-zero, the background index rebuilds the symbol index "
183  "periodically every X milliseconds; otherwise, the "
184  "symbol index will be updated for each indexed file."),
185  llvm::cl::init(5000), llvm::cl::Hidden);
186 
188 static llvm::cl::opt<CompileArgsFrom> CompileArgsFrom(
189  "compile_args_from", llvm::cl::desc("The source of compile commands"),
190  llvm::cl::values(clEnumValN(LSPCompileArgs, "lsp",
191  "All compile commands come from LSP and "
192  "'compile_commands.json' files are ignored"),
193  clEnumValN(FilesystemCompileArgs, "filesystem",
194  "All compile commands come from the "
195  "'compile_commands.json' files")),
196  llvm::cl::init(FilesystemCompileArgs), llvm::cl::Hidden);
197 
198 static llvm::cl::opt<bool> EnableFunctionArgSnippets(
199  "function-arg-placeholders",
200  llvm::cl::desc("When disabled, completions contain only parentheses for "
201  "function calls. When enabled, completions also contain "
202  "placeholders for method parameters."),
204 
205 namespace {
206 
207 /// \brief Supports a test URI scheme with relaxed constraints for lit tests.
208 /// The path in a test URI will be combined with a platform-specific fake
209 /// directory to form an absolute path. For example, test:///a.cpp is resolved
210 /// C:\clangd-test\a.cpp on Windows and /clangd-test/a.cpp on Unix.
211 class TestScheme : public URIScheme {
212 public:
213  llvm::Expected<std::string>
214  getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
215  llvm::StringRef /*HintPath*/) const override {
216  using namespace llvm::sys;
217  // Still require "/" in body to mimic file scheme, as we want lengths of an
218  // equivalent URI in both schemes to be the same.
219  if (!Body.startswith("/"))
220  return llvm::make_error<llvm::StringError>(
221  "Expect URI body to be an absolute path starting with '/': " + Body,
222  llvm::inconvertibleErrorCode());
223  Body = Body.ltrim('/');
224  llvm::SmallVector<char, 16> Path(Body.begin(), Body.end());
225  path::native(Path);
226  fs::make_absolute(TestScheme::TestDir, Path);
227  return std::string(Path.begin(), Path.end());
228  }
229 
230  llvm::Expected<URI>
231  uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
232  llvm::StringRef Body = AbsolutePath;
233  if (!Body.consume_front(TestScheme::TestDir)) {
234  return llvm::make_error<llvm::StringError>(
235  "Path " + AbsolutePath + " doesn't start with root " + TestDir,
236  llvm::inconvertibleErrorCode());
237  }
238 
239  return URI("test", /*Authority=*/"",
240  llvm::sys::path::convert_to_slash(Body));
241  }
242 
243 private:
244  const static char TestDir[];
245 };
246 
247 #ifdef _WIN32
248 const char TestScheme::TestDir[] = "C:\\clangd-test";
249 #else
250 const char TestScheme::TestDir[] = "/clangd-test";
251 #endif
252 
253 } // namespace
254 } // namespace clangd
255 } // namespace clang
256 
257 enum class ErrorResultCode : int {
258  NoShutdownRequest = 1,
260 };
261 
262 int main(int argc, char *argv[]) {
263  using namespace clang;
264  using namespace clang::clangd;
265 
266  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
267  llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
268  OS << clang::getClangToolFullVersion("clangd") << "\n";
269  });
270  llvm::cl::ParseCommandLineOptions(
271  argc, argv,
272  "clangd is a language server that provides IDE-like features to editors. "
273  "\n\nIt should be used via an editor plugin rather than invoked "
274  "directly. "
275  "For more information, see:"
276  "\n\thttps://clang.llvm.org/extra/clangd.html"
277  "\n\thttps://microsoft.github.io/language-server-protocol/");
278  if (Test) {
279  RunSynchronously = true;
281  PrettyPrint = true;
282  preventThreadStarvationInTests(); // Ensure background index makes progress.
283  }
284  if (Test || EnableTestScheme) {
285  static URISchemeRegistry::Add<TestScheme> X(
286  "test", "Test scheme for clangd lit tests.");
287  }
288 
289  if (!RunSynchronously && WorkerThreadsCount == 0) {
290  llvm::errs() << "A number of worker threads cannot be 0. Did you mean to "
291  "specify -run-synchronously?";
292  return 1;
293  }
294 
295  if (RunSynchronously) {
296  if (WorkerThreadsCount.getNumOccurrences())
297  llvm::errs() << "Ignoring -j because -run-synchronously is set.\n";
298  WorkerThreadsCount = 0;
299  }
300 
301  // Validate command line arguments.
302  llvm::Optional<llvm::raw_fd_ostream> InputMirrorStream;
303  if (!InputMirrorFile.empty()) {
304  std::error_code EC;
305  InputMirrorStream.emplace(InputMirrorFile, /*ref*/ EC,
306  llvm::sys::fs::FA_Read | llvm::sys::fs::FA_Write);
307  if (EC) {
308  InputMirrorStream.reset();
309  llvm::errs() << "Error while opening an input mirror file: "
310  << EC.message();
311  } else {
312  InputMirrorStream->SetUnbuffered();
313  }
314  }
315 
316  // Setup tracing facilities if CLANGD_TRACE is set. In practice enabling a
317  // trace flag in your editor's config is annoying, launching with
318  // `CLANGD_TRACE=trace.json vim` is easier.
319  llvm::Optional<llvm::raw_fd_ostream> TraceStream;
320  std::unique_ptr<trace::EventTracer> Tracer;
321  if (auto *TraceFile = getenv("CLANGD_TRACE")) {
322  std::error_code EC;
323  TraceStream.emplace(TraceFile, /*ref*/ EC,
324  llvm::sys::fs::FA_Read | llvm::sys::fs::FA_Write);
325  if (EC) {
326  TraceStream.reset();
327  llvm::errs() << "Error while opening trace file " << TraceFile << ": "
328  << EC.message();
329  } else {
330  Tracer = trace::createJSONTracer(*TraceStream, PrettyPrint);
331  }
332  }
333 
334  llvm::Optional<trace::Session> TracingSession;
335  if (Tracer)
336  TracingSession.emplace(*Tracer);
337 
338  // Use buffered stream to stderr (we still flush each log message). Unbuffered
339  // stream can cause significant (non-deterministic) latency for the logger.
340  llvm::errs().SetBuffered();
341  StreamLogger Logger(llvm::errs(), LogLevel);
343 
344  // If --compile-commands-dir arg was invoked, check value and override default
345  // path.
346  llvm::Optional<Path> CompileCommandsDirPath;
347  if (!CompileCommandsDir.empty()) {
348  if (llvm::sys::fs::exists(CompileCommandsDir)) {
349  // We support passing both relative and absolute paths to the
350  // --compile-commands-dir argument, but we assume the path is absolute in
351  // the rest of clangd so we make sure the path is absolute before
352  // continuing.
353  llvm::SmallString<128> Path(CompileCommandsDir);
354  if (std::error_code EC = llvm::sys::fs::make_absolute(Path)) {
355  llvm::errs() << "Error while converting the relative path specified by "
356  "--compile-commands-dir to an absolute path: "
357  << EC.message() << ". The argument will be ignored.\n";
358  } else {
359  CompileCommandsDirPath = Path.str();
360  }
361  } else {
362  llvm::errs()
363  << "Path specified by --compile-commands-dir does not exist. The "
364  "argument will be ignored.\n";
365  }
366  }
367 
369  switch (PCHStorage) {
371  Opts.StorePreamblesInMemory = true;
372  break;
374  Opts.StorePreamblesInMemory = false;
375  break;
376  }
377  if (!ResourceDir.empty())
378  Opts.ResourceDir = ResourceDir;
383  std::unique_ptr<SymbolIndex> StaticIdx;
384  std::future<void> AsyncIndexLoad; // Block exit while loading the index.
385  if (EnableIndex && !IndexFile.empty()) {
386  // Load the index asynchronously. Meanwhile SwapIndex returns no results.
387  SwapIndex *Placeholder;
388  StaticIdx.reset(Placeholder = new SwapIndex(llvm::make_unique<MemIndex>()));
389  AsyncIndexLoad = runAsync<void>([Placeholder] {
390  if (auto Idx = loadIndex(IndexFile, /*UseDex=*/true))
391  Placeholder->reset(std::move(Idx));
392  });
393  if (RunSynchronously)
394  AsyncIndexLoad.wait();
395  }
396  Opts.StaticIndex = StaticIdx.get();
398 
401  CCOpts.Limit = LimitResults;
403  CCOpts.ShowOrigins = ShowOrigins;
405  CCOpts.IncludeIndicator.Insert.clear();
406  CCOpts.IncludeIndicator.NoInsert.clear();
407  }
408  CCOpts.SpeculativeIndexRequest = Opts.StaticIndex;
411 
412  // Initialize and run ClangdLSPServer.
413  // Change stdin to binary to not lose \r\n on windows.
414  llvm::sys::ChangeStdinToBinary();
415 
416  std::unique_ptr<Transport> TransportLayer;
417  if (getenv("CLANGD_AS_XPC_SERVICE")) {
418 #if CLANGD_BUILD_XPC
419  TransportLayer = newXPCTransport();
420 #else
421  llvm::errs() << "This clangd binary wasn't built with XPC support.\n";
423 #endif
424  } else {
425  TransportLayer = newJSONTransport(
426  stdin, llvm::outs(),
427  InputMirrorStream ? InputMirrorStream.getPointer() : nullptr,
429  }
430 
431  ClangdLSPServer LSPServer(
432  *TransportLayer, CCOpts, CompileCommandsDirPath,
433  /*UseDirBasedCDB=*/CompileArgsFrom == FilesystemCompileArgs, Opts);
434  llvm::set_thread_name("clangd.main");
435  return LSPServer.run() ? 0
436  : static_cast<int>(ErrorResultCode::NoShutdownRequest);
437 }
bool ShowOrigins
Expose origins of completion items in the label (for debugging).
Definition: CodeComplete.h:79
bool BundleOverloads
Combine overloads into a single completion item where possible.
Definition: CodeComplete.h:65
size_t Limit
Limit the number of results returned (0 means no limit).
Definition: CodeComplete.h:69
ErrorResultCode
Definition: ClangdMain.cpp:257
int main(int argc, char *argv[])
Definition: ClangdMain.cpp:262
std::unique_ptr< SymbolIndex > loadIndex(llvm::StringRef SymbolFilename, bool UseDex)
bool BackgroundIndex
If true, ClangdServer automatically indexes files in the current project on background threads...
Definition: ClangdServer.h:87
static llvm::cl::opt< int > BackgroundIndexRebuildPeriod("background-index-rebuild-period", llvm::cl::desc("If set to non-zero, the background index rebuilds the symbol index " "periodically every X milliseconds; otherwise, the " "symbol index will be updated for each indexed file."), llvm::cl::init(5000), llvm::cl::Hidden)
void preventThreadStarvationInTests()
Definition: Threading.cpp:142
static llvm::cl::opt< JSONStreamStyle > InputStyle("input-style", llvm::cl::desc("Input JSON stream encoding"), llvm::cl::values(clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP protocol"), clEnumValN(JSONStreamStyle::Delimited, "delimited", "messages delimited by --- lines, with # comment support")), llvm::cl::init(JSONStreamStyle::Standard))
static llvm::cl::opt< int > LimitResults("limit-results", llvm::cl::desc("Limit the number of results returned by clangd. " "0 means no limit."), llvm::cl::init(100))
URIScheme is an extension point for teaching clangd to recognize a custom URI scheme.
Definition: URI.h:105
std::unique_ptr< Transport > newXPCTransport()
static llvm::cl::opt< CompletionStyleFlag > CompletionStyle("completion-style", llvm::cl::desc("Granularity of code completion suggestions"), llvm::cl::values(clEnumValN(Detailed, "detailed", "One completion item for each semantically distinct " "completion, with full type information."), clEnumValN(Bundled, "bundled", "Similar completion items (e.g. function overloads) are " "combined. Type information shown where possible.")), llvm::cl::init(Detailed))
def make_absolute(f, directory)
unsigned AsyncThreadsCount
To process requests asynchronously, ClangdServer spawns worker threads.
Definition: ClangdServer.h:71
bool BuildDynamicSymbolIndex
If true, ClangdServer builds a dynamic in-memory index for symbols in opened files and uses the index...
Definition: ClangdServer.h:81
static llvm::cl::opt< bool > AllScopesCompletion("all-scopes-completion", llvm::cl::desc("If set to true, code completion will include index symbols that are " "not defined in the scopes (e.g. " "namespaces) visible from the code completion point. Such completions " "can insert scope qualifiers."), llvm::cl::init(true))
static llvm::cl::opt< Logger::Level > LogLevel("log", llvm::cl::desc("Verbosity of log messages written to stderr"), llvm::cl::values(clEnumValN(Logger::Error, "error", "Error messages only"), clEnumValN(Logger::Info, "info", "High level execution tracing"), clEnumValN(Logger::Debug, "verbose", "Low level details")), llvm::cl::init(Logger::Info))
static llvm::cl::opt< bool > PrettyPrint("pretty", llvm::cl::desc("Pretty-print JSON output"), llvm::cl::init(false))
static ClangTidyModuleRegistry::Add< AbseilModule > X("abseil-module", "Add Abseil checks.")
static llvm::cl::opt< bool > UseDex("use-dex-index", llvm::cl::desc("Use experimental Dex dynamic index."), llvm::cl::init(false), llvm::cl::Hidden)
static llvm::cl::opt< Path > InputMirrorFile("input-mirror-file", llvm::cl::desc("Mirror all LSP input to the specified file. Useful for debugging."), llvm::cl::init(""), llvm::cl::Hidden)
static llvm::cl::opt< unsigned > WorkerThreadsCount("j", llvm::cl::desc("Number of async workers used by clangd"), llvm::cl::init(getDefaultAsyncThreadsCount()))
Interface to allow custom logging in clangd.
Definition: Logger.h:24
bool SpeculativeIndexRequest
If set to true, this will send an asynchronous speculative index request, based on the index request ...
Definition: CodeComplete.h:89
static llvm::cl::opt< bool > ShowOrigins("debug-origin", llvm::cl::desc("Show origins of completion items"), llvm::cl::init(CodeCompleteOptions().ShowOrigins), llvm::cl::Hidden)
static llvm::cl::opt< bool > EnableTestScheme("enable-test-uri-scheme", llvm::cl::desc("Enable 'test:' URI scheme. Only use in lit tests."), llvm::cl::init(false), llvm::cl::Hidden)
std::string Path
A typedef to represent a file path.
Definition: Path.h:21
Only one LoggingSession can be active at a time.
Definition: Logger.h:78
bool IncludeIneligibleResults
Include results that are not legal completions in the current context.
Definition: CodeComplete.h:62
std::unique_ptr< Transport > newJSONTransport(std::FILE *In, llvm::raw_ostream &Out, llvm::raw_ostream *InMirror, bool Pretty, JSONStreamStyle Style)
static llvm::cl::opt< bool > RunSynchronously("run-synchronously", llvm::cl::desc("Parse on main thread. If set, -j is ignored"), llvm::cl::init(false), llvm::cl::Hidden)
size_t BackgroundIndexRebuildPeriodMs
If set to non-zero, the background index rebuilds the symbol index periodically every BuildIndexPerio...
Definition: ClangdServer.h:91
static llvm::cl::opt< Path > ResourceDir("resource-dir", llvm::cl::desc("Directory for system clang headers"), llvm::cl::init(""), llvm::cl::Hidden)
bool HeavyweightDynamicSymbolIndex
Use a heavier and faster in-memory index implementation.
Definition: ClangdServer.h:84
unsigned getDefaultAsyncThreadsCount()
Returns a number of a default async threads to use for TUScheduler.
static llvm::cl::opt< PCHStorageFlag > PCHStorage("pch-storage", llvm::cl::desc("Storing PCHs in memory increases memory usages, but may " "improve performance"), llvm::cl::values(clEnumValN(PCHStorageFlag::Disk, "disk", "store PCHs on disk"), clEnumValN(PCHStorageFlag::Memory, "memory", "store PCHs in memory")), llvm::cl::init(PCHStorageFlag::Disk))
static llvm::cl::opt< bool > IncludeIneligibleResults("include-ineligible-results", llvm::cl::desc("Include ineligible completion results (e.g. private members)"), llvm::cl::init(CodeCompleteOptions().IncludeIneligibleResults), llvm::cl::Hidden)
bool StorePreamblesInMemory
Cached preambles are potentially large. If false, store them on disk.
Definition: ClangdServer.h:77
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Optional< std::string > ResourceDir
The resource directory is used to find internal headers, overriding defaults and -resource-dir compil...
Definition: ClangdServer.h:105
std::unique_ptr< EventTracer > createJSONTracer(llvm::raw_ostream &OS, bool Pretty)
Create an instance of EventTracer that produces an output in the Trace Event format supported by Chro...
Definition: Trace.cpp:200
static llvm::cl::opt< bool > Test("lit-test", llvm::cl::desc("Abbreviation for -input-style=delimited -pretty " "-run-synchronously -enable-test-scheme. " "Intended to simplify lit tests."), llvm::cl::init(false), llvm::cl::Hidden)
struct clang::clangd::CodeCompleteOptions::IncludeInsertionIndicator IncludeIndicator
A URI describes the location of a source file.
Definition: URI.h:29
static llvm::cl::opt< bool > HeaderInsertionDecorators("header-insertion-decorators", llvm::cl::desc("Prepend a circular dot or space before the completion " "label, depending on whether " "an include line will be inserted or not."), llvm::cl::init(true))
static llvm::cl::opt< bool > EnableFunctionArgSnippets("function-arg-placeholders", llvm::cl::desc("When disabled, completions contain only parentheses for " "function calls. When enabled, completions also contain " "placeholders for method parameters."), llvm::cl::init(CodeCompleteOptions().EnableFunctionArgSnippets))
bool EnableFunctionArgSnippets
Whether to generate snippets for function arguments on code-completion.
Definition: CodeComplete.h:104
static llvm::cl::opt< bool > EnableIndex("index", llvm::cl::desc("Enable index-based features. By default, clangd maintains an index " "built from symbols in opened files. Global index support needs to " "enabled separatedly."), llvm::cl::init(true), llvm::cl::Hidden)
static llvm::cl::opt< Path > IndexFile("index-file", llvm::cl::desc("Index file to build the static index. The file must have been created " "by a compatible clangd-index.\ "WARNING:This option is experimental only, and will be removed " "eventually. Don 't rely on it."), llvm::cl::init(""), llvm::cl::Hidden)
static llvm::cl::opt< bool > EnableBackgroundIndex("background-index", llvm::cl::desc("Index project code in the background and persist index on disk. " "Experimental"), llvm::cl::init(false), llvm::cl::Hidden)
bool AllScopes
Whether to include index symbols that are not defined in the scopes visible from the code completion ...
Definition: CodeComplete.h:111
This class exposes ClangdServer&#39;s capabilities via Language Server Protocol.
static llvm::cl::opt< Path > CompileCommandsDir("compile-commands-dir", llvm::cl::desc("Specify a path to look for compile_commands.json. If path " "is invalid, clangd will look in the current directory and " "parent paths of each source file."))
SymbolIndex * StaticIndex
If set, use this index to augment code completion results.
Definition: ClangdServer.h:94
void reset(std::unique_ptr< SymbolIndex >)
Definition: Index.cpp:162