Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 1 | //===--- ClangdLSPServer.cpp - LSP server ------------------------*- C++-*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
Kirill Bobyrev | 8e35f1e | 2018-08-14 16:03:32 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 9 | |
| 10 | #include "ClangdLSPServer.h" |
Ilya Biryukov | 71028b8 | 2018-03-12 15:28:22 +0000 | [diff] [blame] | 11 | #include "Diagnostics.h" |
Sam McCall | b536a2a | 2017-12-19 12:23:48 +0000 | [diff] [blame] | 12 | #include "SourceCode.h" |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 13 | #include "Trace.h" |
Eric Liu | 78ed91a7 | 2018-01-29 15:37:46 +0000 | [diff] [blame] | 14 | #include "URI.h" |
Kadir Cetinkaya | 689bf93 | 2018-08-24 13:09:41 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/ScopeExit.h" |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 16 | #include "llvm/Support/Errc.h" |
Marc-Andre Laperle | e7ec16a | 2017-11-03 13:39:15 +0000 | [diff] [blame] | 17 | #include "llvm/Support/FormatVariadic.h" |
Eric Liu | 5740ff5 | 2018-01-31 16:26:27 +0000 | [diff] [blame] | 18 | #include "llvm/Support/Path.h" |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 19 | #include "llvm/Support/ScopedPrinter.h" |
Marc-Andre Laperle | e7ec16a | 2017-11-03 13:39:15 +0000 | [diff] [blame] | 20 | |
Sam McCall | d20d798 | 2018-07-09 14:25:59 +0000 | [diff] [blame] | 21 | using namespace llvm; |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 22 | namespace clang { |
| 23 | namespace clangd { |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 24 | namespace { |
| 25 | |
Ilya Biryukov | 19d7560 | 2018-11-23 15:21:19 +0000 | [diff] [blame^] | 26 | void adjustSymbolKinds(llvm::MutableArrayRef<DocumentSymbol> Syms, |
| 27 | SymbolKindBitset Kinds) { |
| 28 | for (auto &S : Syms) { |
| 29 | S.kind = adjustKindToCapability(S.kind, Kinds); |
| 30 | adjustSymbolKinds(S.children, Kinds); |
| 31 | } |
| 32 | } |
| 33 | |
Marc-Andre Laperle | b387b6e | 2018-04-23 20:00:52 +0000 | [diff] [blame] | 34 | SymbolKindBitset defaultSymbolKinds() { |
| 35 | SymbolKindBitset Defaults; |
| 36 | for (size_t I = SymbolKindMin; I <= static_cast<size_t>(SymbolKind::Array); |
| 37 | ++I) |
| 38 | Defaults.set(I); |
| 39 | return Defaults; |
| 40 | } |
| 41 | |
Kadir Cetinkaya | 133d46f | 2018-09-27 17:13:07 +0000 | [diff] [blame] | 42 | CompletionItemKindBitset defaultCompletionItemKinds() { |
| 43 | CompletionItemKindBitset Defaults; |
| 44 | for (size_t I = CompletionItemKindMin; |
| 45 | I <= static_cast<size_t>(CompletionItemKind::Reference); ++I) |
| 46 | Defaults.set(I); |
| 47 | return Defaults; |
| 48 | } |
| 49 | |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 50 | } // namespace |
| 51 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 52 | // MessageHandler dispatches incoming LSP messages. |
| 53 | // It handles cross-cutting concerns: |
| 54 | // - serializes/deserializes protocol objects to JSON |
| 55 | // - logging of inbound messages |
| 56 | // - cancellation handling |
| 57 | // - basic call tracing |
Sam McCall | 3d0adbe | 2018-10-18 14:41:50 +0000 | [diff] [blame] | 58 | // MessageHandler ensures that initialize() is called before any other handler. |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 59 | class ClangdLSPServer::MessageHandler : public Transport::MessageHandler { |
| 60 | public: |
| 61 | MessageHandler(ClangdLSPServer &Server) : Server(Server) {} |
| 62 | |
| 63 | bool onNotify(StringRef Method, json::Value Params) override { |
| 64 | log("<-- {0}", Method); |
| 65 | if (Method == "exit") |
| 66 | return false; |
Sam McCall | 3d0adbe | 2018-10-18 14:41:50 +0000 | [diff] [blame] | 67 | if (!Server.Server) |
| 68 | elog("Notification {0} before initialization", Method); |
| 69 | else if (Method == "$/cancelRequest") |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 70 | onCancel(std::move(Params)); |
| 71 | else if (auto Handler = Notifications.lookup(Method)) |
| 72 | Handler(std::move(Params)); |
| 73 | else |
| 74 | log("unhandled notification {0}", Method); |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | bool onCall(StringRef Method, json::Value Params, json::Value ID) override { |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 79 | // Calls can be canceled by the client. Add cancellation context. |
| 80 | WithContext WithCancel(cancelableRequestContext(ID)); |
| 81 | trace::Span Tracer(Method); |
| 82 | SPAN_ATTACH(Tracer, "Params", Params); |
| 83 | ReplyOnce Reply(ID, Method, &Server, Tracer.Args); |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 84 | log("<-- {0}({1})", Method, ID); |
Sam McCall | 3d0adbe | 2018-10-18 14:41:50 +0000 | [diff] [blame] | 85 | if (!Server.Server && Method != "initialize") { |
| 86 | elog("Call {0} before initialization.", Method); |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 87 | Reply(make_error<LSPError>("server not initialized", |
| 88 | ErrorCode::ServerNotInitialized)); |
Sam McCall | 3d0adbe | 2018-10-18 14:41:50 +0000 | [diff] [blame] | 89 | } else if (auto Handler = Calls.lookup(Method)) |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 90 | Handler(std::move(Params), std::move(Reply)); |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 91 | else |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 92 | Reply( |
| 93 | make_error<LSPError>("method not found", ErrorCode::MethodNotFound)); |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 94 | return true; |
| 95 | } |
| 96 | |
| 97 | bool onReply(json::Value ID, Expected<json::Value> Result) override { |
| 98 | // We ignore replies, just log them. |
| 99 | if (Result) |
| 100 | log("<-- reply({0})", ID); |
| 101 | else |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 102 | log("<-- reply({0}) error: {1}", ID, toString(Result.takeError())); |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 103 | return true; |
| 104 | } |
| 105 | |
| 106 | // Bind an LSP method name to a call. |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 107 | template <typename Param, typename Result> |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 108 | void bind(const char *Method, |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 109 | void (ClangdLSPServer::*Handler)(const Param &, Callback<Result>)) { |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 110 | Calls[Method] = [Method, Handler, this](json::Value RawParams, |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 111 | ReplyOnce Reply) { |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 112 | Param P; |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 113 | if (fromJSON(RawParams, P)) { |
| 114 | (Server.*Handler)(P, std::move(Reply)); |
| 115 | } else { |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 116 | elog("Failed to decode {0} request.", Method); |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 117 | Reply(make_error<LSPError>("failed to decode request", |
| 118 | ErrorCode::InvalidRequest)); |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 119 | } |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 120 | }; |
| 121 | } |
| 122 | |
| 123 | // Bind an LSP method name to a notification. |
| 124 | template <typename Param> |
| 125 | void bind(const char *Method, |
| 126 | void (ClangdLSPServer::*Handler)(const Param &)) { |
| 127 | Notifications[Method] = [Method, Handler, this](json::Value RawParams) { |
| 128 | Param P; |
| 129 | if (!fromJSON(RawParams, P)) { |
| 130 | elog("Failed to decode {0} request.", Method); |
| 131 | return; |
| 132 | } |
| 133 | trace::Span Tracer(Method); |
| 134 | SPAN_ATTACH(Tracer, "Params", RawParams); |
| 135 | (Server.*Handler)(P); |
| 136 | }; |
| 137 | } |
| 138 | |
| 139 | private: |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 140 | // Function object to reply to an LSP call. |
| 141 | // Each instance must be called exactly once, otherwise: |
| 142 | // - the bug is logged, and (in debug mode) an assert will fire |
| 143 | // - if there was no reply, an error reply is sent |
| 144 | // - if there were multiple replies, only the first is sent |
| 145 | class ReplyOnce { |
| 146 | std::atomic<bool> Replied = {false}; |
Sam McCall | d7babe4 | 2018-10-24 15:18:40 +0000 | [diff] [blame] | 147 | std::chrono::steady_clock::time_point Start; |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 148 | json::Value ID; |
| 149 | std::string Method; |
| 150 | ClangdLSPServer *Server; // Null when moved-from. |
| 151 | json::Object *TraceArgs; |
| 152 | |
| 153 | public: |
| 154 | ReplyOnce(const json::Value &ID, StringRef Method, ClangdLSPServer *Server, |
| 155 | json::Object *TraceArgs) |
Sam McCall | d7babe4 | 2018-10-24 15:18:40 +0000 | [diff] [blame] | 156 | : Start(std::chrono::steady_clock::now()), ID(ID), Method(Method), |
| 157 | Server(Server), TraceArgs(TraceArgs) { |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 158 | assert(Server); |
| 159 | } |
| 160 | ReplyOnce(ReplyOnce &&Other) |
Sam McCall | d7babe4 | 2018-10-24 15:18:40 +0000 | [diff] [blame] | 161 | : Replied(Other.Replied.load()), Start(Other.Start), |
| 162 | ID(std::move(Other.ID)), Method(std::move(Other.Method)), |
| 163 | Server(Other.Server), TraceArgs(Other.TraceArgs) { |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 164 | Other.Server = nullptr; |
| 165 | } |
| 166 | ReplyOnce& operator=(ReplyOnce&&) = delete; |
| 167 | ReplyOnce(const ReplyOnce &) = delete; |
| 168 | ReplyOnce& operator=(const ReplyOnce&) = delete; |
| 169 | |
| 170 | ~ReplyOnce() { |
| 171 | if (Server && !Replied) { |
| 172 | elog("No reply to message {0}({1})", Method, ID); |
| 173 | assert(false && "must reply to all calls!"); |
| 174 | (*this)(make_error<LSPError>("server failed to reply", |
| 175 | ErrorCode::InternalError)); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | void operator()(Expected<json::Value> Reply) { |
| 180 | assert(Server && "moved-from!"); |
| 181 | if (Replied.exchange(true)) { |
| 182 | elog("Replied twice to message {0}({1})", Method, ID); |
| 183 | assert(false && "must reply to each call only once!"); |
| 184 | return; |
| 185 | } |
Sam McCall | d7babe4 | 2018-10-24 15:18:40 +0000 | [diff] [blame] | 186 | auto Duration = std::chrono::steady_clock::now() - Start; |
| 187 | if (Reply) { |
| 188 | log("--> reply:{0}({1}) {2:ms}", Method, ID, Duration); |
| 189 | if (TraceArgs) |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 190 | (*TraceArgs)["Reply"] = *Reply; |
Sam McCall | d7babe4 | 2018-10-24 15:18:40 +0000 | [diff] [blame] | 191 | std::lock_guard<std::mutex> Lock(Server->TranspWriter); |
| 192 | Server->Transp.reply(std::move(ID), std::move(Reply)); |
| 193 | } else { |
| 194 | Error Err = Reply.takeError(); |
| 195 | log("--> reply:{0}({1}) {2:ms}, error: {3}", Method, ID, Duration, Err); |
| 196 | if (TraceArgs) |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 197 | (*TraceArgs)["Error"] = to_string(Err); |
Sam McCall | d7babe4 | 2018-10-24 15:18:40 +0000 | [diff] [blame] | 198 | std::lock_guard<std::mutex> Lock(Server->TranspWriter); |
| 199 | Server->Transp.reply(std::move(ID), std::move(Err)); |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 200 | } |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 201 | } |
| 202 | }; |
| 203 | |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 204 | StringMap<std::function<void(json::Value)>> Notifications; |
Sam McCall | e2f3a73 | 2018-10-24 14:26:26 +0000 | [diff] [blame] | 205 | StringMap<std::function<void(json::Value, ReplyOnce)>> Calls; |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 206 | |
| 207 | // Method calls may be cancelled by ID, so keep track of their state. |
| 208 | // This needs a mutex: handlers may finish on a different thread, and that's |
| 209 | // when we clean up entries in the map. |
| 210 | mutable std::mutex RequestCancelersMutex; |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 211 | StringMap<std::pair<Canceler, /*Cookie*/ unsigned>> RequestCancelers; |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 212 | unsigned NextRequestCookie = 0; // To disambiguate reused IDs, see below. |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 213 | void onCancel(const json::Value &Params) { |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 214 | const json::Value *ID = nullptr; |
| 215 | if (auto *O = Params.getAsObject()) |
| 216 | ID = O->get("id"); |
| 217 | if (!ID) { |
| 218 | elog("Bad cancellation request: {0}", Params); |
| 219 | return; |
| 220 | } |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 221 | auto StrID = to_string(*ID); |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 222 | std::lock_guard<std::mutex> Lock(RequestCancelersMutex); |
| 223 | auto It = RequestCancelers.find(StrID); |
| 224 | if (It != RequestCancelers.end()) |
| 225 | It->second.first(); // Invoke the canceler. |
| 226 | } |
| 227 | // We run cancelable requests in a context that does two things: |
| 228 | // - allows cancellation using RequestCancelers[ID] |
| 229 | // - cleans up the entry in RequestCancelers when it's no longer needed |
| 230 | // If a client reuses an ID, the last wins and the first cannot be canceled. |
| 231 | Context cancelableRequestContext(const json::Value &ID) { |
| 232 | auto Task = cancelableTask(); |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 233 | auto StrID = to_string(ID); // JSON-serialize ID for map key. |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 234 | auto Cookie = NextRequestCookie++; // No lock, only called on main thread. |
| 235 | { |
| 236 | std::lock_guard<std::mutex> Lock(RequestCancelersMutex); |
| 237 | RequestCancelers[StrID] = {std::move(Task.second), Cookie}; |
| 238 | } |
| 239 | // When the request ends, we can clean up the entry we just added. |
| 240 | // The cookie lets us check that it hasn't been overwritten due to ID |
| 241 | // reuse. |
| 242 | return Task.first.derive(make_scope_exit([this, StrID, Cookie] { |
| 243 | std::lock_guard<std::mutex> Lock(RequestCancelersMutex); |
| 244 | auto It = RequestCancelers.find(StrID); |
| 245 | if (It != RequestCancelers.end() && It->second.second == Cookie) |
| 246 | RequestCancelers.erase(It); |
| 247 | })); |
| 248 | } |
| 249 | |
| 250 | ClangdLSPServer &Server; |
| 251 | }; |
| 252 | |
| 253 | // call(), notify(), and reply() wrap the Transport, adding logging and locking. |
| 254 | void ClangdLSPServer::call(StringRef Method, json::Value Params) { |
| 255 | auto ID = NextCallID++; |
| 256 | log("--> {0}({1})", Method, ID); |
| 257 | // We currently don't handle responses, so no need to store ID anywhere. |
| 258 | std::lock_guard<std::mutex> Lock(TranspWriter); |
| 259 | Transp.call(Method, std::move(Params), ID); |
| 260 | } |
| 261 | |
| 262 | void ClangdLSPServer::notify(StringRef Method, json::Value Params) { |
| 263 | log("--> {0}", Method); |
| 264 | std::lock_guard<std::mutex> Lock(TranspWriter); |
| 265 | Transp.notify(Method, std::move(Params)); |
| 266 | } |
| 267 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 268 | void ClangdLSPServer::onInitialize(const InitializeParams &Params, |
| 269 | Callback<json::Value> Reply) { |
Sam McCall | 0d9b40f | 2018-10-19 15:42:23 +0000 | [diff] [blame] | 270 | if (Params.rootUri && *Params.rootUri) |
| 271 | ClangdServerOpts.WorkspaceRoot = Params.rootUri->file(); |
| 272 | else if (Params.rootPath && !Params.rootPath->empty()) |
| 273 | ClangdServerOpts.WorkspaceRoot = *Params.rootPath; |
Sam McCall | 3d0adbe | 2018-10-18 14:41:50 +0000 | [diff] [blame] | 274 | if (Server) |
| 275 | return Reply(make_error<LSPError>("server already initialized", |
| 276 | ErrorCode::InvalidRequest)); |
Sam McCall | bc90461 | 2018-10-25 04:22:52 +0000 | [diff] [blame] | 277 | if (const auto &Dir = Params.initializationOptions.compilationDatabasePath) |
| 278 | CompileCommandsDir = Dir; |
Sam McCall | c55d09a | 2018-11-02 13:09:36 +0000 | [diff] [blame] | 279 | if (UseDirBasedCDB) |
| 280 | BaseCDB = llvm::make_unique<DirectoryBasedGlobalCompilationDatabase>( |
| 281 | CompileCommandsDir); |
Sam McCall | 6980edb | 2018-11-02 14:07:51 +0000 | [diff] [blame] | 282 | CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags); |
Sam McCall | c55d09a | 2018-11-02 13:09:36 +0000 | [diff] [blame] | 283 | Server.emplace(*CDB, FSProvider, static_cast<DiagnosticsConsumer &>(*this), |
| 284 | ClangdServerOpts); |
Sam McCall | bc90461 | 2018-10-25 04:22:52 +0000 | [diff] [blame] | 285 | applyConfiguration(Params.initializationOptions.ConfigSettings); |
Simon Marchi | 8801678 | 2018-08-01 11:28:49 +0000 | [diff] [blame] | 286 | |
Sam McCall | bf6a2fc | 2018-10-17 07:33:42 +0000 | [diff] [blame] | 287 | CCOpts.EnableSnippets = Params.capabilities.CompletionSnippets; |
| 288 | DiagOpts.EmbedFixesInDiagnostics = Params.capabilities.DiagnosticFixes; |
| 289 | DiagOpts.SendDiagnosticCategory = Params.capabilities.DiagnosticCategory; |
| 290 | if (Params.capabilities.WorkspaceSymbolKinds) |
| 291 | SupportedSymbolKinds |= *Params.capabilities.WorkspaceSymbolKinds; |
| 292 | if (Params.capabilities.CompletionItemKinds) |
| 293 | SupportedCompletionItemKinds |= *Params.capabilities.CompletionItemKinds; |
| 294 | SupportsCodeAction = Params.capabilities.CodeActionStructure; |
Ilya Biryukov | 19d7560 | 2018-11-23 15:21:19 +0000 | [diff] [blame^] | 295 | SupportsHierarchicalDocumentSymbol = |
| 296 | Params.capabilities.HierarchicalDocumentSymbol; |
Kadir Cetinkaya | 133d46f | 2018-09-27 17:13:07 +0000 | [diff] [blame] | 297 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 298 | Reply(json::Object{ |
Sam McCall | 0930ab0 | 2017-11-07 15:49:35 +0000 | [diff] [blame] | 299 | {{"capabilities", |
Sam McCall | d20d798 | 2018-07-09 14:25:59 +0000 | [diff] [blame] | 300 | json::Object{ |
Simon Marchi | 9808262 | 2018-03-26 14:41:40 +0000 | [diff] [blame] | 301 | {"textDocumentSync", (int)TextDocumentSyncKind::Incremental}, |
Sam McCall | 0930ab0 | 2017-11-07 15:49:35 +0000 | [diff] [blame] | 302 | {"documentFormattingProvider", true}, |
| 303 | {"documentRangeFormattingProvider", true}, |
| 304 | {"documentOnTypeFormattingProvider", |
Sam McCall | d20d798 | 2018-07-09 14:25:59 +0000 | [diff] [blame] | 305 | json::Object{ |
Sam McCall | 0930ab0 | 2017-11-07 15:49:35 +0000 | [diff] [blame] | 306 | {"firstTriggerCharacter", "}"}, |
| 307 | {"moreTriggerCharacter", {}}, |
| 308 | }}, |
| 309 | {"codeActionProvider", true}, |
| 310 | {"completionProvider", |
Sam McCall | d20d798 | 2018-07-09 14:25:59 +0000 | [diff] [blame] | 311 | json::Object{ |
Sam McCall | 0930ab0 | 2017-11-07 15:49:35 +0000 | [diff] [blame] | 312 | {"resolveProvider", false}, |
| 313 | {"triggerCharacters", {".", ">", ":"}}, |
| 314 | }}, |
| 315 | {"signatureHelpProvider", |
Sam McCall | d20d798 | 2018-07-09 14:25:59 +0000 | [diff] [blame] | 316 | json::Object{ |
Sam McCall | 0930ab0 | 2017-11-07 15:49:35 +0000 | [diff] [blame] | 317 | {"triggerCharacters", {"(", ","}}, |
| 318 | }}, |
| 319 | {"definitionProvider", true}, |
Ilya Biryukov | 0e6a51f | 2017-12-12 12:27:47 +0000 | [diff] [blame] | 320 | {"documentHighlightProvider", true}, |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 321 | {"hoverProvider", true}, |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 322 | {"renameProvider", true}, |
Marc-Andre Laperle | 1be6970 | 2018-07-05 19:35:01 +0000 | [diff] [blame] | 323 | {"documentSymbolProvider", true}, |
Marc-Andre Laperle | b387b6e | 2018-04-23 20:00:52 +0000 | [diff] [blame] | 324 | {"workspaceSymbolProvider", true}, |
Sam McCall | 1ad142f | 2018-09-05 11:53:07 +0000 | [diff] [blame] | 325 | {"referencesProvider", true}, |
Sam McCall | 0930ab0 | 2017-11-07 15:49:35 +0000 | [diff] [blame] | 326 | {"executeCommandProvider", |
Sam McCall | d20d798 | 2018-07-09 14:25:59 +0000 | [diff] [blame] | 327 | json::Object{ |
Eric Liu | 2c19053 | 2018-05-15 15:23:53 +0000 | [diff] [blame] | 328 | {"commands", {ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND}}, |
Sam McCall | 0930ab0 | 2017-11-07 15:49:35 +0000 | [diff] [blame] | 329 | }}, |
| 330 | }}}}); |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 333 | void ClangdLSPServer::onShutdown(const ShutdownParams &Params, |
| 334 | Callback<std::nullptr_t> Reply) { |
Ilya Biryukov | 0d9b8a3 | 2017-10-25 08:45:41 +0000 | [diff] [blame] | 335 | // Do essentially nothing, just say we're ready to exit. |
| 336 | ShutdownRequestReceived = true; |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 337 | Reply(nullptr); |
Sam McCall | 8a5dded | 2017-10-12 13:29:58 +0000 | [diff] [blame] | 338 | } |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 339 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 340 | void ClangdLSPServer::onDocumentDidOpen( |
| 341 | const DidOpenTextDocumentParams &Params) { |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 342 | PathRef File = Params.textDocument.uri.file(); |
Ilya Biryukov | b10ef47 | 2018-06-13 09:20:41 +0000 | [diff] [blame] | 343 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 344 | const std::string &Contents = Params.textDocument.text; |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 345 | |
Simon Marchi | 9808262 | 2018-03-26 14:41:40 +0000 | [diff] [blame] | 346 | DraftMgr.addDraft(File, Contents); |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 347 | Server->addDocument(File, Contents, WantDiagnostics::Yes); |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 350 | void ClangdLSPServer::onDocumentDidChange( |
| 351 | const DidChangeTextDocumentParams &Params) { |
Eric Liu | 51fed18 | 2018-02-22 18:40:39 +0000 | [diff] [blame] | 352 | auto WantDiags = WantDiagnostics::Auto; |
| 353 | if (Params.wantDiagnostics.hasValue()) |
| 354 | WantDiags = Params.wantDiagnostics.getValue() ? WantDiagnostics::Yes |
| 355 | : WantDiagnostics::No; |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 356 | |
| 357 | PathRef File = Params.textDocument.uri.file(); |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 358 | Expected<std::string> Contents = |
Simon Marchi | 9808262 | 2018-03-26 14:41:40 +0000 | [diff] [blame] | 359 | DraftMgr.updateDraft(File, Params.contentChanges); |
| 360 | if (!Contents) { |
| 361 | // If this fails, we are most likely going to be not in sync anymore with |
| 362 | // the client. It is better to remove the draft and let further operations |
| 363 | // fail rather than giving wrong results. |
| 364 | DraftMgr.removeDraft(File); |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 365 | Server->removeDocument(File); |
Sam McCall | bed5885 | 2018-07-11 10:35:11 +0000 | [diff] [blame] | 366 | elog("Failed to update {0}: {1}", File, Contents.takeError()); |
Simon Marchi | 9808262 | 2018-03-26 14:41:40 +0000 | [diff] [blame] | 367 | return; |
| 368 | } |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 369 | |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 370 | Server->addDocument(File, *Contents, WantDiags); |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 373 | void ClangdLSPServer::onFileEvent(const DidChangeWatchedFilesParams &Params) { |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 374 | Server->onFileEvent(Params); |
Marc-Andre Laperle | bf11424 | 2017-10-02 18:00:37 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 377 | void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params, |
| 378 | Callback<json::Value> Reply) { |
| 379 | auto ApplyEdit = [&](WorkspaceEdit WE) { |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 380 | ApplyWorkspaceEditParams Edit; |
| 381 | Edit.edit = std::move(WE); |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 382 | // Ideally, we would wait for the response and if there is no error, we |
| 383 | // would reply success/failure to the original RPC. |
| 384 | call("workspace/applyEdit", Edit); |
| 385 | }; |
Marc-Andre Laperle | e7ec16a | 2017-11-03 13:39:15 +0000 | [diff] [blame] | 386 | if (Params.command == ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND && |
| 387 | Params.workspaceEdit) { |
| 388 | // The flow for "apply-fix" : |
| 389 | // 1. We publish a diagnostic, including fixits |
| 390 | // 2. The user clicks on the diagnostic, the editor asks us for code actions |
| 391 | // 3. We send code actions, with the fixit embedded as context |
| 392 | // 4. The user selects the fixit, the editor asks us to apply it |
| 393 | // 5. We unwrap the changes and send them back to the editor |
| 394 | // 6. The editor applies the changes (applyEdit), and sends us a reply (but |
| 395 | // we ignore it) |
| 396 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 397 | Reply("Fix applied."); |
Eric Liu | c5105f9 | 2018-02-16 14:15:55 +0000 | [diff] [blame] | 398 | ApplyEdit(*Params.workspaceEdit); |
Marc-Andre Laperle | e7ec16a | 2017-11-03 13:39:15 +0000 | [diff] [blame] | 399 | } else { |
| 400 | // We should not get here because ExecuteCommandParams would not have |
| 401 | // parsed in the first place and this handler should not be called. But if |
| 402 | // more commands are added, this will be here has a safe guard. |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 403 | Reply(make_error<LSPError>( |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 404 | formatv("Unsupported command \"{0}\".", Params.command).str(), |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 405 | ErrorCode::InvalidParams)); |
Marc-Andre Laperle | e7ec16a | 2017-11-03 13:39:15 +0000 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 409 | void ClangdLSPServer::onWorkspaceSymbol( |
| 410 | const WorkspaceSymbolParams &Params, |
| 411 | Callback<std::vector<SymbolInformation>> Reply) { |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 412 | Server->workspaceSymbols( |
Marc-Andre Laperle | b387b6e | 2018-04-23 20:00:52 +0000 | [diff] [blame] | 413 | Params.query, CCOpts.Limit, |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 414 | Bind( |
| 415 | [this](decltype(Reply) Reply, |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 416 | Expected<std::vector<SymbolInformation>> Items) { |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 417 | if (!Items) |
| 418 | return Reply(Items.takeError()); |
| 419 | for (auto &Sym : *Items) |
| 420 | Sym.kind = adjustKindToCapability(Sym.kind, SupportedSymbolKinds); |
Marc-Andre Laperle | b387b6e | 2018-04-23 20:00:52 +0000 | [diff] [blame] | 421 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 422 | Reply(std::move(*Items)); |
| 423 | }, |
| 424 | std::move(Reply))); |
Marc-Andre Laperle | b387b6e | 2018-04-23 20:00:52 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 427 | void ClangdLSPServer::onRename(const RenameParams &Params, |
| 428 | Callback<WorkspaceEdit> Reply) { |
Ilya Biryukov | 7d60d20 | 2018-02-16 12:20:47 +0000 | [diff] [blame] | 429 | Path File = Params.textDocument.uri.file(); |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 430 | Optional<std::string> Code = DraftMgr.getDraft(File); |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 431 | if (!Code) |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 432 | return Reply(make_error<LSPError>("onRename called for non-added file", |
| 433 | ErrorCode::InvalidParams)); |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 434 | |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 435 | Server->rename( |
Ilya Biryukov | 2c5e8e8 | 2018-02-15 13:15:47 +0000 | [diff] [blame] | 436 | File, Params.position, Params.newName, |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 437 | Bind( |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 438 | [File, Code, |
| 439 | Params](decltype(Reply) Reply, |
| 440 | Expected<std::vector<tooling::Replacement>> Replacements) { |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 441 | if (!Replacements) |
| 442 | return Reply(Replacements.takeError()); |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 443 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 444 | // Turn the replacements into the format specified by the Language |
| 445 | // Server Protocol. Fuse them into one big JSON array. |
| 446 | std::vector<TextEdit> Edits; |
| 447 | for (const auto &R : *Replacements) |
| 448 | Edits.push_back(replacementToEdit(*Code, R)); |
| 449 | WorkspaceEdit WE; |
| 450 | WE.changes = {{Params.textDocument.uri.uri(), Edits}}; |
| 451 | Reply(WE); |
| 452 | }, |
| 453 | std::move(Reply))); |
Haojian Wu | 345099c | 2017-11-09 11:30:04 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 456 | void ClangdLSPServer::onDocumentDidClose( |
| 457 | const DidCloseTextDocumentParams &Params) { |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 458 | PathRef File = Params.textDocument.uri.file(); |
| 459 | DraftMgr.removeDraft(File); |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 460 | Server->removeDocument(File); |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Sam McCall | 4db732a | 2017-09-30 10:08:52 +0000 | [diff] [blame] | 463 | void ClangdLSPServer::onDocumentOnTypeFormatting( |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 464 | const DocumentOnTypeFormattingParams &Params, |
| 465 | Callback<std::vector<TextEdit>> Reply) { |
Ilya Biryukov | 7d60d20 | 2018-02-16 12:20:47 +0000 | [diff] [blame] | 466 | auto File = Params.textDocument.uri.file(); |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 467 | auto Code = DraftMgr.getDraft(File); |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 468 | if (!Code) |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 469 | return Reply(make_error<LSPError>( |
| 470 | "onDocumentOnTypeFormatting called for non-added file", |
| 471 | ErrorCode::InvalidParams)); |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 472 | |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 473 | auto ReplacementsOrError = Server->formatOnType(*Code, File, Params.position); |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 474 | if (ReplacementsOrError) |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 475 | Reply(replacementsToEdits(*Code, ReplacementsOrError.get())); |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 476 | else |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 477 | Reply(ReplacementsOrError.takeError()); |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 478 | } |
| 479 | |
Sam McCall | 4db732a | 2017-09-30 10:08:52 +0000 | [diff] [blame] | 480 | void ClangdLSPServer::onDocumentRangeFormatting( |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 481 | const DocumentRangeFormattingParams &Params, |
| 482 | Callback<std::vector<TextEdit>> Reply) { |
Ilya Biryukov | 7d60d20 | 2018-02-16 12:20:47 +0000 | [diff] [blame] | 483 | auto File = Params.textDocument.uri.file(); |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 484 | auto Code = DraftMgr.getDraft(File); |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 485 | if (!Code) |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 486 | return Reply(make_error<LSPError>( |
| 487 | "onDocumentRangeFormatting called for non-added file", |
| 488 | ErrorCode::InvalidParams)); |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 489 | |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 490 | auto ReplacementsOrError = Server->formatRange(*Code, File, Params.range); |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 491 | if (ReplacementsOrError) |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 492 | Reply(replacementsToEdits(*Code, ReplacementsOrError.get())); |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 493 | else |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 494 | Reply(ReplacementsOrError.takeError()); |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 497 | void ClangdLSPServer::onDocumentFormatting( |
| 498 | const DocumentFormattingParams &Params, |
| 499 | Callback<std::vector<TextEdit>> Reply) { |
Ilya Biryukov | 7d60d20 | 2018-02-16 12:20:47 +0000 | [diff] [blame] | 500 | auto File = Params.textDocument.uri.file(); |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 501 | auto Code = DraftMgr.getDraft(File); |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 502 | if (!Code) |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 503 | return Reply( |
| 504 | make_error<LSPError>("onDocumentFormatting called for non-added file", |
| 505 | ErrorCode::InvalidParams)); |
Ilya Biryukov | 261c72e | 2018-01-17 12:30:24 +0000 | [diff] [blame] | 506 | |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 507 | auto ReplacementsOrError = Server->formatFile(*Code, File); |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 508 | if (ReplacementsOrError) |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 509 | Reply(replacementsToEdits(*Code, ReplacementsOrError.get())); |
Raoul Wols | 212bcf8 | 2017-12-12 20:25:06 +0000 | [diff] [blame] | 510 | else |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 511 | Reply(ReplacementsOrError.takeError()); |
Sam McCall | 4db732a | 2017-09-30 10:08:52 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Ilya Biryukov | 19d7560 | 2018-11-23 15:21:19 +0000 | [diff] [blame^] | 514 | /// The functions constructs a flattened view of the DocumentSymbol hierarchy. |
| 515 | /// Used by the clients that do not support the hierarchical view. |
| 516 | static std::vector<SymbolInformation> |
| 517 | flattenSymbolHierarchy(llvm::ArrayRef<DocumentSymbol> Symbols, |
| 518 | const URIForFile &FileURI) { |
| 519 | |
| 520 | std::vector<SymbolInformation> Results; |
| 521 | std::function<void(const DocumentSymbol &, StringRef)> Process = |
| 522 | [&](const DocumentSymbol &S, Optional<StringRef> ParentName) { |
| 523 | SymbolInformation SI; |
| 524 | SI.containerName = ParentName ? "" : *ParentName; |
| 525 | SI.name = S.name; |
| 526 | SI.kind = S.kind; |
| 527 | SI.location.range = S.range; |
| 528 | SI.location.uri = FileURI; |
| 529 | |
| 530 | Results.push_back(std::move(SI)); |
| 531 | std::string FullName = |
| 532 | !ParentName ? S.name : (ParentName->str() + "::" + S.name); |
| 533 | for (auto &C : S.children) |
| 534 | Process(C, /*ParentName=*/FullName); |
| 535 | }; |
| 536 | for (auto &S : Symbols) |
| 537 | Process(S, /*ParentName=*/""); |
| 538 | return Results; |
| 539 | } |
| 540 | |
| 541 | void ClangdLSPServer::onDocumentSymbol(const DocumentSymbolParams &Params, |
| 542 | Callback<json::Value> Reply) { |
| 543 | URIForFile FileURI = Params.textDocument.uri; |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 544 | Server->documentSymbols( |
Marc-Andre Laperle | 1be6970 | 2018-07-05 19:35:01 +0000 | [diff] [blame] | 545 | Params.textDocument.uri.file(), |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 546 | Bind( |
Ilya Biryukov | 19d7560 | 2018-11-23 15:21:19 +0000 | [diff] [blame^] | 547 | [this, FileURI](decltype(Reply) Reply, |
| 548 | Expected<std::vector<DocumentSymbol>> Items) { |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 549 | if (!Items) |
| 550 | return Reply(Items.takeError()); |
Ilya Biryukov | 19d7560 | 2018-11-23 15:21:19 +0000 | [diff] [blame^] | 551 | adjustSymbolKinds(*Items, SupportedSymbolKinds); |
| 552 | if (SupportsHierarchicalDocumentSymbol) |
| 553 | return Reply(std::move(*Items)); |
| 554 | else |
| 555 | return Reply(flattenSymbolHierarchy(*Items, FileURI)); |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 556 | }, |
| 557 | std::move(Reply))); |
Marc-Andre Laperle | 1be6970 | 2018-07-05 19:35:01 +0000 | [diff] [blame] | 558 | } |
| 559 | |
Sam McCall | 20841d4 | 2018-10-16 16:29:41 +0000 | [diff] [blame] | 560 | static Optional<Command> asCommand(const CodeAction &Action) { |
| 561 | Command Cmd; |
| 562 | if (Action.command && Action.edit) |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 563 | return None; // Not representable. (We never emit these anyway). |
Sam McCall | 20841d4 | 2018-10-16 16:29:41 +0000 | [diff] [blame] | 564 | if (Action.command) { |
| 565 | Cmd = *Action.command; |
| 566 | } else if (Action.edit) { |
| 567 | Cmd.command = Command::CLANGD_APPLY_FIX_COMMAND; |
| 568 | Cmd.workspaceEdit = *Action.edit; |
| 569 | } else { |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 570 | return None; |
Sam McCall | 20841d4 | 2018-10-16 16:29:41 +0000 | [diff] [blame] | 571 | } |
| 572 | Cmd.title = Action.title; |
| 573 | if (Action.kind && *Action.kind == CodeAction::QUICKFIX_KIND) |
| 574 | Cmd.title = "Apply fix: " + Cmd.title; |
| 575 | return Cmd; |
| 576 | } |
| 577 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 578 | void ClangdLSPServer::onCodeAction(const CodeActionParams &Params, |
| 579 | Callback<json::Value> Reply) { |
| 580 | auto Code = DraftMgr.getDraft(Params.textDocument.uri.file()); |
| 581 | if (!Code) |
| 582 | return Reply(make_error<LSPError>("onCodeAction called for non-added file", |
| 583 | ErrorCode::InvalidParams)); |
Sam McCall | 20841d4 | 2018-10-16 16:29:41 +0000 | [diff] [blame] | 584 | // We provide a code action for Fixes on the specified diagnostics. |
Sam McCall | 20841d4 | 2018-10-16 16:29:41 +0000 | [diff] [blame] | 585 | std::vector<CodeAction> Actions; |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 586 | for (const Diagnostic &D : Params.context.diagnostics) { |
Ilya Biryukov | 71028b8 | 2018-03-12 15:28:22 +0000 | [diff] [blame] | 587 | for (auto &F : getFixes(Params.textDocument.uri.file(), D)) { |
Sam McCall | 16e7070 | 2018-10-24 07:59:38 +0000 | [diff] [blame] | 588 | Actions.push_back(toCodeAction(F, Params.textDocument.uri)); |
Sam McCall | 20841d4 | 2018-10-16 16:29:41 +0000 | [diff] [blame] | 589 | Actions.back().diagnostics = {D}; |
Sam McCall | dd0566b | 2017-11-06 15:40:30 +0000 | [diff] [blame] | 590 | } |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 591 | } |
Sam McCall | 20841d4 | 2018-10-16 16:29:41 +0000 | [diff] [blame] | 592 | |
| 593 | if (SupportsCodeAction) |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 594 | Reply(json::Array(Actions)); |
Sam McCall | 20841d4 | 2018-10-16 16:29:41 +0000 | [diff] [blame] | 595 | else { |
| 596 | std::vector<Command> Commands; |
| 597 | for (const auto &Action : Actions) |
| 598 | if (auto Command = asCommand(Action)) |
| 599 | Commands.push_back(std::move(*Command)); |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 600 | Reply(json::Array(Commands)); |
Sam McCall | 20841d4 | 2018-10-16 16:29:41 +0000 | [diff] [blame] | 601 | } |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 604 | void ClangdLSPServer::onCompletion(const TextDocumentPositionParams &Params, |
| 605 | Callback<CompletionList> Reply) { |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 606 | Server->codeComplete(Params.textDocument.uri.file(), Params.position, CCOpts, |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 607 | Bind( |
| 608 | [this](decltype(Reply) Reply, |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 609 | Expected<CodeCompleteResult> List) { |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 610 | if (!List) |
| 611 | return Reply(List.takeError()); |
| 612 | CompletionList LSPList; |
| 613 | LSPList.isIncomplete = List->HasMore; |
| 614 | for (const auto &R : List->Completions) { |
| 615 | CompletionItem C = R.render(CCOpts); |
| 616 | C.kind = adjustKindToCapability( |
| 617 | C.kind, SupportedCompletionItemKinds); |
| 618 | LSPList.items.push_back(std::move(C)); |
| 619 | } |
| 620 | return Reply(std::move(LSPList)); |
| 621 | }, |
| 622 | std::move(Reply))); |
Ilya Biryukov | d9bdfe0 | 2017-10-06 11:54:17 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 625 | void ClangdLSPServer::onSignatureHelp(const TextDocumentPositionParams &Params, |
| 626 | Callback<SignatureHelp> Reply) { |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 627 | Server->signatureHelp(Params.textDocument.uri.file(), Params.position, |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 628 | std::move(Reply)); |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 629 | } |
| 630 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 631 | void ClangdLSPServer::onGoToDefinition(const TextDocumentPositionParams &Params, |
| 632 | Callback<std::vector<Location>> Reply) { |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 633 | Server->findDefinitions(Params.textDocument.uri.file(), Params.position, |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 634 | std::move(Reply)); |
Marc-Andre Laperle | 2cbf037 | 2017-06-28 16:12:10 +0000 | [diff] [blame] | 635 | } |
| 636 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 637 | void ClangdLSPServer::onSwitchSourceHeader(const TextDocumentIdentifier &Params, |
| 638 | Callback<std::string> Reply) { |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 639 | Optional<Path> Result = Server->switchSourceHeader(Params.uri.file()); |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 640 | Reply(Result ? URI::createFile(*Result).toString() : ""); |
Marc-Andre Laperle | 6571b3e | 2017-09-28 03:14:40 +0000 | [diff] [blame] | 641 | } |
| 642 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 643 | void ClangdLSPServer::onDocumentHighlight( |
| 644 | const TextDocumentPositionParams &Params, |
| 645 | Callback<std::vector<DocumentHighlight>> Reply) { |
| 646 | Server->findDocumentHighlights(Params.textDocument.uri.file(), |
| 647 | Params.position, std::move(Reply)); |
Ilya Biryukov | 0e6a51f | 2017-12-12 12:27:47 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 650 | void ClangdLSPServer::onHover(const TextDocumentPositionParams &Params, |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 651 | Callback<Optional<Hover>> Reply) { |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 652 | Server->findHover(Params.textDocument.uri.file(), Params.position, |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 653 | std::move(Reply)); |
Marc-Andre Laperle | 3e618ed | 2018-02-16 21:38:15 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Simon Marchi | 8801678 | 2018-08-01 11:28:49 +0000 | [diff] [blame] | 656 | void ClangdLSPServer::applyConfiguration( |
Sam McCall | bc90461 | 2018-10-25 04:22:52 +0000 | [diff] [blame] | 657 | const ConfigurationSettings &Settings) { |
Simon Marchi | abeed66 | 2018-10-16 15:55:03 +0000 | [diff] [blame] | 658 | // Per-file update to the compilation database. |
Sam McCall | bc90461 | 2018-10-25 04:22:52 +0000 | [diff] [blame] | 659 | bool ShouldReparseOpenFiles = false; |
| 660 | for (auto &Entry : Settings.compilationDatabaseChanges) { |
| 661 | /// The opened files need to be reparsed only when some existing |
| 662 | /// entries are changed. |
| 663 | PathRef File = Entry.first; |
Sam McCall | c55d09a | 2018-11-02 13:09:36 +0000 | [diff] [blame] | 664 | auto Old = CDB->getCompileCommand(File); |
| 665 | auto New = |
| 666 | tooling::CompileCommand(std::move(Entry.second.workingDirectory), File, |
| 667 | std::move(Entry.second.compilationCommand), |
| 668 | /*Output=*/""); |
Sam McCall | 6980edb | 2018-11-02 14:07:51 +0000 | [diff] [blame] | 669 | if (Old != New) { |
Sam McCall | c55d09a | 2018-11-02 13:09:36 +0000 | [diff] [blame] | 670 | CDB->setCompileCommand(File, std::move(New)); |
Sam McCall | 6980edb | 2018-11-02 14:07:51 +0000 | [diff] [blame] | 671 | ShouldReparseOpenFiles = true; |
| 672 | } |
Alex Lorenz | f808786 | 2018-08-01 17:39:29 +0000 | [diff] [blame] | 673 | } |
Sam McCall | bc90461 | 2018-10-25 04:22:52 +0000 | [diff] [blame] | 674 | if (ShouldReparseOpenFiles) |
| 675 | reparseOpenedFiles(); |
Simon Marchi | 5178f92 | 2018-02-22 14:00:39 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Simon Marchi | 8801678 | 2018-08-01 11:28:49 +0000 | [diff] [blame] | 678 | // FIXME: This function needs to be properly tested. |
| 679 | void ClangdLSPServer::onChangeConfiguration( |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 680 | const DidChangeConfigurationParams &Params) { |
Simon Marchi | 8801678 | 2018-08-01 11:28:49 +0000 | [diff] [blame] | 681 | applyConfiguration(Params.settings); |
| 682 | } |
| 683 | |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 684 | void ClangdLSPServer::onReference(const ReferenceParams &Params, |
| 685 | Callback<std::vector<Location>> Reply) { |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 686 | Server->findReferences(Params.textDocument.uri.file(), Params.position, |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 687 | std::move(Reply)); |
Sam McCall | 1ad142f | 2018-09-05 11:53:07 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 690 | ClangdLSPServer::ClangdLSPServer(class Transport &Transp, |
Sam McCall | adccab6 | 2017-11-23 16:58:22 +0000 | [diff] [blame] | 691 | const clangd::CodeCompleteOptions &CCOpts, |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 692 | Optional<Path> CompileCommandsDir, |
Sam McCall | c55d09a | 2018-11-02 13:09:36 +0000 | [diff] [blame] | 693 | bool UseDirBasedCDB, |
Sam McCall | 7363a2f | 2018-03-05 17:28:54 +0000 | [diff] [blame] | 694 | const ClangdServer::Options &Opts) |
Sam McCall | d1c9d11 | 2018-10-23 14:19:54 +0000 | [diff] [blame] | 695 | : Transp(Transp), MsgHandler(new MessageHandler(*this)), CCOpts(CCOpts), |
| 696 | SupportedSymbolKinds(defaultSymbolKinds()), |
Kadir Cetinkaya | 133d46f | 2018-09-27 17:13:07 +0000 | [diff] [blame] | 697 | SupportedCompletionItemKinds(defaultCompletionItemKinds()), |
Sam McCall | c55d09a | 2018-11-02 13:09:36 +0000 | [diff] [blame] | 698 | UseDirBasedCDB(UseDirBasedCDB), |
Sam McCall | 4b86bb0 | 2018-10-25 02:22:53 +0000 | [diff] [blame] | 699 | CompileCommandsDir(std::move(CompileCommandsDir)), |
| 700 | ClangdServerOpts(Opts) { |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 701 | // clang-format off |
| 702 | MsgHandler->bind("initialize", &ClangdLSPServer::onInitialize); |
| 703 | MsgHandler->bind("shutdown", &ClangdLSPServer::onShutdown); |
| 704 | MsgHandler->bind("textDocument/rangeFormatting", &ClangdLSPServer::onDocumentRangeFormatting); |
| 705 | MsgHandler->bind("textDocument/onTypeFormatting", &ClangdLSPServer::onDocumentOnTypeFormatting); |
| 706 | MsgHandler->bind("textDocument/formatting", &ClangdLSPServer::onDocumentFormatting); |
| 707 | MsgHandler->bind("textDocument/codeAction", &ClangdLSPServer::onCodeAction); |
| 708 | MsgHandler->bind("textDocument/completion", &ClangdLSPServer::onCompletion); |
| 709 | MsgHandler->bind("textDocument/signatureHelp", &ClangdLSPServer::onSignatureHelp); |
| 710 | MsgHandler->bind("textDocument/definition", &ClangdLSPServer::onGoToDefinition); |
| 711 | MsgHandler->bind("textDocument/references", &ClangdLSPServer::onReference); |
| 712 | MsgHandler->bind("textDocument/switchSourceHeader", &ClangdLSPServer::onSwitchSourceHeader); |
| 713 | MsgHandler->bind("textDocument/rename", &ClangdLSPServer::onRename); |
| 714 | MsgHandler->bind("textDocument/hover", &ClangdLSPServer::onHover); |
| 715 | MsgHandler->bind("textDocument/documentSymbol", &ClangdLSPServer::onDocumentSymbol); |
| 716 | MsgHandler->bind("workspace/executeCommand", &ClangdLSPServer::onCommand); |
| 717 | MsgHandler->bind("textDocument/documentHighlight", &ClangdLSPServer::onDocumentHighlight); |
| 718 | MsgHandler->bind("workspace/symbol", &ClangdLSPServer::onWorkspaceSymbol); |
| 719 | MsgHandler->bind("textDocument/didOpen", &ClangdLSPServer::onDocumentDidOpen); |
| 720 | MsgHandler->bind("textDocument/didClose", &ClangdLSPServer::onDocumentDidClose); |
| 721 | MsgHandler->bind("textDocument/didChange", &ClangdLSPServer::onDocumentDidChange); |
| 722 | MsgHandler->bind("workspace/didChangeWatchedFiles", &ClangdLSPServer::onFileEvent); |
| 723 | MsgHandler->bind("workspace/didChangeConfiguration", &ClangdLSPServer::onChangeConfiguration); |
| 724 | // clang-format on |
| 725 | } |
| 726 | |
| 727 | ClangdLSPServer::~ClangdLSPServer() = default; |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 728 | |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 729 | bool ClangdLSPServer::run() { |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 730 | // Run the Language Server loop. |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 731 | bool CleanExit = true; |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 732 | if (auto Err = Transp.loop(*MsgHandler)) { |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 733 | elog("Transport error: {0}", std::move(Err)); |
| 734 | CleanExit = false; |
| 735 | } |
Ilya Biryukov | afb5554 | 2017-05-16 14:40:30 +0000 | [diff] [blame] | 736 | |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 737 | // Destroy ClangdServer to ensure all worker threads finish. |
| 738 | Server.reset(); |
Sam McCall | dc8f3cf | 2018-10-17 07:32:05 +0000 | [diff] [blame] | 739 | return CleanExit && ShutdownRequestReceived; |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Ilya Biryukov | 71028b8 | 2018-03-12 15:28:22 +0000 | [diff] [blame] | 742 | std::vector<Fix> ClangdLSPServer::getFixes(StringRef File, |
| 743 | const clangd::Diagnostic &D) { |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 744 | std::lock_guard<std::mutex> Lock(FixItsMutex); |
| 745 | auto DiagToFixItsIter = FixItsMap.find(File); |
| 746 | if (DiagToFixItsIter == FixItsMap.end()) |
| 747 | return {}; |
| 748 | |
| 749 | const auto &DiagToFixItsMap = DiagToFixItsIter->second; |
| 750 | auto FixItsIter = DiagToFixItsMap.find(D); |
| 751 | if (FixItsIter == DiagToFixItsMap.end()) |
| 752 | return {}; |
| 753 | |
| 754 | return FixItsIter->second; |
| 755 | } |
| 756 | |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 757 | void ClangdLSPServer::onDiagnosticsReady(PathRef File, |
| 758 | std::vector<Diag> Diagnostics) { |
Sam McCall | 16e7070 | 2018-10-24 07:59:38 +0000 | [diff] [blame] | 759 | URIForFile URI(File); |
| 760 | std::vector<Diagnostic> LSPDiagnostics; |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 761 | DiagnosticToReplacementMap LocalFixIts; // Temporary storage |
Sam McCall | a7bb0cc | 2018-03-12 23:22:35 +0000 | [diff] [blame] | 762 | for (auto &Diag : Diagnostics) { |
Sam McCall | 16e7070 | 2018-10-24 07:59:38 +0000 | [diff] [blame] | 763 | toLSPDiags(Diag, URI, DiagOpts, |
| 764 | [&](clangd::Diagnostic Diag, ArrayRef<Fix> Fixes) { |
| 765 | auto &FixItsForDiagnostic = LocalFixIts[Diag]; |
| 766 | llvm::copy(Fixes, std::back_inserter(FixItsForDiagnostic)); |
| 767 | LSPDiagnostics.push_back(std::move(Diag)); |
| 768 | }); |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | // Cache FixIts |
| 772 | { |
| 773 | // FIXME(ibiryukov): should be deleted when documents are removed |
| 774 | std::lock_guard<std::mutex> Lock(FixItsMutex); |
| 775 | FixItsMap[File] = LocalFixIts; |
| 776 | } |
| 777 | |
| 778 | // Publish diagnostics. |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 779 | notify("textDocument/publishDiagnostics", |
| 780 | json::Object{ |
Sam McCall | 16e7070 | 2018-10-24 07:59:38 +0000 | [diff] [blame] | 781 | {"uri", URI}, |
| 782 | {"diagnostics", std::move(LSPDiagnostics)}, |
Sam McCall | 2c30fbc | 2018-10-18 12:32:04 +0000 | [diff] [blame] | 783 | }); |
Ilya Biryukov | 38d7977 | 2017-05-16 09:38:59 +0000 | [diff] [blame] | 784 | } |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 785 | |
| 786 | void ClangdLSPServer::reparseOpenedFiles() { |
| 787 | for (const Path &FilePath : DraftMgr.getActiveFiles()) |
Ilya Biryukov | 652364b | 2018-09-26 05:48:29 +0000 | [diff] [blame] | 788 | Server->addDocument(FilePath, *DraftMgr.getDraft(FilePath), |
| 789 | WantDiagnostics::Auto); |
Simon Marchi | 9569fd5 | 2018-03-16 14:30:42 +0000 | [diff] [blame] | 790 | } |
Alex Lorenz | f808786 | 2018-08-01 17:39:29 +0000 | [diff] [blame] | 791 | |
Sam McCall | c008af6 | 2018-10-20 15:30:37 +0000 | [diff] [blame] | 792 | } // namespace clangd |
| 793 | } // namespace clang |