-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nixd: use lspserver for RPC client/server
- Loading branch information
Showing
10 changed files
with
90 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
|
||
#include "EvalProvider.h" | ||
|
||
#include <lspserver/Connection.h> | ||
|
||
#include <nixt/InitEval.h> | ||
|
||
#include <unistd.h> | ||
|
||
int main() { | ||
nixt::initEval(); | ||
nixd::EvalProvider Provider(STDIN_FILENO, STDOUT_FILENO); | ||
return Provider.run(); | ||
auto In = std::make_unique<lspserver::InboundPort>( | ||
STDIN_FILENO, lspserver::JSONStreamStyle::Standard); | ||
|
||
auto Out = std::make_unique<lspserver::OutboundPort>(false); | ||
nixd::EvalProvider Provider(std::move(In), std::move(Out)); | ||
|
||
Provider.run(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,62 @@ | ||
#pragma once | ||
|
||
#include "nixd/rpc/Protocol.h" | ||
#include "nixd/rpc/Transport.h" | ||
|
||
#include "nixd/util/PipedProc.h" | ||
|
||
#include <lspserver/LSPServer.h> | ||
|
||
#include <memory> | ||
#include <thread> | ||
|
||
namespace nixd { | ||
|
||
class EvalClient : public rpc::Transport { | ||
// Owned process of the evaluator | ||
class EvalClient : public lspserver::LSPServer { | ||
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"); | ||
} | ||
|
||
virtual ~EvalClient() = default; | ||
}; | ||
|
||
class OwnedEvalClient : public EvalClient { | ||
std::unique_ptr<util::PipedProc> Proc; | ||
void handleInbound(const std::vector<char> &Buf) override{}; | ||
std::unique_ptr<llvm::raw_fd_ostream> Stream; | ||
|
||
std::thread Input; | ||
|
||
public: | ||
EvalClient(int InboundFD, int OutboundFD, | ||
std::unique_ptr<util::PipedProc> Proc) | ||
: rpc::Transport(InboundFD, OutboundFD), Proc(std::move(Proc)) {} | ||
OwnedEvalClient(std::unique_ptr<lspserver::InboundPort> In, | ||
std::unique_ptr<lspserver::OutboundPort> Out, | ||
std::unique_ptr<util::PipedProc> Proc, | ||
std::unique_ptr<llvm::raw_fd_ostream> Stream) | ||
: EvalClient(std::move(In), std::move(Out)), Proc(std::move(Proc)), | ||
Stream(std::move(Stream)) { | ||
|
||
virtual ~EvalClient() = default; | ||
Input = std::thread([this]() { run(); }); | ||
} | ||
|
||
util::PipedProc &proc() { return *Proc; } | ||
|
||
~OwnedEvalClient() { | ||
closeInbound(); | ||
Input.join(); | ||
} | ||
|
||
/// Lanch nix-node-eval, with properly handled file descriptors. | ||
/// System-wide errno will be written into "Fail" variable and thus cannot be | ||
/// discarded. | ||
static std::unique_ptr<EvalClient> create(int &Fail); | ||
|
||
void registerBC(const rpc::RegisterBCParams &Params); | ||
|
||
rpc::ExprValueResponse exprValue(const rpc::ExprValueParams &Params); | ||
|
||
util::PipedProc *proc() { return Proc.get(); } | ||
static std::unique_ptr<OwnedEvalClient> create(int &Fail); | ||
}; | ||
|
||
} // namespace nixd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters