Files
carbon-lang/toolchain/language_server/language_server.cpp
T
Jon Ross-Perkins 4f024410f7 Add stdin to driver's streams, and refactor stream passing (#4812)
The language server needs stdin, and for tests we should be passing it
around. My intent is to pass in a faux stdin to Driver for language
server tests.

As long as I'm adding a new parameter, I was looking at also changing
the way streams are passed in to Driver for style (pointers since
they're held past construction lifetime). Since these are all stored in
DriverEnv, I thought it might be a net improvement to use the struct
directly, getting more explicit parameter names and also removing the
need for `SetFuzzing`.

I'm trying here to avoid functional changes, but there are a couple
additional fixes like removing an obsolete `find_insensitive` and
refactoring how `ValidateOptions` handles errors (because it reduces the
number of spots that operate on error_stream).
2025-01-21 16:52:05 +00:00

40 lines
1.4 KiB
C++

// 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/language_server.h"
#include "clang-tools-extra/clangd/LSPBinder.h"
#include "clang-tools-extra/clangd/Transport.h"
#include "common/raw_string_ostream.h"
#include "toolchain/language_server/context.h"
#include "toolchain/language_server/incoming_messages.h"
#include "toolchain/language_server/outgoing_messages.h"
namespace Carbon::LanguageServer {
auto Run(FILE* input_stream, llvm::raw_ostream& output_stream,
llvm::raw_ostream& /*error_stream*/) -> ErrorOr<Success> {
// Set up the connection.
std::unique_ptr<clang::clangd::Transport> transport(
clang::clangd::newJSONTransport(input_stream, output_stream,
/*InMirror=*/nullptr,
/*Pretty=*/true));
Context context;
// TODO: Use error_stream in IncomingMessages to report dropped errors.
IncomingMessages incoming(transport.get(), &context);
OutgoingMessages outgoing(transport.get());
// Run the server loop.
llvm::Error err = transport->loop(incoming);
if (err) {
RawStringOstream out;
out << err;
return Error(out.TakeStr());
} else {
return Success();
}
}
} // namespace Carbon::LanguageServer