Skip to content

Commit

Permalink
nixd/Server: sync config with the eval worker
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Jul 27, 2023
1 parent 7945259 commit fd4314b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 13 deletions.
4 changes: 1 addition & 3 deletions nixd/include/nixd/Server/EvalWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class EvalWorker : public lspserver::LSPServer {

std::unique_ptr<IValueEvalResult> IER;

configuration::TopLevel Config;

EvalDraftStore DraftMgr;

template <class ReplyTy>
Expand All @@ -31,7 +29,7 @@ class EvalWorker : public lspserver::LSPServer {

void onDocumentDidOpen(const lspserver::DidOpenTextDocumentParams &Params);

void onEval(const ipc::WorkerMessage &Params);
void onEval(const ipc::EvalParams &Params);

void onDefinition(const lspserver::TextDocumentPositionParams &,
lspserver::Callback<lspserver::Location>);
Expand Down
8 changes: 5 additions & 3 deletions nixd/include/nixd/Server/IPC.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "lspserver/Protocol.h"
#include "nixd/Server/Config.h"

namespace nixd::ipc {

Expand All @@ -21,8 +22,9 @@ struct AttrPathParams {
std::string Path;
};

bool fromJSON(const llvm::json::Value &, AttrPathParams &, llvm::json::Path);

llvm::json::Value toJSON(const AttrPathParams &);
struct EvalParams {
WorkspaceVersionTy WorkspaceVersion;
configuration::TopLevel::Eval Eval;
};

} // namespace nixd::ipc
8 changes: 8 additions & 0 deletions nixd/include/nixd/Server/IPCSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@

namespace nixd::ipc {

llvm::json::Value toJSON(const AttrPathParams &);

llvm::json::Value toJSON(const EvalParams &);

bool fromJSON(const llvm::json::Value &, WorkerMessage &, llvm::json::Path);
llvm::json::Value toJSON(const WorkerMessage &);

bool fromJSON(const llvm::json::Value &, Diagnostics &, llvm::json::Path);
llvm::json::Value toJSON(const Diagnostics &);

bool fromJSON(const llvm::json::Value &, AttrPathParams &, llvm::json::Path);

bool fromJSON(const llvm::json::Value &, EvalParams &, llvm::json::Path);

} // namespace nixd::ipc
11 changes: 7 additions & 4 deletions nixd/lib/Server/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "nixd/Server/ConfigSerialization.h"
#include "nixd/Server/Controller.h"
#include "nixd/Server/EvalDraftStore.h"
#include "nixd/Server/IPC.h"
#include "nixd/Server/IPCSerialization.h"
#include "nixd/Support/Diagnostic.h"
#include "nixd/Support/Support.h"

Expand Down Expand Up @@ -123,9 +123,12 @@ std::unique_ptr<Controller::Proc> Controller::createEvalWorker() {
auto Args = nix::Strings{"nixd", "-role=evaluator"};
auto EvalWorker = selfExec(nix::stringsToCharPtrs(Args).data());
syncDrafts(*EvalWorker);
auto AskEval = mkOutNotifiction<ipc::WorkerMessage>(
"nixd/ipc/eval", EvalWorker->OutPort.get());
AskEval(ipc::WorkerMessage{WorkspaceVersion});
auto AskEval = mkOutNotifiction<ipc::EvalParams>("nixd/ipc/eval",
EvalWorker->OutPort.get());
{
std::lock_guard _(ConfigLock);
AskEval(ipc::EvalParams{WorkspaceVersion, Config.eval});
}
return EvalWorker;
}

Expand Down
6 changes: 3 additions & 3 deletions nixd/lib/Server/EvalWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ void EvalWorker::onDocumentDidOpen(
DraftMgr.addDraft(File, Version, Contents);
}

void EvalWorker::onEval(const ipc::WorkerMessage &Params) {
void EvalWorker::onEval(const ipc::EvalParams &Params) {
auto Session = std::make_unique<IValueEvalSession>();

auto I = Config.eval.target;
auto Depth = Config.eval.depth;
auto I = Params.Eval.target;
auto Depth = Params.Eval.depth;

if (!I.empty())
Session->parseArgs(I.nArgs());
Expand Down
12 changes: 12 additions & 0 deletions nixd/lib/Server/IPCSerialization.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "nixd/Server/IPCSerialization.h"
#include "nixd/Server/ConfigSerialization.h"
#include "nixd/Server/IPC.h"
#include "nixd/Support/JSONSerialization.h"

namespace nixd::ipc {
Expand Down Expand Up @@ -33,4 +35,14 @@ bool fromJSON(const Value &Params, AttrPathParams &R, Path P) {

Value toJSON(const AttrPathParams &R) { return Object{{"Path", R.Path}}; }

Value toJSON(const EvalParams &R) {
return Object{{"Eval", R.Eval}, {"WorkspaceVersion", R.WorkspaceVersion}};
}

bool fromJSON(const Value &Params, EvalParams &R, Path P) {
ObjectMapper O(Params, P);
return O && O.map("Eval", R.Eval) &&
O.map("WorkspaceVersion", R.WorkspaceVersion);
}

} // namespace nixd::ipc
1 change: 1 addition & 0 deletions nixd/lib/Server/OptionWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "nixd/Nix/Option.h"
#include "nixd/Nix/Value.h"
#include "nixd/Server/ConfigSerialization.h"
#include "nixd/Server/IPCSerialization.h"
#include "nixd/Support/Diagnostic.h"
#include "nixd/Support/ReplyRAII.h"

Expand Down

0 comments on commit fd4314b

Please sign in to comment.