4#include <boost/asio/post.hpp>
8using llvm::json::ObjectMapper;
9using llvm::json::Value;
13 ObjectMapper O(Params, P);
14 return O && O.mapOptional(
"suppress", R.
suppress);
20 if (
auto Str = Params.getAsString()) {
24 ObjectMapper O(Params, P);
25 return O && O.mapOptional(
"command", R.
command);
30 ObjectMapper O(Params, P);
31 return O && O.mapOptional(
"expr", R.
expr);
36 ObjectMapper O(Params, P);
37 return O && O.mapOptional(
"expr", R.
expr);
41 ObjectMapper O(Params, P);
44 && O.mapOptional(
"options", R.
options)
45 && O.mapOptional(
"nixpkgs", R.
nixpkgs)
50void Controller::onDidChangeConfiguration(
57 std::lock_guard G(ConfigLock);
58 Config = std::move(NewConfig);
62 if (nixpkgsClient()) {
63 evalExprWithProgress(*nixpkgsClient(), Config.
nixpkgs.
expr,
68 std::lock_guard
_(OptionsLock);
70 for (
const auto &[Name, Opt] : Config.
options) {
71 auto &Client = Options[Name];
77 evalExprWithProgress(*Client->client(), Opt.expr, Name);
85 std::lock_guard TUsGuard(TUsLock);
86 for (
const auto &[
File, TU] : TUs) {
87 publishDiagnostics(
File, std::nullopt, TU->src(), TU->diagnostics());
91void Controller::fetchConfig() {
92 auto Action = [
this](llvm::Expected<llvm::json::Value> Resp)
mutable {
94 elog(
"workspace/configuration: {0}", Resp.takeError());
99 if (Resp->kind() != llvm::json::Value::Array) {
100 lspserver::elog(
"workspace/configuration response is not an array: {0}",
104 const Value &FirstConfig = Resp->getAsArray()->front();
107 auto ConfigAction = [
this, FirstConfig]()
mutable {
110 llvm::json::Path::Root P;
111 if (!
fromJSON(FirstConfig, NewConfig, P)) {
112 elog(
"workspace/configuration: parse error {0}", P.getError());
117 updateConfig(std::move(NewConfig));
120 boost::asio::post(Pool, std::move(ConfigAction));
126void Controller::workspaceConfiguration(
130 WorkspaceConfiguration(Params, std::move(Reply));
Whether current platform treats paths case insensitively.
llvm::unique_function< void(llvm::Expected< T >)> Callback
llvm::Error error(std::error_code EC, const char *Fmt, Ts &&...Vals)
void elog(const char *Fmt, Ts &&...Vals)
bool fromJSON(const llvm::json::Value &Params, Configuration::Diagnostic &R, llvm::json::Path P)
void startOption(const std::string &Name, std::unique_ptr< AttrSetClientProc > &Worker)
bool WorkspaceConfiguration
std::vector< std::string > suppress
std::string expr
Expression to eval. Treat it as "import <nixpkgs> { }".
std::string expr
Expression to eval. Select this attrset as eval .options.
struct nixd::Configuration::Formatting formatting
std::map< std::string, OptionProvider > options
struct nixd::Configuration::Diagnostic diagnostic
struct nixd::Configuration::NixpkgsProvider nixpkgs