mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
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).
37 lines
1.0 KiB
C++
37 lines
1.0 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/driver/language_server_subcommand.h"
|
|
|
|
#include "toolchain/language_server/language_server.h"
|
|
|
|
namespace Carbon {
|
|
|
|
static constexpr CommandLine::CommandInfo SubcommandInfo = {
|
|
.name = "language-server",
|
|
.help = R"""(
|
|
Runs the language server.
|
|
)""",
|
|
};
|
|
|
|
LanguageServerSubcommand::LanguageServerSubcommand()
|
|
: DriverSubcommand(SubcommandInfo) {}
|
|
|
|
auto LanguageServerSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
|
|
if (!driver_env.input_stream) {
|
|
*driver_env.error_stream
|
|
<< "error: language-server requires input_stream\n";
|
|
}
|
|
|
|
auto err =
|
|
LanguageServer::Run(driver_env.input_stream, *driver_env.output_stream,
|
|
*driver_env.error_stream);
|
|
if (!err.ok()) {
|
|
*driver_env.error_stream << "error: " << err.error() << "\n";
|
|
}
|
|
return {.success = err.ok()};
|
|
}
|
|
|
|
} // namespace Carbon
|