Skip to content

Commit

Permalink
nixd: worker ready notification
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Mar 29, 2024
1 parent 139d129 commit 0aa504f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions nixd/nix-node-eval/src/EvalProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ EvalProvider::EvalProvider(std::unique_ptr<lspserver::InboundPort> In,
new nix::EvalState{{}, nix::openStore("dummy://")})) {
Registry.addMethod("exprValue", this, &EvalProvider::onExprValue);
Registry.addNotification("registerBC", this, &EvalProvider::onRegisterBC);

Ready = mkOutNotifiction<int>("ready");

Ready(getpid());
}

void EvalProvider::onRegisterBC(const rpc::RegisterBCParams &Params) {
Expand Down
2 changes: 1 addition & 1 deletion nixd/nix-node-eval/src/EvalProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EvalProvider : public lspserver::LSPServer {
nixt::EnvMap EMap;
std::unique_ptr<nix::EvalState> State;

llvm::unique_function<void(int)> Exit;
llvm::unique_function<void(int)> Ready;

public:
EvalProvider(std::unique_ptr<lspserver::InboundPort> In,
Expand Down
2 changes: 2 additions & 0 deletions nixd/tools/nixd/src/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Controller : public lspserver::LSPServer {
~Controller() { Pool.join(); }

void setLitTest(bool LitTest) { this->LitTest = LitTest; }

bool isReadyToEval() { return Eval && Eval->ready(); }
};

} // namespace nixd
9 changes: 9 additions & 0 deletions nixd/tools/nixd/src/EvalClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ std::unique_ptr<OwnedEvalClient> OwnedEvalClient::create(int &Fail) {
std::move(ProcFdStream));
}

EvalClient::EvalClient(std::unique_ptr<lspserver::InboundPort> In,
std::unique_ptr<lspserver::OutboundPort> Out)
: lspserver::LSPServer(std::move(In), std::move(Out)), Ready(false) {
RegisterBC = mkOutNotifiction<rpc::RegisterBCParams>("registerBC");
ExprValue =
mkOutMethod<rpc::ExprValueParams, rpc::ExprValueResponse>("exprValue");
Registry.addNotification("ready", this, &EvalClient::onReady);
}

} // namespace nixd
18 changes: 12 additions & 6 deletions nixd/tools/nixd/src/EvalClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@
namespace nixd {

class EvalClient : public lspserver::LSPServer {
std::atomic<bool> Ready;

public:
llvm::unique_function<void(const rpc::RegisterBCParams &)> RegisterBC;
llvm::unique_function<void(const rpc::ExprValueParams &,
lspserver::Callback<rpc::ExprValueResponse>)>
ExprValue;

EvalClient(std::unique_ptr<lspserver::InboundPort> In,
std::unique_ptr<lspserver::OutboundPort> Out)
: lspserver::LSPServer(std::move(In), std::move(Out)) {
RegisterBC = mkOutNotifiction<rpc::RegisterBCParams>("registerBC");
ExprValue =
mkOutMethod<rpc::ExprValueParams, rpc::ExprValueResponse>("exprValue");
}
std::unique_ptr<lspserver::OutboundPort> Out);

virtual ~EvalClient() = default;

void onReady(const int &Flags) {
lspserver::log(
"nix-node-eval({0}) reported it's ready for processing requests",
Flags);
Ready = true;
}

bool ready() { return Ready; }
};

class OwnedEvalClient : public EvalClient {
Expand Down

0 comments on commit 0aa504f

Please sign in to comment.