Refactor the language server structure. (#4721)

I'm trying to make the LSP look more like the rest of the toolchain. I'm
trying to separate the handlers from the transport layer, and remove the
multiple inheritance aspect. Also fixing some style issues, switching to
`Map`, and removing an unnecessary copt.

I'm using `Context` for the central object for consistency with other
portions of the toolchain. In order to get the `handle_*` files working,
I'm using LLVM's registry class. It has a quirk that I can't register
two registries in the same cpp file, so there are two one-line cpp
files.

In order to help show the delta (or lack thereof) for actual
implementation, I've copied server.cpp over handle_* and undone that in
two commits. See the third and fourth commits on the PR history for
that.
This commit is contained in:
Jon Ross-Perkins
2025-01-08 06:01:51 +00:00
committed by GitHub
parent aaef516600
commit 96d836f965
12 changed files with 489 additions and 276 deletions
@@ -0,0 +1,20 @@
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "toolchain/language_server/handle.h"
namespace Carbon::LanguageServer {
auto HandleInitialize(
Context& /*context*/,
const clang::clangd::NoParams& /*client_capabilities*/,
llvm::function_ref<void(llvm::Expected<llvm::json::Object>)> on_done)
-> void {
llvm::json::Object capabilities{{"documentSymbolProvider", true},
{"textDocumentSync", /*Full=*/1}};
llvm::json::Object reply{{"capabilities", std::move(capabilities)}};
on_done(reply);
}
} // namespace Carbon::LanguageServer