annotate clang-tools-extra/clangd/ClangdServer.h @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children 0572611fdcc8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===--- ClangdServer.h - Main clangd server code ----------------*- C++-*-===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
anatofuz
parents:
diff changeset
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDSERVER_H
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 #include "../clang-tidy/ClangTidyOptions.h"
anatofuz
parents:
diff changeset
13 #include "Cancellation.h"
anatofuz
parents:
diff changeset
14 #include "CodeComplete.h"
anatofuz
parents:
diff changeset
15 #include "FSProvider.h"
anatofuz
parents:
diff changeset
16 #include "FormattedString.h"
anatofuz
parents:
diff changeset
17 #include "Function.h"
anatofuz
parents:
diff changeset
18 #include "GlobalCompilationDatabase.h"
anatofuz
parents:
diff changeset
19 #include "Hover.h"
anatofuz
parents:
diff changeset
20 #include "Protocol.h"
anatofuz
parents:
diff changeset
21 #include "SemanticHighlighting.h"
anatofuz
parents:
diff changeset
22 #include "TUScheduler.h"
anatofuz
parents:
diff changeset
23 #include "XRefs.h"
anatofuz
parents:
diff changeset
24 #include "index/Background.h"
anatofuz
parents:
diff changeset
25 #include "index/FileIndex.h"
anatofuz
parents:
diff changeset
26 #include "index/Index.h"
anatofuz
parents:
diff changeset
27 #include "refactor/Rename.h"
anatofuz
parents:
diff changeset
28 #include "refactor/Tweak.h"
anatofuz
parents:
diff changeset
29 #include "clang/Tooling/CompilationDatabase.h"
anatofuz
parents:
diff changeset
30 #include "clang/Tooling/Core/Replacement.h"
anatofuz
parents:
diff changeset
31 #include "llvm/ADT/FunctionExtras.h"
anatofuz
parents:
diff changeset
32 #include "llvm/ADT/IntrusiveRefCntPtr.h"
anatofuz
parents:
diff changeset
33 #include "llvm/ADT/Optional.h"
anatofuz
parents:
diff changeset
34 #include "llvm/ADT/StringRef.h"
anatofuz
parents:
diff changeset
35 #include <functional>
anatofuz
parents:
diff changeset
36 #include <future>
anatofuz
parents:
diff changeset
37 #include <string>
anatofuz
parents:
diff changeset
38 #include <type_traits>
anatofuz
parents:
diff changeset
39 #include <utility>
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 namespace clang {
anatofuz
parents:
diff changeset
42 namespace clangd {
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 /// When set, used by ClangdServer to get clang-tidy options for each particular
anatofuz
parents:
diff changeset
45 /// file. Must be thread-safe. We use this instead of ClangTidyOptionsProvider
anatofuz
parents:
diff changeset
46 /// to allow reading tidy configs from the VFS used for parsing.
anatofuz
parents:
diff changeset
47 using ClangTidyOptionsBuilder = std::function<tidy::ClangTidyOptions(
anatofuz
parents:
diff changeset
48 llvm::vfs::FileSystem &, llvm::StringRef /*File*/)>;
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 /// Manages a collection of source files and derived data (ASTs, indexes),
anatofuz
parents:
diff changeset
51 /// and provides language-aware features such as code completion.
anatofuz
parents:
diff changeset
52 ///
anatofuz
parents:
diff changeset
53 /// The primary client is ClangdLSPServer which exposes these features via
anatofuz
parents:
diff changeset
54 /// the Language Server protocol. ClangdServer may also be embedded directly,
anatofuz
parents:
diff changeset
55 /// though its API is not stable over time.
anatofuz
parents:
diff changeset
56 ///
anatofuz
parents:
diff changeset
57 /// ClangdServer should be used from a single thread. Many potentially-slow
anatofuz
parents:
diff changeset
58 /// operations have asynchronous APIs and deliver their results on another
anatofuz
parents:
diff changeset
59 /// thread.
anatofuz
parents:
diff changeset
60 /// Such operations support cancellation: if the caller sets up a cancelable
anatofuz
parents:
diff changeset
61 /// context, many operations will notice cancellation and fail early.
anatofuz
parents:
diff changeset
62 /// (ClangdLSPServer uses this to implement $/cancelRequest).
anatofuz
parents:
diff changeset
63 class ClangdServer {
anatofuz
parents:
diff changeset
64 public:
anatofuz
parents:
diff changeset
65 /// Interface with hooks for users of ClangdServer to be notified of events.
anatofuz
parents:
diff changeset
66 class Callbacks {
anatofuz
parents:
diff changeset
67 public:
anatofuz
parents:
diff changeset
68 virtual ~Callbacks() = default;
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 /// Called by ClangdServer when \p Diagnostics for \p File are ready.
anatofuz
parents:
diff changeset
71 /// May be called concurrently for separate files, not for a single file.
anatofuz
parents:
diff changeset
72 virtual void onDiagnosticsReady(PathRef File,
anatofuz
parents:
diff changeset
73 std::vector<Diag> Diagnostics) {}
anatofuz
parents:
diff changeset
74 /// Called whenever the file status is updated.
anatofuz
parents:
diff changeset
75 /// May be called concurrently for separate files, not for a single file.
anatofuz
parents:
diff changeset
76 virtual void onFileUpdated(PathRef File, const TUStatus &Status) {}
anatofuz
parents:
diff changeset
77
anatofuz
parents:
diff changeset
78 /// Called by ClangdServer when some \p Highlightings for \p File are ready.
anatofuz
parents:
diff changeset
79 /// May be called concurrently for separate files, not for a single file.
anatofuz
parents:
diff changeset
80 virtual void
anatofuz
parents:
diff changeset
81 onHighlightingsReady(PathRef File,
anatofuz
parents:
diff changeset
82 std::vector<HighlightingToken> Highlightings) {}
anatofuz
parents:
diff changeset
83
anatofuz
parents:
diff changeset
84 /// Called when background indexing tasks are enqueued/started/completed.
anatofuz
parents:
diff changeset
85 /// Not called concurrently.
anatofuz
parents:
diff changeset
86 virtual void
anatofuz
parents:
diff changeset
87 onBackgroundIndexProgress(const BackgroundQueue::Stats &Stats) {}
anatofuz
parents:
diff changeset
88 };
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 struct Options {
anatofuz
parents:
diff changeset
91 /// To process requests asynchronously, ClangdServer spawns worker threads.
anatofuz
parents:
diff changeset
92 /// If this is zero, no threads are spawned. All work is done on the calling
anatofuz
parents:
diff changeset
93 /// thread, and callbacks are invoked before "async" functions return.
anatofuz
parents:
diff changeset
94 unsigned AsyncThreadsCount = getDefaultAsyncThreadsCount();
anatofuz
parents:
diff changeset
95
anatofuz
parents:
diff changeset
96 /// AST caching policy. The default is to keep up to 3 ASTs in memory.
anatofuz
parents:
diff changeset
97 ASTRetentionPolicy RetentionPolicy;
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99 /// Cached preambles are potentially large. If false, store them on disk.
anatofuz
parents:
diff changeset
100 bool StorePreamblesInMemory = true;
anatofuz
parents:
diff changeset
101
anatofuz
parents:
diff changeset
102 /// If true, ClangdServer builds a dynamic in-memory index for symbols in
anatofuz
parents:
diff changeset
103 /// opened files and uses the index to augment code completion results.
anatofuz
parents:
diff changeset
104 bool BuildDynamicSymbolIndex = false;
anatofuz
parents:
diff changeset
105 /// Use a heavier and faster in-memory index implementation.
anatofuz
parents:
diff changeset
106 bool HeavyweightDynamicSymbolIndex = true;
anatofuz
parents:
diff changeset
107 /// If true, ClangdServer automatically indexes files in the current project
anatofuz
parents:
diff changeset
108 /// on background threads. The index is stored in the project root.
anatofuz
parents:
diff changeset
109 bool BackgroundIndex = false;
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111 /// If set, use this index to augment code completion results.
anatofuz
parents:
diff changeset
112 SymbolIndex *StaticIndex = nullptr;
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 /// If set, enable clang-tidy in clangd and use to it get clang-tidy
anatofuz
parents:
diff changeset
115 /// configurations for a particular file.
anatofuz
parents:
diff changeset
116 /// Clangd supports only a small subset of ClangTidyOptions, these options
anatofuz
parents:
diff changeset
117 /// (Checks, CheckOptions) are about which clang-tidy checks will be
anatofuz
parents:
diff changeset
118 /// enabled.
anatofuz
parents:
diff changeset
119 ClangTidyOptionsBuilder GetClangTidyOptions;
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 /// Clangd's workspace root. Relevant for "workspace" operations not bound
anatofuz
parents:
diff changeset
122 /// to a particular file.
anatofuz
parents:
diff changeset
123 /// FIXME: If not set, should use the current working directory.
anatofuz
parents:
diff changeset
124 llvm::Optional<std::string> WorkspaceRoot;
anatofuz
parents:
diff changeset
125
anatofuz
parents:
diff changeset
126 /// The resource directory is used to find internal headers, overriding
anatofuz
parents:
diff changeset
127 /// defaults and -resource-dir compiler flag).
anatofuz
parents:
diff changeset
128 /// If None, ClangdServer calls CompilerInvocation::GetResourcePath() to
anatofuz
parents:
diff changeset
129 /// obtain the standard resource directory.
anatofuz
parents:
diff changeset
130 llvm::Optional<std::string> ResourceDir = llvm::None;
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 /// Time to wait after a new file version before computing diagnostics.
anatofuz
parents:
diff changeset
133 DebouncePolicy UpdateDebounce =
anatofuz
parents:
diff changeset
134 DebouncePolicy::fixed(std::chrono::milliseconds(500));
anatofuz
parents:
diff changeset
135
anatofuz
parents:
diff changeset
136 bool SuggestMissingIncludes = false;
anatofuz
parents:
diff changeset
137
anatofuz
parents:
diff changeset
138 /// Clangd will execute compiler drivers matching one of these globs to
anatofuz
parents:
diff changeset
139 /// fetch system include path.
anatofuz
parents:
diff changeset
140 std::vector<std::string> QueryDriverGlobs;
anatofuz
parents:
diff changeset
141
anatofuz
parents:
diff changeset
142 /// Enable semantic highlighting features.
anatofuz
parents:
diff changeset
143 bool SemanticHighlighting = false;
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145 /// Enable cross-file rename feature.
anatofuz
parents:
diff changeset
146 bool CrossFileRename = false;
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 /// Returns true if the tweak should be enabled.
anatofuz
parents:
diff changeset
149 std::function<bool(const Tweak &)> TweakFilter = [](const Tweak &T) {
anatofuz
parents:
diff changeset
150 return !T.hidden(); // only enable non-hidden tweaks.
anatofuz
parents:
diff changeset
151 };
anatofuz
parents:
diff changeset
152
anatofuz
parents:
diff changeset
153 explicit operator TUScheduler::Options() const;
anatofuz
parents:
diff changeset
154 };
anatofuz
parents:
diff changeset
155 // Sensible default options for use in tests.
anatofuz
parents:
diff changeset
156 // Features like indexing must be enabled if desired.
anatofuz
parents:
diff changeset
157 static Options optsForTest();
anatofuz
parents:
diff changeset
158
anatofuz
parents:
diff changeset
159 /// Creates a new ClangdServer instance.
anatofuz
parents:
diff changeset
160 ///
anatofuz
parents:
diff changeset
161 /// ClangdServer uses \p CDB to obtain compilation arguments for parsing. Note
anatofuz
parents:
diff changeset
162 /// that ClangdServer only obtains compilation arguments once for each newly
anatofuz
parents:
diff changeset
163 /// added file (i.e., when processing a first call to addDocument) and reuses
anatofuz
parents:
diff changeset
164 /// those arguments for subsequent reparses. However, ClangdServer will check
anatofuz
parents:
diff changeset
165 /// if compilation arguments changed on calls to forceReparse().
anatofuz
parents:
diff changeset
166 ClangdServer(const GlobalCompilationDatabase &CDB,
anatofuz
parents:
diff changeset
167 const FileSystemProvider &FSProvider, const Options &Opts,
anatofuz
parents:
diff changeset
168 Callbacks *Callbacks = nullptr);
anatofuz
parents:
diff changeset
169
anatofuz
parents:
diff changeset
170 /// Add a \p File to the list of tracked C++ files or update the contents if
anatofuz
parents:
diff changeset
171 /// \p File is already tracked. Also schedules parsing of the AST for it on a
anatofuz
parents:
diff changeset
172 /// separate thread. When the parsing is complete, DiagConsumer passed in
anatofuz
parents:
diff changeset
173 /// constructor will receive onDiagnosticsReady callback.
anatofuz
parents:
diff changeset
174 void addDocument(PathRef File, StringRef Contents,
anatofuz
parents:
diff changeset
175 WantDiagnostics WD = WantDiagnostics::Auto,
anatofuz
parents:
diff changeset
176 bool ForceRebuild = false);
anatofuz
parents:
diff changeset
177
anatofuz
parents:
diff changeset
178 /// Get the contents of \p File, which should have been added.
anatofuz
parents:
diff changeset
179 llvm::StringRef getDocument(PathRef File) const;
anatofuz
parents:
diff changeset
180
anatofuz
parents:
diff changeset
181 /// Remove \p File from list of tracked files, schedule a request to free
anatofuz
parents:
diff changeset
182 /// resources associated with it. Pending diagnostics for closed files may not
anatofuz
parents:
diff changeset
183 /// be delivered, even if requested with WantDiags::Auto or WantDiags::Yes.
anatofuz
parents:
diff changeset
184 void removeDocument(PathRef File);
anatofuz
parents:
diff changeset
185
anatofuz
parents:
diff changeset
186 /// Run code completion for \p File at \p Pos.
anatofuz
parents:
diff changeset
187 /// Request is processed asynchronously.
anatofuz
parents:
diff changeset
188 ///
anatofuz
parents:
diff changeset
189 /// This method should only be called for currently tracked files. However, it
anatofuz
parents:
diff changeset
190 /// is safe to call removeDocument for \p File after this method returns, even
anatofuz
parents:
diff changeset
191 /// while returned future is not yet ready.
anatofuz
parents:
diff changeset
192 /// A version of `codeComplete` that runs \p Callback on the processing thread
anatofuz
parents:
diff changeset
193 /// when codeComplete results become available.
anatofuz
parents:
diff changeset
194 void codeComplete(PathRef File, Position Pos,
anatofuz
parents:
diff changeset
195 const clangd::CodeCompleteOptions &Opts,
anatofuz
parents:
diff changeset
196 Callback<CodeCompleteResult> CB);
anatofuz
parents:
diff changeset
197
anatofuz
parents:
diff changeset
198 /// Provide signature help for \p File at \p Pos. This method should only be
anatofuz
parents:
diff changeset
199 /// called for tracked files.
anatofuz
parents:
diff changeset
200 void signatureHelp(PathRef File, Position Pos, Callback<SignatureHelp> CB);
anatofuz
parents:
diff changeset
201
anatofuz
parents:
diff changeset
202 /// Find declaration/definition locations of symbol at a specified position.
anatofuz
parents:
diff changeset
203 void locateSymbolAt(PathRef File, Position Pos,
anatofuz
parents:
diff changeset
204 Callback<std::vector<LocatedSymbol>> CB);
anatofuz
parents:
diff changeset
205
anatofuz
parents:
diff changeset
206 /// Switch to a corresponding source file when given a header file, and vice
anatofuz
parents:
diff changeset
207 /// versa.
anatofuz
parents:
diff changeset
208 void switchSourceHeader(PathRef Path,
anatofuz
parents:
diff changeset
209 Callback<llvm::Optional<clangd::Path>> CB);
anatofuz
parents:
diff changeset
210
anatofuz
parents:
diff changeset
211 /// Get document highlights for a given position.
anatofuz
parents:
diff changeset
212 void findDocumentHighlights(PathRef File, Position Pos,
anatofuz
parents:
diff changeset
213 Callback<std::vector<DocumentHighlight>> CB);
anatofuz
parents:
diff changeset
214
anatofuz
parents:
diff changeset
215 /// Get code hover for a given position.
anatofuz
parents:
diff changeset
216 void findHover(PathRef File, Position Pos,
anatofuz
parents:
diff changeset
217 Callback<llvm::Optional<HoverInfo>> CB);
anatofuz
parents:
diff changeset
218
anatofuz
parents:
diff changeset
219 /// Get information about type hierarchy for a given position.
anatofuz
parents:
diff changeset
220 void typeHierarchy(PathRef File, Position Pos, int Resolve,
anatofuz
parents:
diff changeset
221 TypeHierarchyDirection Direction,
anatofuz
parents:
diff changeset
222 Callback<llvm::Optional<TypeHierarchyItem>> CB);
anatofuz
parents:
diff changeset
223
anatofuz
parents:
diff changeset
224 /// Resolve type hierarchy item in the given direction.
anatofuz
parents:
diff changeset
225 void resolveTypeHierarchy(TypeHierarchyItem Item, int Resolve,
anatofuz
parents:
diff changeset
226 TypeHierarchyDirection Direction,
anatofuz
parents:
diff changeset
227 Callback<llvm::Optional<TypeHierarchyItem>> CB);
anatofuz
parents:
diff changeset
228
anatofuz
parents:
diff changeset
229 /// Retrieve the top symbols from the workspace matching a query.
anatofuz
parents:
diff changeset
230 void workspaceSymbols(StringRef Query, int Limit,
anatofuz
parents:
diff changeset
231 Callback<std::vector<SymbolInformation>> CB);
anatofuz
parents:
diff changeset
232
anatofuz
parents:
diff changeset
233 /// Retrieve the symbols within the specified file.
anatofuz
parents:
diff changeset
234 void documentSymbols(StringRef File,
anatofuz
parents:
diff changeset
235 Callback<std::vector<DocumentSymbol>> CB);
anatofuz
parents:
diff changeset
236
anatofuz
parents:
diff changeset
237 /// Retrieve locations for symbol references.
anatofuz
parents:
diff changeset
238 void findReferences(PathRef File, Position Pos, uint32_t Limit,
anatofuz
parents:
diff changeset
239 Callback<ReferencesResult> CB);
anatofuz
parents:
diff changeset
240
anatofuz
parents:
diff changeset
241 /// Run formatting for \p Rng inside \p File with content \p Code.
anatofuz
parents:
diff changeset
242 llvm::Expected<tooling::Replacements> formatRange(StringRef Code,
anatofuz
parents:
diff changeset
243 PathRef File, Range Rng);
anatofuz
parents:
diff changeset
244
anatofuz
parents:
diff changeset
245 /// Run formatting for the whole \p File with content \p Code.
anatofuz
parents:
diff changeset
246 llvm::Expected<tooling::Replacements> formatFile(StringRef Code,
anatofuz
parents:
diff changeset
247 PathRef File);
anatofuz
parents:
diff changeset
248
anatofuz
parents:
diff changeset
249 /// Run formatting after \p TriggerText was typed at \p Pos in \p File with
anatofuz
parents:
diff changeset
250 /// content \p Code.
anatofuz
parents:
diff changeset
251 llvm::Expected<std::vector<TextEdit>> formatOnType(StringRef Code,
anatofuz
parents:
diff changeset
252 PathRef File, Position Pos,
anatofuz
parents:
diff changeset
253 StringRef TriggerText);
anatofuz
parents:
diff changeset
254
anatofuz
parents:
diff changeset
255 /// Test the validity of a rename operation.
anatofuz
parents:
diff changeset
256 void prepareRename(PathRef File, Position Pos,
anatofuz
parents:
diff changeset
257 Callback<llvm::Optional<Range>> CB);
anatofuz
parents:
diff changeset
258
anatofuz
parents:
diff changeset
259 /// Rename all occurrences of the symbol at the \p Pos in \p File to
anatofuz
parents:
diff changeset
260 /// \p NewName.
anatofuz
parents:
diff changeset
261 /// If WantFormat is false, the final TextEdit will be not formatted,
anatofuz
parents:
diff changeset
262 /// embedders could use this method to get all occurrences of the symbol (e.g.
anatofuz
parents:
diff changeset
263 /// highlighting them in prepare stage).
anatofuz
parents:
diff changeset
264 void rename(PathRef File, Position Pos, llvm::StringRef NewName,
anatofuz
parents:
diff changeset
265 bool WantFormat, Callback<FileEdits> CB);
anatofuz
parents:
diff changeset
266
anatofuz
parents:
diff changeset
267 struct TweakRef {
anatofuz
parents:
diff changeset
268 std::string ID; /// ID to pass for applyTweak.
anatofuz
parents:
diff changeset
269 std::string Title; /// A single-line message to show in the UI.
anatofuz
parents:
diff changeset
270 Tweak::Intent Intent;
anatofuz
parents:
diff changeset
271 };
anatofuz
parents:
diff changeset
272 /// Enumerate the code tweaks available to the user at a specified point.
anatofuz
parents:
diff changeset
273 void enumerateTweaks(PathRef File, Range Sel,
anatofuz
parents:
diff changeset
274 Callback<std::vector<TweakRef>> CB);
anatofuz
parents:
diff changeset
275
anatofuz
parents:
diff changeset
276 /// Apply the code tweak with a specified \p ID.
anatofuz
parents:
diff changeset
277 void applyTweak(PathRef File, Range Sel, StringRef ID,
anatofuz
parents:
diff changeset
278 Callback<Tweak::Effect> CB);
anatofuz
parents:
diff changeset
279
anatofuz
parents:
diff changeset
280 /// Only for testing purposes.
anatofuz
parents:
diff changeset
281 /// Waits until all requests to worker thread are finished and dumps AST for
anatofuz
parents:
diff changeset
282 /// \p File. \p File must be in the list of added documents.
anatofuz
parents:
diff changeset
283 void dumpAST(PathRef File, llvm::unique_function<void(std::string)> Callback);
anatofuz
parents:
diff changeset
284 /// Called when an event occurs for a watched file in the workspace.
anatofuz
parents:
diff changeset
285 void onFileEvent(const DidChangeWatchedFilesParams &Params);
anatofuz
parents:
diff changeset
286
anatofuz
parents:
diff changeset
287 /// Get symbol info for given position.
anatofuz
parents:
diff changeset
288 /// Clangd extension - not part of official LSP.
anatofuz
parents:
diff changeset
289 void symbolInfo(PathRef File, Position Pos,
anatofuz
parents:
diff changeset
290 Callback<std::vector<SymbolDetails>> CB);
anatofuz
parents:
diff changeset
291
anatofuz
parents:
diff changeset
292 /// Get semantic ranges around a specified position in a file.
anatofuz
parents:
diff changeset
293 void semanticRanges(PathRef File, Position Pos,
anatofuz
parents:
diff changeset
294 Callback<std::vector<Range>> CB);
anatofuz
parents:
diff changeset
295
anatofuz
parents:
diff changeset
296 /// Get all document links in a file.
anatofuz
parents:
diff changeset
297 void documentLinks(PathRef File, Callback<std::vector<DocumentLink>> CB);
anatofuz
parents:
diff changeset
298
anatofuz
parents:
diff changeset
299 /// Returns estimated memory usage for each of the currently open files.
anatofuz
parents:
diff changeset
300 /// The order of results is unspecified.
anatofuz
parents:
diff changeset
301 /// Overall memory usage of clangd may be significantly more than reported
anatofuz
parents:
diff changeset
302 /// here, as this metric does not account (at least) for:
anatofuz
parents:
diff changeset
303 /// - memory occupied by static and dynamic index,
anatofuz
parents:
diff changeset
304 /// - memory required for in-flight requests,
anatofuz
parents:
diff changeset
305 /// FIXME: those metrics might be useful too, we should add them.
anatofuz
parents:
diff changeset
306 std::vector<std::pair<Path, std::size_t>> getUsedBytesPerFile() const;
anatofuz
parents:
diff changeset
307
anatofuz
parents:
diff changeset
308 // Blocks the main thread until the server is idle. Only for use in tests.
anatofuz
parents:
diff changeset
309 // Returns false if the timeout expires.
anatofuz
parents:
diff changeset
310 LLVM_NODISCARD bool
anatofuz
parents:
diff changeset
311 blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds = 10);
anatofuz
parents:
diff changeset
312
anatofuz
parents:
diff changeset
313 private:
anatofuz
parents:
diff changeset
314 /// FIXME: This stats several files to find a .clang-format file. I/O can be
anatofuz
parents:
diff changeset
315 /// slow. Think of a way to cache this.
anatofuz
parents:
diff changeset
316 llvm::Expected<tooling::Replacements>
anatofuz
parents:
diff changeset
317 formatCode(llvm::StringRef Code, PathRef File,
anatofuz
parents:
diff changeset
318 ArrayRef<tooling::Range> Ranges);
anatofuz
parents:
diff changeset
319
anatofuz
parents:
diff changeset
320 const FileSystemProvider &FSProvider;
anatofuz
parents:
diff changeset
321
anatofuz
parents:
diff changeset
322 Path ResourceDir;
anatofuz
parents:
diff changeset
323 // The index used to look up symbols. This could be:
anatofuz
parents:
diff changeset
324 // - null (all index functionality is optional)
anatofuz
parents:
diff changeset
325 // - the dynamic index owned by ClangdServer (DynamicIdx)
anatofuz
parents:
diff changeset
326 // - the static index passed to the constructor
anatofuz
parents:
diff changeset
327 // - a merged view of a static and dynamic index (MergedIndex)
anatofuz
parents:
diff changeset
328 const SymbolIndex *Index = nullptr;
anatofuz
parents:
diff changeset
329 // If present, an index of symbols in open files. Read via *Index.
anatofuz
parents:
diff changeset
330 std::unique_ptr<FileIndex> DynamicIdx;
anatofuz
parents:
diff changeset
331 // If present, the new "auto-index" maintained in background threads.
anatofuz
parents:
diff changeset
332 std::unique_ptr<BackgroundIndex> BackgroundIdx;
anatofuz
parents:
diff changeset
333 // Storage for merged views of the various indexes.
anatofuz
parents:
diff changeset
334 std::vector<std::unique_ptr<SymbolIndex>> MergedIdx;
anatofuz
parents:
diff changeset
335
anatofuz
parents:
diff changeset
336 // When set, provides clang-tidy options for a specific file.
anatofuz
parents:
diff changeset
337 ClangTidyOptionsBuilder GetClangTidyOptions;
anatofuz
parents:
diff changeset
338
anatofuz
parents:
diff changeset
339 // If this is true, suggest include insertion fixes for diagnostic errors that
anatofuz
parents:
diff changeset
340 // can be caused by missing includes (e.g. member access in incomplete type).
anatofuz
parents:
diff changeset
341 bool SuggestMissingIncludes = false;
anatofuz
parents:
diff changeset
342
anatofuz
parents:
diff changeset
343 bool CrossFileRename = false;
anatofuz
parents:
diff changeset
344
anatofuz
parents:
diff changeset
345 std::function<bool(const Tweak &)> TweakFilter;
anatofuz
parents:
diff changeset
346
anatofuz
parents:
diff changeset
347 // GUARDED_BY(CachedCompletionFuzzyFindRequestMutex)
anatofuz
parents:
diff changeset
348 llvm::StringMap<llvm::Optional<FuzzyFindRequest>>
anatofuz
parents:
diff changeset
349 CachedCompletionFuzzyFindRequestByFile;
anatofuz
parents:
diff changeset
350 mutable std::mutex CachedCompletionFuzzyFindRequestMutex;
anatofuz
parents:
diff changeset
351
anatofuz
parents:
diff changeset
352 llvm::Optional<std::string> WorkspaceRoot;
anatofuz
parents:
diff changeset
353 // WorkScheduler has to be the last member, because its destructor has to be
anatofuz
parents:
diff changeset
354 // called before all other members to stop the worker thread that references
anatofuz
parents:
diff changeset
355 // ClangdServer.
anatofuz
parents:
diff changeset
356 TUScheduler WorkScheduler;
anatofuz
parents:
diff changeset
357 };
anatofuz
parents:
diff changeset
358
anatofuz
parents:
diff changeset
359 } // namespace clangd
anatofuz
parents:
diff changeset
360 } // namespace clang
anatofuz
parents:
diff changeset
361
anatofuz
parents:
diff changeset
362 #endif