-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nixd-next: init, without any capabilities
- Loading branch information
Showing
7 changed files
with
158 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,3 +47,4 @@ subdir('lspserver') | |
subdir('libnixf') | ||
subdir('libnixt') | ||
subdir('nixd') | ||
subdir('nixd-next') |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
subdir('tools') |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
subdir('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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
nixd_next = executable('nixd-next', | ||
'src/Controller.cpp', | ||
'src/Main.cpp', | ||
install: true, | ||
dependencies: [ nixd_lsp_server, nixf, llvm ] | ||
) |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/// \file | ||
/// \brief Controller. The process interacting with users. | ||
#include "nixd-config.h" | ||
|
||
#include "lspserver/LSPServer.h" | ||
|
||
#include <llvm/Support/JSON.h> | ||
|
||
namespace { | ||
|
||
using namespace lspserver; | ||
using namespace llvm::json; | ||
|
||
class Controller : public LSPServer { | ||
public: | ||
Controller(std::unique_ptr<InboundPort> In, std::unique_ptr<OutboundPort> Out) | ||
: LSPServer(std::move(In), std::move(Out)) { | ||
|
||
// Life Cycle | ||
Registry.addMethod("initialize", this, &Controller::onInitialize); | ||
Registry.addNotification("initialized", this, &Controller::onInitialized); | ||
} | ||
|
||
void onInitialize( // NOLINT(readability-convert-member-functions-to-static) | ||
[[maybe_unused]] const InitializeParams &Params, Callback<Value> Reply) { | ||
|
||
Object ServerCaps{ | ||
{}, | ||
}; | ||
|
||
Object Result{{ | ||
{"serverInfo", | ||
Object{ | ||
{"name", "nixd"}, | ||
{"version", NIXD_VERSION}, | ||
}}, | ||
{"capabilities", std::move(ServerCaps)}, | ||
}}; | ||
|
||
Reply(std::move(Result)); | ||
} | ||
void onInitialized([[maybe_unused]] const InitializedParams &Params) {} | ||
}; | ||
|
||
} // namespace | ||
|
||
namespace nixd { | ||
void launchController(std::unique_ptr<InboundPort> In, | ||
std::unique_ptr<OutboundPort> Out) { | ||
Controller C(std::move(In), std::move(Out)); | ||
C.run(); | ||
} | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "lspserver/Connection.h" | ||
|
||
#include <memory> | ||
|
||
namespace nixd { | ||
|
||
[[noreturn]] void | ||
launchController(std::unique_ptr<lspserver::InboundPort> In, | ||
std::unique_ptr<lspserver::OutboundPort> Out); | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "nixd-config.h" | ||
|
||
#include "lspserver/Connection.h" | ||
#include "lspserver/Logger.h" | ||
|
||
#include "Controller.h" | ||
|
||
#include <llvm/ADT/ArrayRef.h> | ||
#include <llvm/Support/CommandLine.h> | ||
|
||
using namespace lspserver; | ||
|
||
namespace { | ||
|
||
using namespace llvm::cl; | ||
|
||
OptionCategory Misc("miscellaneous options"); | ||
OptionCategory Debug("debug-only options (for developers)"); | ||
|
||
const OptionCategory *NixdCatogories[] = {&Misc, &Debug}; | ||
|
||
opt<JSONStreamStyle> InputStyle{ | ||
"input-style", | ||
desc("Input JSON stream encoding"), | ||
values( | ||
clEnumValN(JSONStreamStyle::Standard, "standard", "usual LSP protocol"), | ||
clEnumValN(JSONStreamStyle::Delimited, "delimited", | ||
"messages delimited by `// -----` lines, " | ||
"with // comment support")), | ||
init(JSONStreamStyle::Standard), | ||
cat(Debug), | ||
Hidden, | ||
}; | ||
opt<bool> LitTest{ | ||
"lit-test", | ||
desc("Abbreviation for -input-style=delimited -pretty -log=verbose. " | ||
"Intended to simplify lit tests"), | ||
init(false), cat(Debug)}; | ||
opt<Logger::Level> LogLevel{ | ||
"log", desc("Verbosity of log messages written to stderr"), | ||
values( | ||
clEnumValN(Logger::Level::Error, "error", "Error messages only"), | ||
clEnumValN(Logger::Level::Info, "info", "High level execution tracing"), | ||
clEnumValN(Logger::Level::Debug, "debug", "Debugging details"), | ||
clEnumValN(Logger::Level::Verbose, "verbose", "Low level details")), | ||
init(Logger::Level::Info), cat(Misc)}; | ||
opt<bool> PrettyPrint{"pretty", desc("Pretty-print JSON output"), init(false), | ||
cat(Debug)}; | ||
|
||
} // namespace | ||
|
||
int main(int argc, char *argv[]) { | ||
SetVersionPrinter([](llvm::raw_ostream &OS) { | ||
OS << "nixd, version: "; | ||
#ifdef NIXD_VCS_TAG | ||
OS << NIXD_VCS_TAG; | ||
#else | ||
OS << NIXD_VERSION; | ||
#endif | ||
OS << "\n"; | ||
}); | ||
|
||
HideUnrelatedOptions(NixdCatogories); | ||
ParseCommandLineOptions(argc, argv, "nixd language server", nullptr, | ||
"NIXD_FLAGS"); | ||
|
||
if (LitTest) { | ||
InputStyle = JSONStreamStyle::Delimited; | ||
LogLevel = Logger::Level::Verbose; | ||
PrettyPrint = true; | ||
} | ||
|
||
StreamLogger Logger(llvm::errs(), LogLevel); | ||
LoggingSession Session(Logger); | ||
|
||
auto In = std::make_unique<lspserver::InboundPort>(STDIN_FILENO, InputStyle); | ||
|
||
auto Out = std::make_unique<lspserver::OutboundPort>(PrettyPrint); | ||
|
||
nixd::launchController(std::move(In), std::move(Out)); | ||
|
||
return 0; | ||
} |