Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixd/Controller: Conditionally include devenv option support by default #584

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions nixd/lib/Controller/LifeTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ opt<std::string> DefaultNixOSOptionsExpr{
"= (import <nixpkgs/nixos/modules/module-list.nix>) ++ [ ({...}: { "
"nixpkgs.hostPlatform = builtins.currentSystem;} ) ] ; })).options")};

opt<std::string> DefaultDevenvOptionsExpr{
"devenv-options-expr",
desc("Default expression interpreted as devenv option declarations"),
cat(NixdCategory),
init("let\n"
" currentSystem = builtins.currentSystem;\n"
" flake = builtins.getFlake \"github:cachix/devenv\";\n"
"in\n"
" if builtins.hasAttr currentSystem flake.outputs.packages\n"
" then "
"flake.outputs.packages.${currentSystem}.devenv-module-options."
"options\n"
" else {}")};

opt<bool> EnableSemanticTokens{"semantic-tokens",
desc("Enable/Disable semantic tokens"),
init(true), cat(NixdCategory)};
Expand All @@ -48,6 +62,18 @@ std::string getDefaultNixpkgsExpr() {
return DefaultNixpkgsExpr;
}

// Check if devenv executable is present
bool isDevenvAvailable() {
return std::system("which devenv > /dev/null 2>&1") == 0;
}

std::string getDefaultDevenvOptionsExpr() {
if (LitTest && !DefaultDevenvOptionsExpr.getNumOccurrences()) {
return "{ }";
}
return DefaultDevenvOptionsExpr;
}

std::string getDefaultNixOSOptionsExpr() {
if (LitTest && !DefaultNixOSOptionsExpr.getNumOccurrences()) {
return "{ }";
Expand Down Expand Up @@ -192,6 +218,20 @@ void Controller::
Err.takeError());
std::exit(-1);
}

// Launch devenv worker only if devenv is available
if (isDevenvAvailable()) {
std::lock_guard _(OptionsLock);
startOption("devenv", Options["devenv"]);

if (AttrSetClient *Client = Options["devenv"]->client()) {
evalExprWithProgress(*Client, getDefaultDevenvOptionsExpr(),
"devenv options");
}
} else {
lspserver::log("devenv not found, skipping devenv initialization");
}

fetchConfig();
}

Expand Down
Loading