6#include "nixd-config.h"
16#include <llvm/Support/CommandLine.h>
20using namespace llvm::json;
21using namespace llvm::cl;
26opt<std::string> DefaultNixpkgsExpr{
28 desc(
"Default expression intrepreted as `import <nixpkgs> { }`"),
31opt<std::string> DefaultNixOSOptionsExpr{
33 desc(
"Default expression interpreted as option declarations"),
35 init(
"(let pkgs = import <nixpkgs> { }; in (pkgs.lib.evalModules { modules "
36 "= (import <nixpkgs/nixos/modules/module-list.nix>) ++ [ ({...}: { "
37 "nixpkgs.hostPlatform = builtins.currentSystem;} ) ] ; })).options")};
39opt<bool> EnableSemanticTokens{
"semantic-tokens",
40 desc(
"Enable/Disable semantic tokens"),
44std::string getDefaultNixpkgsExpr() {
45 if (
LitTest && !DefaultNixpkgsExpr.getNumOccurrences()) {
48 return DefaultNixpkgsExpr;
51std::string getDefaultNixOSOptionsExpr() {
52 if (
LitTest && !DefaultNixOSOptionsExpr.getNumOccurrences()) {
55 return DefaultNixOSOptionsExpr;
62 std::string_view Description) {
64 auto Action = [Token, Description = std::string(Description),
65 this](llvm::Expected<EvalExprResponse> Resp) {
69 std::string(Description)},
76 createWorkDoneProgress({Token});
77 beginWorkDoneProgress({.token = Token,
79 .title =
"evaluating " + std::string(Description),
83 Client.
evalExpr(Params, std::move(Action));
95 {
"change", (int)TextDocumentSyncKind::Incremental},
102 {
"resolveProvider",
false},
105 {
"definitionProvider",
true},
106 {
"documentLinkProvider",
Object{}},
107 {
"documentSymbolProvider",
true},
108 {
"inlayHintProvider",
true},
109 {
"completionProvider",
111 {
"resolveProvider",
true},
112 {
"triggerCharacters", {
"."}},
114 {
"referencesProvider",
true},
115 {
"documentHighlightProvider",
true},
116 {
"hoverProvider",
true},
117 {
"documentFormattingProvider",
true},
120 {
"prepareProvider",
true},
124 if (EnableSemanticTokens) {
125 ServerCaps[
"semanticTokensProvider"] =
Object{
162 {
"version", NIXD_VERSION},
164 {
"capabilities", std::move(ServerCaps)},
167 Reply(std::move(Result));
169 ClientCaps = Params.capabilities;
174 if (nixpkgsClient()) {
175 evalExprWithProgress(*nixpkgsClient(), getDefaultNixpkgsExpr(),
181 std::lock_guard
_(OptionsLock);
185 evalExprWithProgress(*Client, getDefaultNixOSOptionsExpr(),
202 ReceivedShutdown =
true;
Allow default configuration being passed via CLI.
void evalExpr(const EvalExprParams &Params, lspserver::Callback< EvalExprResponse > Reply)
Request eval some expression. The expression should be evaluted to attrset.
Whether current platform treats paths case insensitively.
llvm::unique_function< void(llvm::Expected< T >)> Callback
void elog(const char *Fmt, Ts &&...Vals)
std::string EvalExprParams
llvm::cl::OptionCategory NixdCategory
void startOption(const std::string &Name, std::unique_ptr< AttrSetClientProc > &Worker)
nixd::Configuration parseCLIConfig()
Parse the CLI flag and initialize the config nixd::DefaultConfig.
void startNixpkgs(std::unique_ptr< AttrSetClientProc > &NixpkgsEval)
llvm::cl::opt< bool > LitTest
Indicating that we are in lit-test mode.
static const llvm::StringLiteral QUICKFIX_KIND
Signals the end of progress reporting.