nixd
Loading...
Searching...
No Matches
nixd.cpp
Go to the documentation of this file.
1#include "nixd-config.h"
2
4#include "lspserver/Logger.h"
5
8
9#include <llvm/ADT/ArrayRef.h>
10#include <llvm/Support/CommandLine.h>
11
12using namespace lspserver;
13using namespace nixd;
14
15namespace {
16
17using namespace llvm::cl;
18
19OptionCategory Misc("miscellaneous options");
20OptionCategory Debug("debug-only options (for developers)");
21
22const OptionCategory *NixdCatogories[] = {&Misc, &Debug, &nixd::NixdCategory};
23
24opt<JSONStreamStyle> InputStyle{
25 "input-style",
26 desc("Input JSON stream encoding"),
27 values(
28 clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP protocol"),
29 clEnumValN(JSONStreamStyle::LitTest, "lit-test",
30 "Input format for lit-testing")),
32 cat(Debug),
33 Hidden,
34};
35
36opt<Logger::Level> LogLevel{
37 "log", desc("Verbosity of log messages written to stderr"),
38 values(
39 clEnumValN(Logger::Level::Error, "error", "Error messages only"),
40 clEnumValN(Logger::Level::Info, "info", "High level execution tracing"),
41 clEnumValN(Logger::Level::Debug, "debug", "Debugging details"),
42 clEnumValN(Logger::Level::Verbose, "verbose", "Low level details")),
43 init(Logger::Level::Info), cat(Misc)};
44opt<bool> PrettyPrint{"pretty", desc("Pretty-print JSON output"), init(false),
45 cat(Debug)};
46
47} // namespace
48
49int main(int argc, char *argv[]) {
50 SetVersionPrinter([](llvm::raw_ostream &OS) {
51 OS << "nixd, version: ";
52#ifdef NIXD_VCS_TAG
53 OS << NIXD_VCS_TAG;
54#else
55 OS << NIXD_VERSION;
56#endif
57 OS << "\n";
58 });
59
60 HideUnrelatedOptions(NixdCatogories);
61 ParseCommandLineOptions(argc, argv, "nixd language server", nullptr,
62 "NIXD_FLAGS");
63
64 if (LitTest) {
65 InputStyle = JSONStreamStyle::LitTest;
66 LogLevel = Logger::Level::Verbose;
67 PrettyPrint = true;
68 }
69
70 StreamLogger Logger(llvm::errs(), LogLevel);
71 LoggingSession Session(Logger);
72
73 auto In = std::make_unique<lspserver::InboundPort>(STDIN_FILENO, InputStyle);
74
75 auto Out = std::make_unique<lspserver::OutboundPort>(PrettyPrint);
76
77 auto Controller =
78 std::make_unique<nixd::Controller>(std::move(In), std::move(Out));
79
80 Controller->run();
81
82 return 0;
83}
Interface to allow custom logging in clangd.
Definition Logger.h:13
Only one LoggingSession can be active at a time.
Definition Logger.h:91
Whether current platform treats paths case insensitively.
Definition Connection.h:11
llvm::cl::OptionCategory NixdCategory
llvm::cl::opt< bool > LitTest
Indicating that we are in lit-test mode.
Definition Options.cpp:8
int main(int argc, char *argv[])
Definition nixd.cpp:49