nixd
Toggle main menu visibility
Loading...
Searching...
No Matches
nixd
include
nixd
Eval
AttrSetProvider.h
Go to the documentation of this file.
1
/// \file
2
/// \brief Dedicated worker for evaluating attrset.
3
///
4
/// Motivation: eval things in attrset (e.g. nixpkgs). (packages, functions ...)
5
///
6
/// Observation:
7
/// 1. Fast: eval (import <nixpkgs> { }).
8
/// 2. Slow: eval a whole NixOS config until some node is being touched.
9
///
10
/// This worker is designed to answer "packages"/"functions" in nixpkgs, but not
11
/// limited to it.
12
///
13
/// For time-saving:
14
/// Once a value is evaluated. It basically assume it will not change.
15
/// That is, any workspace editing will not invalidate the value.
16
///
17
18
#pragma once
19
20
#include "
nixd/Protocol/AttrSet.h
"
21
22
#include "
lspserver/LSPServer.h
"
23
24
#include <nix/expr/eval.hh>
25
26
#include <memory>
27
28
namespace
nixd
{
29
30
/// \brief Main RPC class for attrset provider.
31
class
AttrSetProvider
:
public
lspserver::LSPServer
{
32
33
std::unique_ptr<nix::EvalState> State;
34
35
nix::Value Nixpkgs;
36
37
/// Convenient method for get state. Basically assume this->State is not null
38
nix::EvalState &state() {
39
assert(State &&
"State should be allocated by ctor!"
);
40
return
*State;
41
}
42
43
public
:
44
AttrSetProvider
(std::unique_ptr<lspserver::InboundPort> In,
45
std::unique_ptr<lspserver::OutboundPort> Out);
46
47
/// \brief Eval an expression, use it for furthur requests.
48
void
onEvalExpr
(
const
EvalExprParams
&Name,
49
lspserver::Callback<EvalExprResponse>
Reply);
50
51
/// \brief Query attrpath information.
52
void
onAttrPathInfo
(
const
AttrPathInfoParams
&AttrPath,
53
lspserver::Callback<AttrPathInfoResponse>
Reply);
54
55
/// \brief Complete attrpath entries.
56
void
onAttrPathComplete
(
const
AttrPathCompleteParams
&Params,
57
lspserver::Callback<AttrPathCompleteResponse>
Reply);
58
59
/// \brief Provide option information on given attrpath.
60
void
onOptionInfo
(
const
AttrPathInfoParams
&AttrPath,
61
lspserver::Callback<OptionInfoResponse>
Reply);
62
63
/// \brief Complete attrpath entries. However dive into submodules while
64
/// selecting.
65
///
66
/// FIXME: suppport list names. i.e. `foo.*.submodule`
67
void
onOptionComplete
(
const
AttrPathCompleteParams
&Params,
68
lspserver::Callback<OptionCompleteResponse>
Reply);
69
};
70
71
}
// namespace nixd
AttrSet.h
Types used in nixpkgs provider.
LSPServer.h
lspserver::LSPServer
Definition
LSPServer.h:17
nixd::AttrSetProvider::onOptionInfo
void onOptionInfo(const AttrPathInfoParams &AttrPath, lspserver::Callback< OptionInfoResponse > Reply)
Provide option information on given attrpath.
Definition
AttrSetProvider.cpp:341
nixd::AttrSetProvider::onAttrPathInfo
void onAttrPathInfo(const AttrPathInfoParams &AttrPath, lspserver::Callback< AttrPathInfoResponse > Reply)
Query attrpath information.
Definition
AttrSetProvider.cpp:296
nixd::AttrSetProvider::onEvalExpr
void onEvalExpr(const EvalExprParams &Name, lspserver::Callback< EvalExprResponse > Reply)
Eval an expression, use it for furthur requests.
Definition
AttrSetProvider.cpp:279
nixd::AttrSetProvider::AttrSetProvider
AttrSetProvider(std::unique_ptr< lspserver::InboundPort > In, std::unique_ptr< lspserver::OutboundPort > Out)
Definition
AttrSetProvider.cpp:263
nixd::AttrSetProvider::onAttrPathComplete
void onAttrPathComplete(const AttrPathCompleteParams &Params, lspserver::Callback< AttrPathCompleteResponse > Reply)
Complete attrpath entries.
Definition
AttrSetProvider.cpp:320
nixd::AttrSetProvider::onOptionComplete
void onOptionComplete(const AttrPathCompleteParams &Params, lspserver::Callback< OptionCompleteResponse > Reply)
Complete attrpath entries. However dive into submodules while selecting.
Definition
AttrSetProvider.cpp:368
lspserver::Callback
llvm::unique_function< void(llvm::Expected< T >)> Callback
Definition
Function.h:14
nixd
Definition
CommandLine/Configuration.h:9
nixd::EvalExprParams
std::string EvalExprParams
Definition
AttrSet.h:39
nixd::AttrPathInfoParams
Selector AttrPathInfoParams
Definition
AttrSet.h:48
nixd::AttrPathCompleteParams
Definition
AttrSet.h:107
Generated by
1.17.0