blob: 6bc8499730f5516c7d3b7c2c63bc3ac74f2dc2fd [file] [log] [blame]
Ilya Biryukov38d79772017-05-16 09:38:59 +00001//===--- ClangdLSPServer.cpp - LSP server ------------------------*- C++-*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Ilya Biryukov38d79772017-05-16 09:38:59 +00006//
Kirill Bobyrev8e35f1e2018-08-14 16:03:32 +00007//===----------------------------------------------------------------------===//
Ilya Biryukov38d79772017-05-16 09:38:59 +00008
9#include "ClangdLSPServer.h"
Ilya Biryukov71028b82018-03-12 15:28:22 +000010#include "Diagnostics.h"
Ilya Biryukovcce67a32019-01-29 14:17:36 +000011#include "Protocol.h"
Sam McCallb536a2a2017-12-19 12:23:48 +000012#include "SourceCode.h"
Sam McCall2c30fbc2018-10-18 12:32:04 +000013#include "Trace.h"
Eric Liu78ed91a72018-01-29 15:37:46 +000014#include "URI.h"
Ilya Biryukovcce67a32019-01-29 14:17:36 +000015#include "clang/Tooling/Core/Replacement.h"
Sam McCalla69698f2019-03-27 17:47:49 +000016#include "llvm/ADT/Optional.h"
Kadir Cetinkaya689bf932018-08-24 13:09:41 +000017#include "llvm/ADT/ScopeExit.h"
Simon Marchi9569fd52018-03-16 14:30:42 +000018#include "llvm/Support/Errc.h"
Ilya Biryukovcce67a32019-01-29 14:17:36 +000019#include "llvm/Support/Error.h"
Marc-Andre Laperlee7ec16a2017-11-03 13:39:15 +000020#include "llvm/Support/FormatVariadic.h"
Eric Liu5740ff52018-01-31 16:26:27 +000021#include "llvm/Support/Path.h"
Sam McCall2c30fbc2018-10-18 12:32:04 +000022#include "llvm/Support/ScopedPrinter.h"
Marc-Andre Laperlee7ec16a2017-11-03 13:39:15 +000023
Sam McCallc008af62018-10-20 15:30:37 +000024namespace clang {
25namespace clangd {
Ilya Biryukovafb55542017-05-16 14:40:30 +000026namespace {
Ilya Biryukovb0826bd2019-01-03 13:37:12 +000027class IgnoreCompletionError : public llvm::ErrorInfo<CancelledError> {
28public:
29 void log(llvm::raw_ostream &OS) const override {
30 OS << "ignored auto-triggered completion, preceding char did not match";
31 }
32 std::error_code convertToErrorCode() const override {
33 return std::make_error_code(std::errc::operation_canceled);
34 }
35};
Ilya Biryukovafb55542017-05-16 14:40:30 +000036
Ilya Biryukovcce67a32019-01-29 14:17:36 +000037/// Transforms a tweak into a code action that would apply it if executed.
38/// EXPECTS: T.prepare() was called and returned true.
39CodeAction toCodeAction(const ClangdServer::TweakRef &T, const URIForFile &File,
40 Range Selection) {
41 CodeAction CA;
42 CA.title = T.Title;
43 CA.kind = CodeAction::REFACTOR_KIND;
44 // This tweak may have an expensive second stage, we only run it if the user
45 // actually chooses it in the UI. We reply with a command that would run the
46 // corresponding tweak.
47 // FIXME: for some tweaks, computing the edits is cheap and we could send them
48 // directly.
49 CA.command.emplace();
50 CA.command->title = T.Title;
51 CA.command->command = Command::CLANGD_APPLY_TWEAK;
52 CA.command->tweakArgs.emplace();
53 CA.command->tweakArgs->file = File;
54 CA.command->tweakArgs->tweakID = T.ID;
55 CA.command->tweakArgs->selection = Selection;
56 return CA;
Simon Pilgrime9a136b2019-02-03 14:08:30 +000057}
Ilya Biryukovcce67a32019-01-29 14:17:36 +000058
Ilya Biryukov19d75602018-11-23 15:21:19 +000059void adjustSymbolKinds(llvm::MutableArrayRef<DocumentSymbol> Syms,
60 SymbolKindBitset Kinds) {
61 for (auto &S : Syms) {
62 S.kind = adjustKindToCapability(S.kind, Kinds);
63 adjustSymbolKinds(S.children, Kinds);
64 }
65}
66
Marc-Andre Laperleb387b6e2018-04-23 20:00:52 +000067SymbolKindBitset defaultSymbolKinds() {
68 SymbolKindBitset Defaults;
69 for (size_t I = SymbolKindMin; I <= static_cast<size_t>(SymbolKind::Array);
70 ++I)
71 Defaults.set(I);
72 return Defaults;
73}
74
Kadir Cetinkaya133d46f2018-09-27 17:13:07 +000075CompletionItemKindBitset defaultCompletionItemKinds() {
76 CompletionItemKindBitset Defaults;
77 for (size_t I = CompletionItemKindMin;
78 I <= static_cast<size_t>(CompletionItemKind::Reference); ++I)
79 Defaults.set(I);
80 return Defaults;
81}
82
Ilya Biryukovafb55542017-05-16 14:40:30 +000083} // namespace
84
Sam McCall2c30fbc2018-10-18 12:32:04 +000085// MessageHandler dispatches incoming LSP messages.
86// It handles cross-cutting concerns:
87// - serializes/deserializes protocol objects to JSON
88// - logging of inbound messages
89// - cancellation handling
90// - basic call tracing
Sam McCall3d0adbe2018-10-18 14:41:50 +000091// MessageHandler ensures that initialize() is called before any other handler.
Sam McCall2c30fbc2018-10-18 12:32:04 +000092class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
93public:
94 MessageHandler(ClangdLSPServer &Server) : Server(Server) {}
95
Ilya Biryukovf2001aa2019-01-07 15:45:19 +000096 bool onNotify(llvm::StringRef Method, llvm::json::Value Params) override {
Sam McCalla69698f2019-03-27 17:47:49 +000097 WithContext HandlerContext(handlerContext());
Sam McCall2c30fbc2018-10-18 12:32:04 +000098 log("<-- {0}", Method);
99 if (Method == "exit")
100 return false;
Sam McCall3d0adbe2018-10-18 14:41:50 +0000101 if (!Server.Server)
102 elog("Notification {0} before initialization", Method);
103 else if (Method == "$/cancelRequest")
Sam McCall2c30fbc2018-10-18 12:32:04 +0000104 onCancel(std::move(Params));
105 else if (auto Handler = Notifications.lookup(Method))
106 Handler(std::move(Params));
107 else
108 log("unhandled notification {0}", Method);
109 return true;
110 }
111
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000112 bool onCall(llvm::StringRef Method, llvm::json::Value Params,
113 llvm::json::Value ID) override {
Sam McCalla69698f2019-03-27 17:47:49 +0000114 WithContext HandlerContext(handlerContext());
Sam McCalle2f3a732018-10-24 14:26:26 +0000115 // Calls can be canceled by the client. Add cancellation context.
116 WithContext WithCancel(cancelableRequestContext(ID));
117 trace::Span Tracer(Method);
118 SPAN_ATTACH(Tracer, "Params", Params);
119 ReplyOnce Reply(ID, Method, &Server, Tracer.Args);
Sam McCall2c30fbc2018-10-18 12:32:04 +0000120 log("<-- {0}({1})", Method, ID);
Sam McCall3d0adbe2018-10-18 14:41:50 +0000121 if (!Server.Server && Method != "initialize") {
122 elog("Call {0} before initialization.", Method);
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000123 Reply(llvm::make_error<LSPError>("server not initialized",
124 ErrorCode::ServerNotInitialized));
Sam McCall3d0adbe2018-10-18 14:41:50 +0000125 } else if (auto Handler = Calls.lookup(Method))
Sam McCalle2f3a732018-10-24 14:26:26 +0000126 Handler(std::move(Params), std::move(Reply));
Sam McCall2c30fbc2018-10-18 12:32:04 +0000127 else
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000128 Reply(llvm::make_error<LSPError>("method not found",
129 ErrorCode::MethodNotFound));
Sam McCall2c30fbc2018-10-18 12:32:04 +0000130 return true;
131 }
132
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000133 bool onReply(llvm::json::Value ID,
134 llvm::Expected<llvm::json::Value> Result) override {
Sam McCalla69698f2019-03-27 17:47:49 +0000135 WithContext HandlerContext(handlerContext());
Sam McCall2c30fbc2018-10-18 12:32:04 +0000136 // We ignore replies, just log them.
137 if (Result)
138 log("<-- reply({0})", ID);
139 else
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000140 log("<-- reply({0}) error: {1}", ID, llvm::toString(Result.takeError()));
Sam McCall2c30fbc2018-10-18 12:32:04 +0000141 return true;
142 }
143
144 // Bind an LSP method name to a call.
Sam McCalle2f3a732018-10-24 14:26:26 +0000145 template <typename Param, typename Result>
Sam McCall2c30fbc2018-10-18 12:32:04 +0000146 void bind(const char *Method,
Sam McCalle2f3a732018-10-24 14:26:26 +0000147 void (ClangdLSPServer::*Handler)(const Param &, Callback<Result>)) {
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000148 Calls[Method] = [Method, Handler, this](llvm::json::Value RawParams,
Sam McCalle2f3a732018-10-24 14:26:26 +0000149 ReplyOnce Reply) {
Sam McCall2c30fbc2018-10-18 12:32:04 +0000150 Param P;
Sam McCalle2f3a732018-10-24 14:26:26 +0000151 if (fromJSON(RawParams, P)) {
152 (Server.*Handler)(P, std::move(Reply));
153 } else {
Sam McCall2c30fbc2018-10-18 12:32:04 +0000154 elog("Failed to decode {0} request.", Method);
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000155 Reply(llvm::make_error<LSPError>("failed to decode request",
156 ErrorCode::InvalidRequest));
Sam McCall2c30fbc2018-10-18 12:32:04 +0000157 }
Sam McCall2c30fbc2018-10-18 12:32:04 +0000158 };
159 }
160
161 // Bind an LSP method name to a notification.
162 template <typename Param>
163 void bind(const char *Method,
164 void (ClangdLSPServer::*Handler)(const Param &)) {
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000165 Notifications[Method] = [Method, Handler,
166 this](llvm::json::Value RawParams) {
Sam McCall2c30fbc2018-10-18 12:32:04 +0000167 Param P;
168 if (!fromJSON(RawParams, P)) {
169 elog("Failed to decode {0} request.", Method);
170 return;
171 }
172 trace::Span Tracer(Method);
173 SPAN_ATTACH(Tracer, "Params", RawParams);
174 (Server.*Handler)(P);
175 };
176 }
177
178private:
Sam McCalle2f3a732018-10-24 14:26:26 +0000179 // Function object to reply to an LSP call.
180 // Each instance must be called exactly once, otherwise:
181 // - the bug is logged, and (in debug mode) an assert will fire
182 // - if there was no reply, an error reply is sent
183 // - if there were multiple replies, only the first is sent
184 class ReplyOnce {
185 std::atomic<bool> Replied = {false};
Sam McCalld7babe42018-10-24 15:18:40 +0000186 std::chrono::steady_clock::time_point Start;
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000187 llvm::json::Value ID;
Sam McCalle2f3a732018-10-24 14:26:26 +0000188 std::string Method;
189 ClangdLSPServer *Server; // Null when moved-from.
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000190 llvm::json::Object *TraceArgs;
Sam McCalle2f3a732018-10-24 14:26:26 +0000191
192 public:
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000193 ReplyOnce(const llvm::json::Value &ID, llvm::StringRef Method,
194 ClangdLSPServer *Server, llvm::json::Object *TraceArgs)
Sam McCalld7babe42018-10-24 15:18:40 +0000195 : Start(std::chrono::steady_clock::now()), ID(ID), Method(Method),
196 Server(Server), TraceArgs(TraceArgs) {
Sam McCalle2f3a732018-10-24 14:26:26 +0000197 assert(Server);
198 }
199 ReplyOnce(ReplyOnce &&Other)
Sam McCalld7babe42018-10-24 15:18:40 +0000200 : Replied(Other.Replied.load()), Start(Other.Start),
201 ID(std::move(Other.ID)), Method(std::move(Other.Method)),
202 Server(Other.Server), TraceArgs(Other.TraceArgs) {
Sam McCalle2f3a732018-10-24 14:26:26 +0000203 Other.Server = nullptr;
204 }
Ilya Biryukov22fa4652019-01-03 13:28:05 +0000205 ReplyOnce &operator=(ReplyOnce &&) = delete;
Sam McCalle2f3a732018-10-24 14:26:26 +0000206 ReplyOnce(const ReplyOnce &) = delete;
Ilya Biryukov22fa4652019-01-03 13:28:05 +0000207 ReplyOnce &operator=(const ReplyOnce &) = delete;
Sam McCalle2f3a732018-10-24 14:26:26 +0000208
209 ~ReplyOnce() {
210 if (Server && !Replied) {
211 elog("No reply to message {0}({1})", Method, ID);
212 assert(false && "must reply to all calls!");
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000213 (*this)(llvm::make_error<LSPError>("server failed to reply",
214 ErrorCode::InternalError));
Sam McCalle2f3a732018-10-24 14:26:26 +0000215 }
216 }
217
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000218 void operator()(llvm::Expected<llvm::json::Value> Reply) {
Sam McCalle2f3a732018-10-24 14:26:26 +0000219 assert(Server && "moved-from!");
220 if (Replied.exchange(true)) {
221 elog("Replied twice to message {0}({1})", Method, ID);
222 assert(false && "must reply to each call only once!");
223 return;
224 }
Sam McCalld7babe42018-10-24 15:18:40 +0000225 auto Duration = std::chrono::steady_clock::now() - Start;
226 if (Reply) {
227 log("--> reply:{0}({1}) {2:ms}", Method, ID, Duration);
228 if (TraceArgs)
Sam McCalle2f3a732018-10-24 14:26:26 +0000229 (*TraceArgs)["Reply"] = *Reply;
Sam McCalld7babe42018-10-24 15:18:40 +0000230 std::lock_guard<std::mutex> Lock(Server->TranspWriter);
231 Server->Transp.reply(std::move(ID), std::move(Reply));
232 } else {
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000233 llvm::Error Err = Reply.takeError();
Sam McCalld7babe42018-10-24 15:18:40 +0000234 log("--> reply:{0}({1}) {2:ms}, error: {3}", Method, ID, Duration, Err);
235 if (TraceArgs)
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000236 (*TraceArgs)["Error"] = llvm::to_string(Err);
Sam McCalld7babe42018-10-24 15:18:40 +0000237 std::lock_guard<std::mutex> Lock(Server->TranspWriter);
238 Server->Transp.reply(std::move(ID), std::move(Err));
Sam McCalle2f3a732018-10-24 14:26:26 +0000239 }
Sam McCalle2f3a732018-10-24 14:26:26 +0000240 }
241 };
242
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000243 llvm::StringMap<std::function<void(llvm::json::Value)>> Notifications;
244 llvm::StringMap<std::function<void(llvm::json::Value, ReplyOnce)>> Calls;
Sam McCall2c30fbc2018-10-18 12:32:04 +0000245
246 // Method calls may be cancelled by ID, so keep track of their state.
247 // This needs a mutex: handlers may finish on a different thread, and that's
248 // when we clean up entries in the map.
249 mutable std::mutex RequestCancelersMutex;
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000250 llvm::StringMap<std::pair<Canceler, /*Cookie*/ unsigned>> RequestCancelers;
Sam McCall2c30fbc2018-10-18 12:32:04 +0000251 unsigned NextRequestCookie = 0; // To disambiguate reused IDs, see below.
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000252 void onCancel(const llvm::json::Value &Params) {
253 const llvm::json::Value *ID = nullptr;
Sam McCall2c30fbc2018-10-18 12:32:04 +0000254 if (auto *O = Params.getAsObject())
255 ID = O->get("id");
256 if (!ID) {
257 elog("Bad cancellation request: {0}", Params);
258 return;
259 }
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000260 auto StrID = llvm::to_string(*ID);
Sam McCall2c30fbc2018-10-18 12:32:04 +0000261 std::lock_guard<std::mutex> Lock(RequestCancelersMutex);
262 auto It = RequestCancelers.find(StrID);
263 if (It != RequestCancelers.end())
264 It->second.first(); // Invoke the canceler.
265 }
Sam McCalla69698f2019-03-27 17:47:49 +0000266
267 Context handlerContext() const {
268 return Context::current().derive(
269 kCurrentOffsetEncoding,
270 Server.NegotiatedOffsetEncoding.getValueOr(OffsetEncoding::UTF16));
271 }
272
Sam McCall2c30fbc2018-10-18 12:32:04 +0000273 // We run cancelable requests in a context that does two things:
274 // - allows cancellation using RequestCancelers[ID]
275 // - cleans up the entry in RequestCancelers when it's no longer needed
276 // If a client reuses an ID, the last wins and the first cannot be canceled.
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000277 Context cancelableRequestContext(const llvm::json::Value &ID) {
Sam McCall2c30fbc2018-10-18 12:32:04 +0000278 auto Task = cancelableTask();
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000279 auto StrID = llvm::to_string(ID); // JSON-serialize ID for map key.
Sam McCall2c30fbc2018-10-18 12:32:04 +0000280 auto Cookie = NextRequestCookie++; // No lock, only called on main thread.
281 {
282 std::lock_guard<std::mutex> Lock(RequestCancelersMutex);
283 RequestCancelers[StrID] = {std::move(Task.second), Cookie};
284 }
285 // When the request ends, we can clean up the entry we just added.
286 // The cookie lets us check that it hasn't been overwritten due to ID
287 // reuse.
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000288 return Task.first.derive(llvm::make_scope_exit([this, StrID, Cookie] {
Sam McCall2c30fbc2018-10-18 12:32:04 +0000289 std::lock_guard<std::mutex> Lock(RequestCancelersMutex);
290 auto It = RequestCancelers.find(StrID);
291 if (It != RequestCancelers.end() && It->second.second == Cookie)
292 RequestCancelers.erase(It);
293 }));
294 }
295
296 ClangdLSPServer &Server;
297};
298
299// call(), notify(), and reply() wrap the Transport, adding logging and locking.
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000300void ClangdLSPServer::call(llvm::StringRef Method, llvm::json::Value Params) {
Sam McCall2c30fbc2018-10-18 12:32:04 +0000301 auto ID = NextCallID++;
302 log("--> {0}({1})", Method, ID);
303 // We currently don't handle responses, so no need to store ID anywhere.
304 std::lock_guard<std::mutex> Lock(TranspWriter);
305 Transp.call(Method, std::move(Params), ID);
306}
307
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000308void ClangdLSPServer::notify(llvm::StringRef Method, llvm::json::Value Params) {
Sam McCall2c30fbc2018-10-18 12:32:04 +0000309 log("--> {0}", Method);
310 std::lock_guard<std::mutex> Lock(TranspWriter);
311 Transp.notify(Method, std::move(Params));
312}
313
Sam McCall2c30fbc2018-10-18 12:32:04 +0000314void ClangdLSPServer::onInitialize(const InitializeParams &Params,
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000315 Callback<llvm::json::Value> Reply) {
Sam McCalla69698f2019-03-27 17:47:49 +0000316 // Determine character encoding first as it affects constructed ClangdServer.
317 if (Params.capabilities.offsetEncoding && !NegotiatedOffsetEncoding) {
318 NegotiatedOffsetEncoding = OffsetEncoding::UTF16; // fallback
319 for (OffsetEncoding Supported : *Params.capabilities.offsetEncoding)
320 if (Supported != OffsetEncoding::UnsupportedEncoding) {
321 NegotiatedOffsetEncoding = Supported;
322 break;
323 }
324 }
325 llvm::Optional<WithContextValue> WithOffsetEncoding;
326 if (NegotiatedOffsetEncoding)
327 WithOffsetEncoding.emplace(kCurrentOffsetEncoding,
328 *NegotiatedOffsetEncoding);
329
Sam McCall0d9b40f2018-10-19 15:42:23 +0000330 if (Params.rootUri && *Params.rootUri)
331 ClangdServerOpts.WorkspaceRoot = Params.rootUri->file();
332 else if (Params.rootPath && !Params.rootPath->empty())
333 ClangdServerOpts.WorkspaceRoot = *Params.rootPath;
Sam McCall3d0adbe2018-10-18 14:41:50 +0000334 if (Server)
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000335 return Reply(llvm::make_error<LSPError>("server already initialized",
336 ErrorCode::InvalidRequest));
Sam McCallbc904612018-10-25 04:22:52 +0000337 if (const auto &Dir = Params.initializationOptions.compilationDatabasePath)
338 CompileCommandsDir = Dir;
Sam McCallc55d09a2018-11-02 13:09:36 +0000339 if (UseDirBasedCDB)
340 BaseCDB = llvm::make_unique<DirectoryBasedGlobalCompilationDatabase>(
341 CompileCommandsDir);
Kadir Cetinkayabe6b35d2019-01-22 09:10:20 +0000342 CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags,
343 ClangdServerOpts.ResourceDir);
Sam McCallc55d09a2018-11-02 13:09:36 +0000344 Server.emplace(*CDB, FSProvider, static_cast<DiagnosticsConsumer &>(*this),
345 ClangdServerOpts);
Sam McCallbc904612018-10-25 04:22:52 +0000346 applyConfiguration(Params.initializationOptions.ConfigSettings);
Simon Marchi88016782018-08-01 11:28:49 +0000347
Sam McCallbf6a2fc2018-10-17 07:33:42 +0000348 CCOpts.EnableSnippets = Params.capabilities.CompletionSnippets;
349 DiagOpts.EmbedFixesInDiagnostics = Params.capabilities.DiagnosticFixes;
350 DiagOpts.SendDiagnosticCategory = Params.capabilities.DiagnosticCategory;
Sam McCallc9e4ee92019-04-18 15:17:07 +0000351 DiagOpts.EmitRelatedLocations =
352 Params.capabilities.DiagnosticRelatedInformation;
Sam McCallbf6a2fc2018-10-17 07:33:42 +0000353 if (Params.capabilities.WorkspaceSymbolKinds)
354 SupportedSymbolKinds |= *Params.capabilities.WorkspaceSymbolKinds;
355 if (Params.capabilities.CompletionItemKinds)
356 SupportedCompletionItemKinds |= *Params.capabilities.CompletionItemKinds;
357 SupportsCodeAction = Params.capabilities.CodeActionStructure;
Ilya Biryukov19d75602018-11-23 15:21:19 +0000358 SupportsHierarchicalDocumentSymbol =
359 Params.capabilities.HierarchicalDocumentSymbol;
Haojian Wub6188492018-12-20 15:39:12 +0000360 SupportFileStatus = Params.initializationOptions.FileStatus;
Sam McCalla69698f2019-03-27 17:47:49 +0000361 llvm::json::Object Result{
Sam McCall0930ab02017-11-07 15:49:35 +0000362 {{"capabilities",
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000363 llvm::json::Object{
Simon Marchi98082622018-03-26 14:41:40 +0000364 {"textDocumentSync", (int)TextDocumentSyncKind::Incremental},
Sam McCall0930ab02017-11-07 15:49:35 +0000365 {"documentFormattingProvider", true},
366 {"documentRangeFormattingProvider", true},
367 {"documentOnTypeFormattingProvider",
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000368 llvm::json::Object{
Sam McCall0930ab02017-11-07 15:49:35 +0000369 {"firstTriggerCharacter", "}"},
370 {"moreTriggerCharacter", {}},
371 }},
372 {"codeActionProvider", true},
373 {"completionProvider",
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000374 llvm::json::Object{
Sam McCall0930ab02017-11-07 15:49:35 +0000375 {"resolveProvider", false},
Ilya Biryukovb0826bd2019-01-03 13:37:12 +0000376 // We do extra checks for '>' and ':' in completion to only
377 // trigger on '->' and '::'.
Sam McCall0930ab02017-11-07 15:49:35 +0000378 {"triggerCharacters", {".", ">", ":"}},
379 }},
380 {"signatureHelpProvider",
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000381 llvm::json::Object{
Sam McCall0930ab02017-11-07 15:49:35 +0000382 {"triggerCharacters", {"(", ","}},
383 }},
Sam McCall866ba2c2019-02-01 11:26:13 +0000384 {"declarationProvider", true},
Sam McCall0930ab02017-11-07 15:49:35 +0000385 {"definitionProvider", true},
Ilya Biryukov0e6a51f2017-12-12 12:27:47 +0000386 {"documentHighlightProvider", true},
Marc-Andre Laperle3e618ed2018-02-16 21:38:15 +0000387 {"hoverProvider", true},
Haojian Wu345099c2017-11-09 11:30:04 +0000388 {"renameProvider", true},
Marc-Andre Laperle1be69702018-07-05 19:35:01 +0000389 {"documentSymbolProvider", true},
Marc-Andre Laperleb387b6e2018-04-23 20:00:52 +0000390 {"workspaceSymbolProvider", true},
Sam McCall1ad142f2018-09-05 11:53:07 +0000391 {"referencesProvider", true},
Sam McCall0930ab02017-11-07 15:49:35 +0000392 {"executeCommandProvider",
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000393 llvm::json::Object{
Ilya Biryukovcce67a32019-01-29 14:17:36 +0000394 {"commands",
395 {ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND,
396 ExecuteCommandParams::CLANGD_APPLY_TWEAK}},
Sam McCall0930ab02017-11-07 15:49:35 +0000397 }},
Kadir Cetinkaya86658022019-03-19 09:27:04 +0000398 {"typeHierarchyProvider", true},
Sam McCalla69698f2019-03-27 17:47:49 +0000399 }}}};
400 if (NegotiatedOffsetEncoding)
401 Result["offsetEncoding"] = *NegotiatedOffsetEncoding;
402 Reply(std::move(Result));
Ilya Biryukovafb55542017-05-16 14:40:30 +0000403}
404
Sam McCall2c30fbc2018-10-18 12:32:04 +0000405void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
406 Callback<std::nullptr_t> Reply) {
Ilya Biryukov0d9b8a32017-10-25 08:45:41 +0000407 // Do essentially nothing, just say we're ready to exit.
408 ShutdownRequestReceived = true;
Sam McCall2c30fbc2018-10-18 12:32:04 +0000409 Reply(nullptr);
Sam McCall8a5dded2017-10-12 13:29:58 +0000410}
Ilya Biryukovafb55542017-05-16 14:40:30 +0000411
Sam McCall422c8282018-11-26 16:00:11 +0000412// sync is a clangd extension: it blocks until all background work completes.
413// It blocks the calling thread, so no messages are processed until it returns!
414void ClangdLSPServer::onSync(const NoParams &Params,
415 Callback<std::nullptr_t> Reply) {
416 if (Server->blockUntilIdleForTest(/*TimeoutSeconds=*/60))
417 Reply(nullptr);
418 else
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000419 Reply(llvm::createStringError(llvm::inconvertibleErrorCode(),
420 "Not idle after a minute"));
Sam McCall422c8282018-11-26 16:00:11 +0000421}
422
Sam McCall2c30fbc2018-10-18 12:32:04 +0000423void ClangdLSPServer::onDocumentDidOpen(
424 const DidOpenTextDocumentParams &Params) {
Simon Marchi9569fd52018-03-16 14:30:42 +0000425 PathRef File = Params.textDocument.uri.file();
Ilya Biryukovb10ef472018-06-13 09:20:41 +0000426
Sam McCall2c30fbc2018-10-18 12:32:04 +0000427 const std::string &Contents = Params.textDocument.text;
Simon Marchi9569fd52018-03-16 14:30:42 +0000428
Simon Marchi98082622018-03-26 14:41:40 +0000429 DraftMgr.addDraft(File, Contents);
Ilya Biryukov652364b2018-09-26 05:48:29 +0000430 Server->addDocument(File, Contents, WantDiagnostics::Yes);
Ilya Biryukovafb55542017-05-16 14:40:30 +0000431}
432
Sam McCall2c30fbc2018-10-18 12:32:04 +0000433void ClangdLSPServer::onDocumentDidChange(
434 const DidChangeTextDocumentParams &Params) {
Eric Liu51fed182018-02-22 18:40:39 +0000435 auto WantDiags = WantDiagnostics::Auto;
436 if (Params.wantDiagnostics.hasValue())
437 WantDiags = Params.wantDiagnostics.getValue() ? WantDiagnostics::Yes
438 : WantDiagnostics::No;
Simon Marchi9569fd52018-03-16 14:30:42 +0000439
440 PathRef File = Params.textDocument.uri.file();
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000441 llvm::Expected<std::string> Contents =
Simon Marchi98082622018-03-26 14:41:40 +0000442 DraftMgr.updateDraft(File, Params.contentChanges);
443 if (!Contents) {
444 // If this fails, we are most likely going to be not in sync anymore with
445 // the client. It is better to remove the draft and let further operations
446 // fail rather than giving wrong results.
447 DraftMgr.removeDraft(File);
Ilya Biryukov652364b2018-09-26 05:48:29 +0000448 Server->removeDocument(File);
Sam McCallbed58852018-07-11 10:35:11 +0000449 elog("Failed to update {0}: {1}", File, Contents.takeError());
Simon Marchi98082622018-03-26 14:41:40 +0000450 return;
451 }
Simon Marchi9569fd52018-03-16 14:30:42 +0000452
Ilya Biryukov652364b2018-09-26 05:48:29 +0000453 Server->addDocument(File, *Contents, WantDiags);
Ilya Biryukovafb55542017-05-16 14:40:30 +0000454}
455
Sam McCall2c30fbc2018-10-18 12:32:04 +0000456void ClangdLSPServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
Ilya Biryukov652364b2018-09-26 05:48:29 +0000457 Server->onFileEvent(Params);
Marc-Andre Laperlebf114242017-10-02 18:00:37 +0000458}
459
Sam McCall2c30fbc2018-10-18 12:32:04 +0000460void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params,
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000461 Callback<llvm::json::Value> Reply) {
Ilya Biryukovcce67a32019-01-29 14:17:36 +0000462 auto ApplyEdit = [this](WorkspaceEdit WE) {
Eric Liuc5105f92018-02-16 14:15:55 +0000463 ApplyWorkspaceEditParams Edit;
464 Edit.edit = std::move(WE);
Eric Liuc5105f92018-02-16 14:15:55 +0000465 // Ideally, we would wait for the response and if there is no error, we
466 // would reply success/failure to the original RPC.
467 call("workspace/applyEdit", Edit);
468 };
Marc-Andre Laperlee7ec16a2017-11-03 13:39:15 +0000469 if (Params.command == ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND &&
470 Params.workspaceEdit) {
471 // The flow for "apply-fix" :
472 // 1. We publish a diagnostic, including fixits
473 // 2. The user clicks on the diagnostic, the editor asks us for code actions
474 // 3. We send code actions, with the fixit embedded as context
475 // 4. The user selects the fixit, the editor asks us to apply it
476 // 5. We unwrap the changes and send them back to the editor
477 // 6. The editor applies the changes (applyEdit), and sends us a reply (but
478 // we ignore it)
479
Sam McCall2c30fbc2018-10-18 12:32:04 +0000480 Reply("Fix applied.");
Eric Liuc5105f92018-02-16 14:15:55 +0000481 ApplyEdit(*Params.workspaceEdit);
Ilya Biryukovcce67a32019-01-29 14:17:36 +0000482 } else if (Params.command == ExecuteCommandParams::CLANGD_APPLY_TWEAK &&
483 Params.tweakArgs) {
484 auto Code = DraftMgr.getDraft(Params.tweakArgs->file.file());
485 if (!Code)
486 return Reply(llvm::createStringError(
487 llvm::inconvertibleErrorCode(),
488 "trying to apply a code action for a non-added file"));
489
490 auto Action = [ApplyEdit](decltype(Reply) Reply, URIForFile File,
491 std::string Code,
492 llvm::Expected<tooling::Replacements> R) {
493 if (!R)
494 return Reply(R.takeError());
495
496 WorkspaceEdit WE;
497 WE.changes.emplace();
498 (*WE.changes)[File.uri()] = replacementsToEdits(Code, *R);
499
500 Reply("Fix applied.");
501 ApplyEdit(std::move(WE));
502 };
503 Server->applyTweak(Params.tweakArgs->file.file(),
504 Params.tweakArgs->selection, Params.tweakArgs->tweakID,
505 Bind(Action, std::move(Reply), Params.tweakArgs->file,
506 std::move(*Code)));
Marc-Andre Laperlee7ec16a2017-11-03 13:39:15 +0000507 } else {
508 // We should not get here because ExecuteCommandParams would not have
509 // parsed in the first place and this handler should not be called. But if
510 // more commands are added, this will be here has a safe guard.
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000511 Reply(llvm::make_error<LSPError>(
512 llvm::formatv("Unsupported command \"{0}\".", Params.command).str(),
Sam McCall2c30fbc2018-10-18 12:32:04 +0000513 ErrorCode::InvalidParams));
Marc-Andre Laperlee7ec16a2017-11-03 13:39:15 +0000514 }
515}
516
Sam McCall2c30fbc2018-10-18 12:32:04 +0000517void ClangdLSPServer::onWorkspaceSymbol(
518 const WorkspaceSymbolParams &Params,
519 Callback<std::vector<SymbolInformation>> Reply) {
Ilya Biryukov652364b2018-09-26 05:48:29 +0000520 Server->workspaceSymbols(
Marc-Andre Laperleb387b6e2018-04-23 20:00:52 +0000521 Params.query, CCOpts.Limit,
Sam McCall2c30fbc2018-10-18 12:32:04 +0000522 Bind(
523 [this](decltype(Reply) Reply,
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000524 llvm::Expected<std::vector<SymbolInformation>> Items) {
Sam McCall2c30fbc2018-10-18 12:32:04 +0000525 if (!Items)
526 return Reply(Items.takeError());
527 for (auto &Sym : *Items)
528 Sym.kind = adjustKindToCapability(Sym.kind, SupportedSymbolKinds);
Marc-Andre Laperleb387b6e2018-04-23 20:00:52 +0000529
Sam McCall2c30fbc2018-10-18 12:32:04 +0000530 Reply(std::move(*Items));
531 },
532 std::move(Reply)));
Marc-Andre Laperleb387b6e2018-04-23 20:00:52 +0000533}
534
Sam McCall2c30fbc2018-10-18 12:32:04 +0000535void ClangdLSPServer::onRename(const RenameParams &Params,
536 Callback<WorkspaceEdit> Reply) {
Ilya Biryukov7d60d202018-02-16 12:20:47 +0000537 Path File = Params.textDocument.uri.file();
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000538 llvm::Optional<std::string> Code = DraftMgr.getDraft(File);
Ilya Biryukov261c72e2018-01-17 12:30:24 +0000539 if (!Code)
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000540 return Reply(llvm::make_error<LSPError>(
541 "onRename called for non-added file", ErrorCode::InvalidParams));
Ilya Biryukov261c72e2018-01-17 12:30:24 +0000542
Ilya Biryukov652364b2018-09-26 05:48:29 +0000543 Server->rename(
Ilya Biryukov2c5e8e82018-02-15 13:15:47 +0000544 File, Params.position, Params.newName,
Sam McCall2c30fbc2018-10-18 12:32:04 +0000545 Bind(
Ilya Biryukovd9c24dc2019-04-03 07:18:43 +0000546 [File, Code, Params](decltype(Reply) Reply,
547 llvm::Expected<std::vector<TextEdit>> Edits) {
548 if (!Edits)
549 return Reply(Edits.takeError());
Ilya Biryukov261c72e2018-01-17 12:30:24 +0000550
Sam McCall2c30fbc2018-10-18 12:32:04 +0000551 WorkspaceEdit WE;
Ilya Biryukovd9c24dc2019-04-03 07:18:43 +0000552 WE.changes = {{Params.textDocument.uri.uri(), *Edits}};
Sam McCall2c30fbc2018-10-18 12:32:04 +0000553 Reply(WE);
554 },
555 std::move(Reply)));
Haojian Wu345099c2017-11-09 11:30:04 +0000556}
557
Sam McCall2c30fbc2018-10-18 12:32:04 +0000558void ClangdLSPServer::onDocumentDidClose(
559 const DidCloseTextDocumentParams &Params) {
Simon Marchi9569fd52018-03-16 14:30:42 +0000560 PathRef File = Params.textDocument.uri.file();
561 DraftMgr.removeDraft(File);
Ilya Biryukov652364b2018-09-26 05:48:29 +0000562 Server->removeDocument(File);
Ilya Biryukov49c10712019-03-25 10:15:11 +0000563
564 {
565 std::lock_guard<std::mutex> Lock(FixItsMutex);
566 FixItsMap.erase(File);
567 }
568 // clangd will not send updates for this file anymore, so we empty out the
569 // list of diagnostics shown on the client (e.g. in the "Problems" pane of
570 // VSCode). Note that this cannot race with actual diagnostics responses
571 // because removeDocument() guarantees no diagnostic callbacks will be
572 // executed after it returns.
573 publishDiagnostics(URIForFile::canonicalize(File, /*TUPath=*/File), {});
Ilya Biryukovafb55542017-05-16 14:40:30 +0000574}
575
Sam McCall4db732a2017-09-30 10:08:52 +0000576void ClangdLSPServer::onDocumentOnTypeFormatting(
Sam McCall2c30fbc2018-10-18 12:32:04 +0000577 const DocumentOnTypeFormattingParams &Params,
578 Callback<std::vector<TextEdit>> Reply) {
Ilya Biryukov7d60d202018-02-16 12:20:47 +0000579 auto File = Params.textDocument.uri.file();
Simon Marchi9569fd52018-03-16 14:30:42 +0000580 auto Code = DraftMgr.getDraft(File);
Ilya Biryukov261c72e2018-01-17 12:30:24 +0000581 if (!Code)
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000582 return Reply(llvm::make_error<LSPError>(
Sam McCall2c30fbc2018-10-18 12:32:04 +0000583 "onDocumentOnTypeFormatting called for non-added file",
584 ErrorCode::InvalidParams));
Ilya Biryukov261c72e2018-01-17 12:30:24 +0000585
Ilya Biryukov652364b2018-09-26 05:48:29 +0000586 auto ReplacementsOrError = Server->formatOnType(*Code, File, Params.position);
Raoul Wols212bcf82017-12-12 20:25:06 +0000587 if (ReplacementsOrError)
Sam McCall2c30fbc2018-10-18 12:32:04 +0000588 Reply(replacementsToEdits(*Code, ReplacementsOrError.get()));
Raoul Wols212bcf82017-12-12 20:25:06 +0000589 else
Sam McCall2c30fbc2018-10-18 12:32:04 +0000590 Reply(ReplacementsOrError.takeError());
Ilya Biryukovafb55542017-05-16 14:40:30 +0000591}
592
Sam McCall4db732a2017-09-30 10:08:52 +0000593void ClangdLSPServer::onDocumentRangeFormatting(
Sam McCall2c30fbc2018-10-18 12:32:04 +0000594 const DocumentRangeFormattingParams &Params,
595 Callback<std::vector<TextEdit>> Reply) {
Ilya Biryukov7d60d202018-02-16 12:20:47 +0000596 auto File = Params.textDocument.uri.file();
Simon Marchi9569fd52018-03-16 14:30:42 +0000597 auto Code = DraftMgr.getDraft(File);
Ilya Biryukov261c72e2018-01-17 12:30:24 +0000598 if (!Code)
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000599 return Reply(llvm::make_error<LSPError>(
Sam McCall2c30fbc2018-10-18 12:32:04 +0000600 "onDocumentRangeFormatting called for non-added file",
601 ErrorCode::InvalidParams));
Ilya Biryukov261c72e2018-01-17 12:30:24 +0000602
Ilya Biryukov652364b2018-09-26 05:48:29 +0000603 auto ReplacementsOrError = Server->formatRange(*Code, File, Params.range);
Raoul Wols212bcf82017-12-12 20:25:06 +0000604 if (ReplacementsOrError)
Sam McCall2c30fbc2018-10-18 12:32:04 +0000605 Reply(replacementsToEdits(*Code, ReplacementsOrError.get()));
Raoul Wols212bcf82017-12-12 20:25:06 +0000606 else
Sam McCall2c30fbc2018-10-18 12:32:04 +0000607 Reply(ReplacementsOrError.takeError());
Ilya Biryukovafb55542017-05-16 14:40:30 +0000608}
609
Sam McCall2c30fbc2018-10-18 12:32:04 +0000610void ClangdLSPServer::onDocumentFormatting(
611 const DocumentFormattingParams &Params,
612 Callback<std::vector<TextEdit>> Reply) {
Ilya Biryukov7d60d202018-02-16 12:20:47 +0000613 auto File = Params.textDocument.uri.file();
Simon Marchi9569fd52018-03-16 14:30:42 +0000614 auto Code = DraftMgr.getDraft(File);
Ilya Biryukov261c72e2018-01-17 12:30:24 +0000615 if (!Code)
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000616 return Reply(llvm::make_error<LSPError>(
617 "onDocumentFormatting called for non-added file",
618 ErrorCode::InvalidParams));
Ilya Biryukov261c72e2018-01-17 12:30:24 +0000619
Ilya Biryukov652364b2018-09-26 05:48:29 +0000620 auto ReplacementsOrError = Server->formatFile(*Code, File);
Raoul Wols212bcf82017-12-12 20:25:06 +0000621 if (ReplacementsOrError)
Sam McCall2c30fbc2018-10-18 12:32:04 +0000622 Reply(replacementsToEdits(*Code, ReplacementsOrError.get()));
Raoul Wols212bcf82017-12-12 20:25:06 +0000623 else
Sam McCall2c30fbc2018-10-18 12:32:04 +0000624 Reply(ReplacementsOrError.takeError());
Sam McCall4db732a2017-09-30 10:08:52 +0000625}
626
Ilya Biryukov19d75602018-11-23 15:21:19 +0000627/// The functions constructs a flattened view of the DocumentSymbol hierarchy.
628/// Used by the clients that do not support the hierarchical view.
629static std::vector<SymbolInformation>
630flattenSymbolHierarchy(llvm::ArrayRef<DocumentSymbol> Symbols,
631 const URIForFile &FileURI) {
632
633 std::vector<SymbolInformation> Results;
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000634 std::function<void(const DocumentSymbol &, llvm::StringRef)> Process =
635 [&](const DocumentSymbol &S, llvm::Optional<llvm::StringRef> ParentName) {
Ilya Biryukov19d75602018-11-23 15:21:19 +0000636 SymbolInformation SI;
637 SI.containerName = ParentName ? "" : *ParentName;
638 SI.name = S.name;
639 SI.kind = S.kind;
640 SI.location.range = S.range;
641 SI.location.uri = FileURI;
642
643 Results.push_back(std::move(SI));
644 std::string FullName =
645 !ParentName ? S.name : (ParentName->str() + "::" + S.name);
646 for (auto &C : S.children)
647 Process(C, /*ParentName=*/FullName);
648 };
649 for (auto &S : Symbols)
650 Process(S, /*ParentName=*/"");
651 return Results;
652}
653
654void ClangdLSPServer::onDocumentSymbol(const DocumentSymbolParams &Params,
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000655 Callback<llvm::json::Value> Reply) {
Ilya Biryukov19d75602018-11-23 15:21:19 +0000656 URIForFile FileURI = Params.textDocument.uri;
Ilya Biryukov652364b2018-09-26 05:48:29 +0000657 Server->documentSymbols(
Marc-Andre Laperle1be69702018-07-05 19:35:01 +0000658 Params.textDocument.uri.file(),
Sam McCall2c30fbc2018-10-18 12:32:04 +0000659 Bind(
Ilya Biryukov19d75602018-11-23 15:21:19 +0000660 [this, FileURI](decltype(Reply) Reply,
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000661 llvm::Expected<std::vector<DocumentSymbol>> Items) {
Sam McCall2c30fbc2018-10-18 12:32:04 +0000662 if (!Items)
663 return Reply(Items.takeError());
Ilya Biryukov19d75602018-11-23 15:21:19 +0000664 adjustSymbolKinds(*Items, SupportedSymbolKinds);
665 if (SupportsHierarchicalDocumentSymbol)
666 return Reply(std::move(*Items));
667 else
668 return Reply(flattenSymbolHierarchy(*Items, FileURI));
Sam McCall2c30fbc2018-10-18 12:32:04 +0000669 },
670 std::move(Reply)));
Marc-Andre Laperle1be69702018-07-05 19:35:01 +0000671}
672
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000673static llvm::Optional<Command> asCommand(const CodeAction &Action) {
Sam McCall20841d42018-10-16 16:29:41 +0000674 Command Cmd;
675 if (Action.command && Action.edit)
Sam McCallc008af62018-10-20 15:30:37 +0000676 return None; // Not representable. (We never emit these anyway).
Sam McCall20841d42018-10-16 16:29:41 +0000677 if (Action.command) {
678 Cmd = *Action.command;
679 } else if (Action.edit) {
680 Cmd.command = Command::CLANGD_APPLY_FIX_COMMAND;
681 Cmd.workspaceEdit = *Action.edit;
682 } else {
Sam McCallc008af62018-10-20 15:30:37 +0000683 return None;
Sam McCall20841d42018-10-16 16:29:41 +0000684 }
685 Cmd.title = Action.title;
686 if (Action.kind && *Action.kind == CodeAction::QUICKFIX_KIND)
687 Cmd.title = "Apply fix: " + Cmd.title;
688 return Cmd;
689}
690
Sam McCall2c30fbc2018-10-18 12:32:04 +0000691void ClangdLSPServer::onCodeAction(const CodeActionParams &Params,
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000692 Callback<llvm::json::Value> Reply) {
Ilya Biryukovcce67a32019-01-29 14:17:36 +0000693 URIForFile File = Params.textDocument.uri;
694 auto Code = DraftMgr.getDraft(File.file());
Sam McCall2c30fbc2018-10-18 12:32:04 +0000695 if (!Code)
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000696 return Reply(llvm::make_error<LSPError>(
697 "onCodeAction called for non-added file", ErrorCode::InvalidParams));
Sam McCall20841d42018-10-16 16:29:41 +0000698 // We provide a code action for Fixes on the specified diagnostics.
Ilya Biryukovcce67a32019-01-29 14:17:36 +0000699 std::vector<CodeAction> FixIts;
Sam McCall2c30fbc2018-10-18 12:32:04 +0000700 for (const Diagnostic &D : Params.context.diagnostics) {
Ilya Biryukovcce67a32019-01-29 14:17:36 +0000701 for (auto &F : getFixes(File.file(), D)) {
702 FixIts.push_back(toCodeAction(F, Params.textDocument.uri));
703 FixIts.back().diagnostics = {D};
Sam McCalldd0566b2017-11-06 15:40:30 +0000704 }
Ilya Biryukovafb55542017-05-16 14:40:30 +0000705 }
Sam McCall20841d42018-10-16 16:29:41 +0000706
Ilya Biryukovcce67a32019-01-29 14:17:36 +0000707 // Now enumerate the semantic code actions.
708 auto ConsumeActions =
709 [this](decltype(Reply) Reply, URIForFile File, std::string Code,
710 Range Selection, std::vector<CodeAction> FixIts,
711 llvm::Expected<std::vector<ClangdServer::TweakRef>> Tweaks) {
Ilya Biryukovc6ed7782019-01-30 14:24:17 +0000712 if (!Tweaks)
713 return Reply(Tweaks.takeError());
Ilya Biryukovcce67a32019-01-29 14:17:36 +0000714
715 std::vector<CodeAction> Actions = std::move(FixIts);
716 Actions.reserve(Actions.size() + Tweaks->size());
717 for (const auto &T : *Tweaks)
718 Actions.push_back(toCodeAction(T, File, Selection));
719
720 if (SupportsCodeAction)
721 return Reply(llvm::json::Array(Actions));
722 std::vector<Command> Commands;
723 for (const auto &Action : Actions) {
724 if (auto Command = asCommand(Action))
725 Commands.push_back(std::move(*Command));
726 }
727 return Reply(llvm::json::Array(Commands));
728 };
729
730 Server->enumerateTweaks(File.file(), Params.range,
Ilya Biryukovc9409c62019-01-30 09:39:01 +0000731 Bind(ConsumeActions, std::move(Reply), File,
732 std::move(*Code), Params.range,
Ilya Biryukovcce67a32019-01-29 14:17:36 +0000733 std::move(FixIts)));
Ilya Biryukovafb55542017-05-16 14:40:30 +0000734}
735
Ilya Biryukovb0826bd2019-01-03 13:37:12 +0000736void ClangdLSPServer::onCompletion(const CompletionParams &Params,
Sam McCall2c30fbc2018-10-18 12:32:04 +0000737 Callback<CompletionList> Reply) {
Ilya Biryukovb0826bd2019-01-03 13:37:12 +0000738 if (!shouldRunCompletion(Params))
739 return Reply(llvm::make_error<IgnoreCompletionError>());
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000740 Server->codeComplete(Params.textDocument.uri.file(), Params.position, CCOpts,
741 Bind(
742 [this](decltype(Reply) Reply,
743 llvm::Expected<CodeCompleteResult> List) {
744 if (!List)
745 return Reply(List.takeError());
746 CompletionList LSPList;
747 LSPList.isIncomplete = List->HasMore;
748 for (const auto &R : List->Completions) {
749 CompletionItem C = R.render(CCOpts);
750 C.kind = adjustKindToCapability(
751 C.kind, SupportedCompletionItemKinds);
752 LSPList.items.push_back(std::move(C));
753 }
754 return Reply(std::move(LSPList));
755 },
756 std::move(Reply)));
Ilya Biryukovd9bdfe02017-10-06 11:54:17 +0000757}
758
Sam McCall2c30fbc2018-10-18 12:32:04 +0000759void ClangdLSPServer::onSignatureHelp(const TextDocumentPositionParams &Params,
760 Callback<SignatureHelp> Reply) {
Ilya Biryukov652364b2018-09-26 05:48:29 +0000761 Server->signatureHelp(Params.textDocument.uri.file(), Params.position,
Sam McCall2c30fbc2018-10-18 12:32:04 +0000762 std::move(Reply));
Ilya Biryukov652364b2018-09-26 05:48:29 +0000763}
764
Sam McCall0dbab7f2019-02-02 05:56:00 +0000765// Go to definition has a toggle function: if def and decl are distinct, then
766// the first press gives you the def, the second gives you the matching def.
767// getToggle() returns the counterpart location that under the cursor.
768//
769// We return the toggled location alone (ignoring other symbols) to encourage
770// editors to "bounce" quickly between locations, without showing a menu.
771static Location *getToggle(const TextDocumentPositionParams &Point,
772 LocatedSymbol &Sym) {
773 // Toggle only makes sense with two distinct locations.
774 if (!Sym.Definition || *Sym.Definition == Sym.PreferredDeclaration)
775 return nullptr;
776 if (Sym.Definition->uri.file() == Point.textDocument.uri.file() &&
777 Sym.Definition->range.contains(Point.position))
778 return &Sym.PreferredDeclaration;
779 if (Sym.PreferredDeclaration.uri.file() == Point.textDocument.uri.file() &&
780 Sym.PreferredDeclaration.range.contains(Point.position))
781 return &*Sym.Definition;
782 return nullptr;
783}
784
Sam McCall2c30fbc2018-10-18 12:32:04 +0000785void ClangdLSPServer::onGoToDefinition(const TextDocumentPositionParams &Params,
786 Callback<std::vector<Location>> Reply) {
Sam McCall866ba2c2019-02-01 11:26:13 +0000787 Server->locateSymbolAt(
788 Params.textDocument.uri.file(), Params.position,
789 Bind(
Sam McCall0dbab7f2019-02-02 05:56:00 +0000790 [&, Params](decltype(Reply) Reply,
791 llvm::Expected<std::vector<LocatedSymbol>> Symbols) {
Sam McCall866ba2c2019-02-01 11:26:13 +0000792 if (!Symbols)
793 return Reply(Symbols.takeError());
794 std::vector<Location> Defs;
Sam McCall0dbab7f2019-02-02 05:56:00 +0000795 for (auto &S : *Symbols) {
796 if (Location *Toggle = getToggle(Params, S))
797 return Reply(std::vector<Location>{std::move(*Toggle)});
Sam McCall866ba2c2019-02-01 11:26:13 +0000798 Defs.push_back(S.Definition.getValueOr(S.PreferredDeclaration));
Sam McCall0dbab7f2019-02-02 05:56:00 +0000799 }
Sam McCall866ba2c2019-02-01 11:26:13 +0000800 Reply(std::move(Defs));
801 },
802 std::move(Reply)));
803}
804
805void ClangdLSPServer::onGoToDeclaration(
806 const TextDocumentPositionParams &Params,
807 Callback<std::vector<Location>> Reply) {
808 Server->locateSymbolAt(
809 Params.textDocument.uri.file(), Params.position,
810 Bind(
Sam McCall0dbab7f2019-02-02 05:56:00 +0000811 [&, Params](decltype(Reply) Reply,
812 llvm::Expected<std::vector<LocatedSymbol>> Symbols) {
Sam McCall866ba2c2019-02-01 11:26:13 +0000813 if (!Symbols)
814 return Reply(Symbols.takeError());
815 std::vector<Location> Decls;
Sam McCall0dbab7f2019-02-02 05:56:00 +0000816 for (auto &S : *Symbols) {
817 if (Location *Toggle = getToggle(Params, S))
818 return Reply(std::vector<Location>{std::move(*Toggle)});
819 Decls.push_back(std::move(S.PreferredDeclaration));
820 }
Sam McCall866ba2c2019-02-01 11:26:13 +0000821 Reply(std::move(Decls));
822 },
823 std::move(Reply)));
Marc-Andre Laperle2cbf0372017-06-28 16:12:10 +0000824}
825
Sam McCall111fe842019-05-07 07:55:35 +0000826void ClangdLSPServer::onSwitchSourceHeader(
827 const TextDocumentIdentifier &Params,
Sam McCallb9ec3e92019-05-07 08:30:32 +0000828 Callback<llvm::Optional<URIForFile>> Reply) {
Sam McCall111fe842019-05-07 07:55:35 +0000829 if (auto Result = Server->switchSourceHeader(Params.uri.file()))
Sam McCallb9ec3e92019-05-07 08:30:32 +0000830 Reply(URIForFile::canonicalize(*Result, Params.uri.file()));
Sam McCall111fe842019-05-07 07:55:35 +0000831 else
832 Reply(llvm::None);
Marc-Andre Laperle6571b3e2017-09-28 03:14:40 +0000833}
834
Sam McCall2c30fbc2018-10-18 12:32:04 +0000835void ClangdLSPServer::onDocumentHighlight(
836 const TextDocumentPositionParams &Params,
837 Callback<std::vector<DocumentHighlight>> Reply) {
838 Server->findDocumentHighlights(Params.textDocument.uri.file(),
839 Params.position, std::move(Reply));
Ilya Biryukov0e6a51f2017-12-12 12:27:47 +0000840}
841
Sam McCall2c30fbc2018-10-18 12:32:04 +0000842void ClangdLSPServer::onHover(const TextDocumentPositionParams &Params,
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000843 Callback<llvm::Optional<Hover>> Reply) {
Ilya Biryukov652364b2018-09-26 05:48:29 +0000844 Server->findHover(Params.textDocument.uri.file(), Params.position,
Sam McCall2c30fbc2018-10-18 12:32:04 +0000845 std::move(Reply));
Marc-Andre Laperle3e618ed2018-02-16 21:38:15 +0000846}
847
Kadir Cetinkaya86658022019-03-19 09:27:04 +0000848void ClangdLSPServer::onTypeHierarchy(
849 const TypeHierarchyParams &Params,
850 Callback<Optional<TypeHierarchyItem>> Reply) {
851 Server->typeHierarchy(Params.textDocument.uri.file(), Params.position,
852 Params.resolve, Params.direction, std::move(Reply));
853}
854
Simon Marchi88016782018-08-01 11:28:49 +0000855void ClangdLSPServer::applyConfiguration(
Sam McCallbc904612018-10-25 04:22:52 +0000856 const ConfigurationSettings &Settings) {
Simon Marchiabeed662018-10-16 15:55:03 +0000857 // Per-file update to the compilation database.
Sam McCallbc904612018-10-25 04:22:52 +0000858 bool ShouldReparseOpenFiles = false;
859 for (auto &Entry : Settings.compilationDatabaseChanges) {
860 /// The opened files need to be reparsed only when some existing
861 /// entries are changed.
862 PathRef File = Entry.first;
Sam McCallc55d09a2018-11-02 13:09:36 +0000863 auto Old = CDB->getCompileCommand(File);
864 auto New =
865 tooling::CompileCommand(std::move(Entry.second.workingDirectory), File,
866 std::move(Entry.second.compilationCommand),
867 /*Output=*/"");
Sam McCall6980edb2018-11-02 14:07:51 +0000868 if (Old != New) {
Sam McCallc55d09a2018-11-02 13:09:36 +0000869 CDB->setCompileCommand(File, std::move(New));
Sam McCall6980edb2018-11-02 14:07:51 +0000870 ShouldReparseOpenFiles = true;
871 }
Alex Lorenzf8087862018-08-01 17:39:29 +0000872 }
Sam McCallbc904612018-10-25 04:22:52 +0000873 if (ShouldReparseOpenFiles)
874 reparseOpenedFiles();
Simon Marchi5178f922018-02-22 14:00:39 +0000875}
876
Ilya Biryukov49c10712019-03-25 10:15:11 +0000877void ClangdLSPServer::publishDiagnostics(
878 const URIForFile &File, std::vector<clangd::Diagnostic> Diagnostics) {
879 // Publish diagnostics.
880 notify("textDocument/publishDiagnostics",
881 llvm::json::Object{
882 {"uri", File},
883 {"diagnostics", std::move(Diagnostics)},
884 });
885}
886
Simon Marchi88016782018-08-01 11:28:49 +0000887// FIXME: This function needs to be properly tested.
888void ClangdLSPServer::onChangeConfiguration(
Sam McCall2c30fbc2018-10-18 12:32:04 +0000889 const DidChangeConfigurationParams &Params) {
Simon Marchi88016782018-08-01 11:28:49 +0000890 applyConfiguration(Params.settings);
891}
892
Sam McCall2c30fbc2018-10-18 12:32:04 +0000893void ClangdLSPServer::onReference(const ReferenceParams &Params,
894 Callback<std::vector<Location>> Reply) {
Ilya Biryukov652364b2018-09-26 05:48:29 +0000895 Server->findReferences(Params.textDocument.uri.file(), Params.position,
Haojian Wuc34f0222019-01-14 18:11:09 +0000896 CCOpts.Limit, std::move(Reply));
Sam McCall1ad142f2018-09-05 11:53:07 +0000897}
898
Jan Korousb4067012018-11-27 16:40:46 +0000899void ClangdLSPServer::onSymbolInfo(const TextDocumentPositionParams &Params,
900 Callback<std::vector<SymbolDetails>> Reply) {
901 Server->symbolInfo(Params.textDocument.uri.file(), Params.position,
902 std::move(Reply));
903}
904
Sam McCalla69698f2019-03-27 17:47:49 +0000905ClangdLSPServer::ClangdLSPServer(
906 class Transport &Transp, const FileSystemProvider &FSProvider,
907 const clangd::CodeCompleteOptions &CCOpts,
908 llvm::Optional<Path> CompileCommandsDir, bool UseDirBasedCDB,
909 llvm::Optional<OffsetEncoding> ForcedOffsetEncoding,
910 const ClangdServer::Options &Opts)
Haojian Wu1ca0c582019-01-22 09:39:05 +0000911 : Transp(Transp), MsgHandler(new MessageHandler(*this)),
912 FSProvider(FSProvider), CCOpts(CCOpts),
Sam McCalld1c9d112018-10-23 14:19:54 +0000913 SupportedSymbolKinds(defaultSymbolKinds()),
Kadir Cetinkaya133d46f2018-09-27 17:13:07 +0000914 SupportedCompletionItemKinds(defaultCompletionItemKinds()),
Sam McCallc55d09a2018-11-02 13:09:36 +0000915 UseDirBasedCDB(UseDirBasedCDB),
Sam McCalla69698f2019-03-27 17:47:49 +0000916 CompileCommandsDir(std::move(CompileCommandsDir)), ClangdServerOpts(Opts),
917 NegotiatedOffsetEncoding(ForcedOffsetEncoding) {
Sam McCall2c30fbc2018-10-18 12:32:04 +0000918 // clang-format off
919 MsgHandler->bind("initialize", &ClangdLSPServer::onInitialize);
920 MsgHandler->bind("shutdown", &ClangdLSPServer::onShutdown);
Sam McCall422c8282018-11-26 16:00:11 +0000921 MsgHandler->bind("sync", &ClangdLSPServer::onSync);
Sam McCall2c30fbc2018-10-18 12:32:04 +0000922 MsgHandler->bind("textDocument/rangeFormatting", &ClangdLSPServer::onDocumentRangeFormatting);
923 MsgHandler->bind("textDocument/onTypeFormatting", &ClangdLSPServer::onDocumentOnTypeFormatting);
924 MsgHandler->bind("textDocument/formatting", &ClangdLSPServer::onDocumentFormatting);
925 MsgHandler->bind("textDocument/codeAction", &ClangdLSPServer::onCodeAction);
926 MsgHandler->bind("textDocument/completion", &ClangdLSPServer::onCompletion);
927 MsgHandler->bind("textDocument/signatureHelp", &ClangdLSPServer::onSignatureHelp);
928 MsgHandler->bind("textDocument/definition", &ClangdLSPServer::onGoToDefinition);
Sam McCall866ba2c2019-02-01 11:26:13 +0000929 MsgHandler->bind("textDocument/declaration", &ClangdLSPServer::onGoToDeclaration);
Sam McCall2c30fbc2018-10-18 12:32:04 +0000930 MsgHandler->bind("textDocument/references", &ClangdLSPServer::onReference);
931 MsgHandler->bind("textDocument/switchSourceHeader", &ClangdLSPServer::onSwitchSourceHeader);
932 MsgHandler->bind("textDocument/rename", &ClangdLSPServer::onRename);
933 MsgHandler->bind("textDocument/hover", &ClangdLSPServer::onHover);
934 MsgHandler->bind("textDocument/documentSymbol", &ClangdLSPServer::onDocumentSymbol);
935 MsgHandler->bind("workspace/executeCommand", &ClangdLSPServer::onCommand);
936 MsgHandler->bind("textDocument/documentHighlight", &ClangdLSPServer::onDocumentHighlight);
937 MsgHandler->bind("workspace/symbol", &ClangdLSPServer::onWorkspaceSymbol);
938 MsgHandler->bind("textDocument/didOpen", &ClangdLSPServer::onDocumentDidOpen);
939 MsgHandler->bind("textDocument/didClose", &ClangdLSPServer::onDocumentDidClose);
940 MsgHandler->bind("textDocument/didChange", &ClangdLSPServer::onDocumentDidChange);
941 MsgHandler->bind("workspace/didChangeWatchedFiles", &ClangdLSPServer::onFileEvent);
942 MsgHandler->bind("workspace/didChangeConfiguration", &ClangdLSPServer::onChangeConfiguration);
Jan Korousb4067012018-11-27 16:40:46 +0000943 MsgHandler->bind("textDocument/symbolInfo", &ClangdLSPServer::onSymbolInfo);
Kadir Cetinkaya86658022019-03-19 09:27:04 +0000944 MsgHandler->bind("textDocument/typeHierarchy", &ClangdLSPServer::onTypeHierarchy);
Sam McCall2c30fbc2018-10-18 12:32:04 +0000945 // clang-format on
946}
947
948ClangdLSPServer::~ClangdLSPServer() = default;
Ilya Biryukov38d79772017-05-16 09:38:59 +0000949
Sam McCalldc8f3cf2018-10-17 07:32:05 +0000950bool ClangdLSPServer::run() {
Ilya Biryukovafb55542017-05-16 14:40:30 +0000951 // Run the Language Server loop.
Sam McCalldc8f3cf2018-10-17 07:32:05 +0000952 bool CleanExit = true;
Sam McCall2c30fbc2018-10-18 12:32:04 +0000953 if (auto Err = Transp.loop(*MsgHandler)) {
Sam McCalldc8f3cf2018-10-17 07:32:05 +0000954 elog("Transport error: {0}", std::move(Err));
955 CleanExit = false;
956 }
Ilya Biryukovafb55542017-05-16 14:40:30 +0000957
Ilya Biryukov652364b2018-09-26 05:48:29 +0000958 // Destroy ClangdServer to ensure all worker threads finish.
959 Server.reset();
Sam McCalldc8f3cf2018-10-17 07:32:05 +0000960 return CleanExit && ShutdownRequestReceived;
Ilya Biryukov38d79772017-05-16 09:38:59 +0000961}
962
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000963std::vector<Fix> ClangdLSPServer::getFixes(llvm::StringRef File,
Ilya Biryukov71028b82018-03-12 15:28:22 +0000964 const clangd::Diagnostic &D) {
Ilya Biryukov38d79772017-05-16 09:38:59 +0000965 std::lock_guard<std::mutex> Lock(FixItsMutex);
966 auto DiagToFixItsIter = FixItsMap.find(File);
967 if (DiagToFixItsIter == FixItsMap.end())
968 return {};
969
970 const auto &DiagToFixItsMap = DiagToFixItsIter->second;
971 auto FixItsIter = DiagToFixItsMap.find(D);
972 if (FixItsIter == DiagToFixItsMap.end())
973 return {};
974
975 return FixItsIter->second;
976}
977
Ilya Biryukovb0826bd2019-01-03 13:37:12 +0000978bool ClangdLSPServer::shouldRunCompletion(
979 const CompletionParams &Params) const {
Ilya Biryukovf2001aa2019-01-07 15:45:19 +0000980 llvm::StringRef Trigger = Params.context.triggerCharacter;
Ilya Biryukovb0826bd2019-01-03 13:37:12 +0000981 if (Params.context.triggerKind != CompletionTriggerKind::TriggerCharacter ||
982 (Trigger != ">" && Trigger != ":"))
983 return true;
984
985 auto Code = DraftMgr.getDraft(Params.textDocument.uri.file());
986 if (!Code)
987 return true; // completion code will log the error for untracked doc.
988
989 // A completion request is sent when the user types '>' or ':', but we only
990 // want to trigger on '->' and '::'. We check the preceeding character to make
991 // sure it matches what we expected.
992 // Running the lexer here would be more robust (e.g. we can detect comments
993 // and avoid triggering completion there), but we choose to err on the side
994 // of simplicity here.
995 auto Offset = positionToOffset(*Code, Params.position,
996 /*AllowColumnsBeyondLineLength=*/false);
997 if (!Offset) {
998 vlog("could not convert position '{0}' to offset for file '{1}'",
999 Params.position, Params.textDocument.uri.file());
1000 return true;
1001 }
1002 if (*Offset < 2)
1003 return false;
1004
1005 if (Trigger == ">")
1006 return (*Code)[*Offset - 2] == '-'; // trigger only on '->'.
1007 if (Trigger == ":")
1008 return (*Code)[*Offset - 2] == ':'; // trigger only on '::'.
1009 assert(false && "unhandled trigger character");
1010 return true;
1011}
1012
Sam McCalla7bb0cc2018-03-12 23:22:35 +00001013void ClangdLSPServer::onDiagnosticsReady(PathRef File,
1014 std::vector<Diag> Diagnostics) {
Eric Liu4d814a92018-11-28 10:30:42 +00001015 auto URI = URIForFile::canonicalize(File, /*TUPath=*/File);
Sam McCall16e70702018-10-24 07:59:38 +00001016 std::vector<Diagnostic> LSPDiagnostics;
Ilya Biryukov38d79772017-05-16 09:38:59 +00001017 DiagnosticToReplacementMap LocalFixIts; // Temporary storage
Sam McCalla7bb0cc2018-03-12 23:22:35 +00001018 for (auto &Diag : Diagnostics) {
Sam McCall16e70702018-10-24 07:59:38 +00001019 toLSPDiags(Diag, URI, DiagOpts,
Ilya Biryukovf2001aa2019-01-07 15:45:19 +00001020 [&](clangd::Diagnostic Diag, llvm::ArrayRef<Fix> Fixes) {
Sam McCall16e70702018-10-24 07:59:38 +00001021 auto &FixItsForDiagnostic = LocalFixIts[Diag];
1022 llvm::copy(Fixes, std::back_inserter(FixItsForDiagnostic));
1023 LSPDiagnostics.push_back(std::move(Diag));
1024 });
Ilya Biryukov38d79772017-05-16 09:38:59 +00001025 }
1026
1027 // Cache FixIts
1028 {
Ilya Biryukov38d79772017-05-16 09:38:59 +00001029 std::lock_guard<std::mutex> Lock(FixItsMutex);
1030 FixItsMap[File] = LocalFixIts;
1031 }
1032
Ilya Biryukov49c10712019-03-25 10:15:11 +00001033 // Send a notification to the LSP client.
1034 publishDiagnostics(URI, std::move(LSPDiagnostics));
Ilya Biryukov38d79772017-05-16 09:38:59 +00001035}
Simon Marchi9569fd52018-03-16 14:30:42 +00001036
Haojian Wub6188492018-12-20 15:39:12 +00001037void ClangdLSPServer::onFileUpdated(PathRef File, const TUStatus &Status) {
1038 if (!SupportFileStatus)
1039 return;
1040 // FIXME: we don't emit "BuildingFile" and `RunningAction`, as these
1041 // two statuses are running faster in practice, which leads the UI constantly
1042 // changing, and doesn't provide much value. We may want to emit status at a
1043 // reasonable time interval (e.g. 0.5s).
1044 if (Status.Action.S == TUAction::BuildingFile ||
1045 Status.Action.S == TUAction::RunningAction)
1046 return;
1047 notify("textDocument/clangd.fileStatus", Status.render(File));
1048}
1049
Simon Marchi9569fd52018-03-16 14:30:42 +00001050void ClangdLSPServer::reparseOpenedFiles() {
1051 for (const Path &FilePath : DraftMgr.getActiveFiles())
Ilya Biryukov652364b2018-09-26 05:48:29 +00001052 Server->addDocument(FilePath, *DraftMgr.getDraft(FilePath),
1053 WantDiagnostics::Auto);
Simon Marchi9569fd52018-03-16 14:30:42 +00001054}
Alex Lorenzf8087862018-08-01 17:39:29 +00001055
Sam McCallc008af62018-10-20 15:30:37 +00001056} // namespace clangd
1057} // namespace clang