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