Skip to content

Commit

Permalink
nixd: refactor into library-like structure (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Apr 8, 2024
1 parent 1066132 commit 83a1305
Show file tree
Hide file tree
Showing 36 changed files with 91 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Controller : public lspserver::LSPServer {
Controller(std::unique_ptr<lspserver::InboundPort> In,
std::unique_ptr<lspserver::OutboundPort> Out);

~Controller() { Pool.join(); }
~Controller() override { Pool.join(); }

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "nixd/rpc/Protocol.h"
#include "nixd/Protocol/Protocol.h"

#include "nixd/util/PipedProc.h"
#include "nixd/Support/PipedProc.h"

#include <lspserver/LSPServer.h>

Expand All @@ -23,8 +23,6 @@ class EvalClient : public lspserver::LSPServer {
EvalClient(std::unique_ptr<lspserver::InboundPort> In,
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",
Expand Down Expand Up @@ -54,7 +52,7 @@ class OwnedEvalClient : public EvalClient {

util::PipedProc &proc() { return *Proc; }

~OwnedEvalClient() {
~OwnedEvalClient() override {
closeInbound();
Input.join();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "nixd/util/OwnedRegion.h"
#include "nixd/Support/OwnedRegion.h"

#include "nixf/Basic/Diagnostic.h"
#include "nixf/Basic/Nodes/Basic.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "nixd/rpc/Protocol.h"
#include "nixd/Protocol/Protocol.h"

#include <lspserver/Function.h>
#include <lspserver/LSPServer.h>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
/// [Code Action]:
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction

#include "Controller.h"
#include "Convert.h"

#include "nixd/Controller/Controller.h"

#include <boost/asio/post.hpp>

namespace nixd {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
/// [PublishDiagnostics Notification]:
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics

#include "Controller.h"
#include "Convert.h"

#include "nixd/Controller/Controller.h"

namespace nixd {

using namespace llvm::json;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "nixd-config.h"

#include "EvalClient.h"

#include "nixd/util/ForkPiped.h"
#include "nixd/Controller/EvalClient.h"
#include "nixd/Support/ForkPiped.h"

#include <bc/Read.h>
#include <bc/Write.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
/// [Hover Request]:
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_hover

#include "Controller.h"
#include "Convert.h"

#include "nixd/Controller/Controller.h"

#include <llvm/Support/Error.h>

#include <boost/asio/post.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

#include "nixd-config.h"

#include "Controller.h"
#include "EvalClient.h"

#include "nixd/util/PipedProc.h"
#include "nixd/Controller/Controller.h"
#include "nixd/Controller/EvalClient.h"
#include "nixd/Support/PipedProc.h"

#include <cstring>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Controller.h"

#include "nixd/rpc/Protocol.h"
#include "nixd/util/OwnedRegion.h"
#include "nixd/Controller/Controller.h"
#include "nixd/Protocol/Protocol.h"
#include "nixd/Support/OwnedRegion.h"

#include "nixf/Basic/Diagnostic.h"
#include "nixf/Bytecode/Write.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// \file
/// \brief Implementation of the [text document
/// sync](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_synchronization).
#include "Controller.h"
#include "nixd/Controller/Controller.h"

#include "lspserver/SourceCode.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "EvalProvider.h"

#include "nixd/rpc/Protocol.h"
#include "nixd/Eval/EvalProvider.h"
#include "nixd/Protocol/Protocol.h"

#include <nixt/Deserialize.h>
#include <nixt/HackCache.h>
Expand Down Expand Up @@ -31,8 +30,7 @@ using namespace rpc;
EvalProvider::EvalProvider(std::unique_ptr<lspserver::InboundPort> In,
std::unique_ptr<lspserver::OutboundPort> Out)
: lspserver::LSPServer(std::move(In), std::move(Out)),
State(std::unique_ptr<nix::EvalState>(
new nix::EvalState{{}, nix::openStore("dummy://")})) {
State(new nix::EvalState{{}, nix::openStore()}) {
Registry.addMethod("exprValue", this, &EvalProvider::onExprValue);
Registry.addNotification("registerBC", this, &EvalProvider::onRegisterBC);

Expand Down
Empty file added nixd/lib/Eval/Main.cpp
Empty file.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#include "nixd/rpc/Protocol.h"
#include "nixd/Protocol/Protocol.h"

#include <bc/Read.h>
#include <bc/Write.h>

namespace nixd::rpc {

using bc::readBytecode;
using bc::writeBytecode;
using namespace llvm::json;

Value toJSON(const RegisterBCParams &Params) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "nixd/util/AutoCloseFD.h"
#include "nixd/Support/AutoCloseFD.h"

#include <unistd.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "nixd/util/AutoRemoveShm.h"
#include "nixd/Support/AutoRemoveShm.h"

namespace nixd::util {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "nixd/util/ForkPiped.h"
#include "nixd/Support/ForkPiped.h"

#include <cerrno>

Expand Down
24 changes: 0 additions & 24 deletions nixd/librpc/meson.build

This file was deleted.

12 changes: 0 additions & 12 deletions nixd/librpc/test/Transport.cpp

This file was deleted.

19 changes: 0 additions & 19 deletions nixd/libutil/meson.build

This file was deleted.

65 changes: 61 additions & 4 deletions nixd/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
subdir('librpc')
subdir('libutil')
subdir('nix-node-eval')
subdir('tools')
libnixd_include = include_directories('include')

libnixd_deps = [ nixd_lsp_server, nixf, llvm, nixt ]

libnixd_lib = library(
'nixd',
'lib/Controller/CodeAction.cpp',
'lib/Controller/Convert.cpp',
'lib/Controller/Diagnostics.cpp',
'lib/Controller/EvalClient.cpp',
'lib/Controller/Hover.cpp',
'lib/Controller/LifeTime.cpp',
'lib/Controller/Support.cpp',
'lib/Controller/TextDocumentSync.cpp',
'lib/Eval/EvalProvider.cpp',
'lib/Protocol/Protocol.cpp',
'lib/Support/AutoCloseFD.cpp',
'lib/Support/AutoRemoveShm.cpp',
'lib/Support/ForkPiped.cpp',
dependencies: libnixd_deps,
include_directories: libnixd_include,
install: true
)

libnixd = declare_dependency(
include_directories: libnixd_include,
link_with: libnixd_lib,
dependencies: libnixd_deps
)

nixd = executable(
'nixd',
'tools/nixd.cpp',
install: true,
dependencies: libnixd
)

regression_env = environment()

regression_env.append('PATH', meson.current_build_dir())
regression_env.set('MESON_BUILD_ROOT', meson.current_build_dir())

if lit.found()
test(
'regression/nixd',
lit,
env: regression_env,
args: [
'-vv',
meson.current_source_dir() + '/tools/nixd/test'
],
depends: [ nixd ] )
endif


nix_node_eval = executable(
'nix-node-eval',
'tools/nix-node-eval.cpp',
install: true,
dependencies: libnixd
)
3 changes: 0 additions & 3 deletions nixd/nix-node-eval/README.md

This file was deleted.

21 changes: 0 additions & 21 deletions nixd/nix-node-eval/meson.build

This file was deleted.

1 change: 0 additions & 1 deletion nixd/tools/meson.build

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "EvalProvider.h"
#include "nixd/Eval/EvalProvider.h"

#include <lspserver/Connection.h>

Expand Down
2 changes: 1 addition & 1 deletion nixd/tools/nixd/src/Main.cpp → nixd/tools/nixd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "lspserver/Connection.h"
#include "lspserver/Logger.h"

#include "Controller.h"
#include "nixd/Controller/Controller.h"

#include <llvm/ADT/ArrayRef.h>
#include <llvm/Support/CommandLine.h>
Expand Down
31 changes: 0 additions & 31 deletions nixd/tools/nixd/meson.build

This file was deleted.

0 comments on commit 83a1305

Please sign in to comment.