nixd
Loading...
Searching...
No Matches
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
21
22#include "lspserver/LSPServer.h"
23
24#include <nix/eval.hh>
25
26#include <memory>
27
28namespace nixd {
29
30/// \brief Main RPC class for attrset provider.
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
43public:
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,
50
51 /// \brief Query attrpath information.
52 void onAttrPathInfo(const AttrPathInfoParams &AttrPath,
54
55 /// \brief Complete attrpath entries.
58
59 /// \brief Provide option information on given attrpath.
60 void onOptionInfo(const AttrPathInfoParams &AttrPath,
62
63 /// \brief Complete attrpath entries. However dive into submodules while
64 /// selecting.
65 ///
66 /// FIXME: suppport list names. i.e. `foo.*.submodule`
69};
70
71} // namespace nixd
Types used in nixpkgs provider.
Main RPC class for attrset provider.
void onOptionInfo(const AttrPathInfoParams &AttrPath, lspserver::Callback< OptionInfoResponse > Reply)
Provide option information on given attrpath.
void onAttrPathInfo(const AttrPathInfoParams &AttrPath, lspserver::Callback< AttrPathInfoResponse > Reply)
Query attrpath information.
void onEvalExpr(const EvalExprParams &Name, lspserver::Callback< EvalExprResponse > Reply)
Eval an expression, use it for furthur requests.
AttrSetProvider(std::unique_ptr< lspserver::InboundPort > In, std::unique_ptr< lspserver::OutboundPort > Out)
void onAttrPathComplete(const AttrPathCompleteParams &Params, lspserver::Callback< AttrPathCompleteResponse > Reply)
Complete attrpath entries.
void onOptionComplete(const AttrPathCompleteParams &Params, lspserver::Callback< OptionCompleteResponse > Reply)
Complete attrpath entries. However dive into submodules while selecting.
llvm::unique_function< void(llvm::Expected< T >)> Callback
Definition Function.h:14
std::string EvalExprParams
Definition AttrSet.h:38
Selector AttrPathInfoParams
Definition AttrSet.h:47