nixd
Loading...
Searching...
No Matches
AttrSet.h
Go to the documentation of this file.
1/// \file
2/// \brief Types used in nixpkgs provider.
3
4#pragma once
5
6#include <cstdint>
7#include <optional>
8#include <string>
9#include <vector>
10
11#include <llvm/Support/JSON.h>
12#include <lspserver/Protocol.h>
13
14// https://github.com/NixOS/nix/issues/11136
15#ifdef __clang__
16#pragma clang diagnostic push
17#pragma clang diagnostic ignored "-Wdocumentation"
18#endif
19
20#include <nix/expr/value.hh>
21
22#ifdef __clang__
23#pragma clang diagnostic pop
24#endif
25
26namespace nixd {
27
28namespace rpcMethod {
29
30constexpr inline std::string_view EvalExpr = "attrset/evalExpr";
31constexpr inline std::string_view AttrPathInfo = "attrset/attrpathInfo";
32constexpr inline std::string_view AttrPathComplete = "attrset/attrpathComplete";
33constexpr inline std::string_view OptionInfo = "attrset/optionInfo";
34constexpr inline std::string_view OptionComplete = "attrset/optionComplete";
35constexpr inline std::string_view Exit = "exit";
36
37} // namespace rpcMethod
38
39using EvalExprParams = std::string;
40using EvalExprResponse = std::optional<std::string>;
41
42/// \brief A list of strings that "select"s into a attribute set.
43using Selector = std::vector<std::string>;
44
47
49
51 std::optional<std::string> Name;
52 std::optional<std::string> PName;
53 std::optional<std::string> Version;
54 std::optional<std::string> Description;
55 std::optional<std::string> LongDescription;
56 std::optional<std::string> Position;
57 std::optional<std::string> Homepage;
58};
59
60llvm::json::Value toJSON(const PackageDescription &Params);
61bool fromJSON(const llvm::json::Value &Params, PackageDescription &R,
62 llvm::json::Path P);
63
64/// \brief General metadata of all `nix::Value`s
65struct ValueMeta {
66 /// \brief Type of this value.
67 int Type;
68
69 /// \brief Location of the value.
70 ///
71 /// This presence of this value is determined by the nix evaluator.
72 /// In nix 2.19.x and later:
73 /// 1. It is available only for attribute sets and lambdas.
74 /// 2. There is no practical "range" information, only the starting point.
75 std::optional<lspserver::Location> Location;
76};
77
78llvm::json::Value toJSON(const ValueMeta &Params);
79bool fromJSON(const llvm::json::Value &Params, ValueMeta &R,
80 llvm::json::Path P);
81
82/// \brief Using nix's ":doc" method to retrieve value's additional information.
84 std::string Doc;
85 std::int64_t Arity;
86 std::vector<std::string> Args;
87};
88
89llvm::json::Value toJSON(const ValueDescription &Params);
90bool fromJSON(const llvm::json::Value &Params, ValueDescription &R,
91 llvm::json::Path P);
92
94 /// \brief General value description
96
97 /// \brief Package description of the attribute path, if available.
99
100 std::optional<ValueDescription> ValueDesc;
101};
102
103llvm::json::Value toJSON(const AttrPathInfoResponse &Params);
104bool fromJSON(const llvm::json::Value &Params, AttrPathInfoResponse &R,
105 llvm::json::Path P);
106
109 /// \brief Search for packages prefixed with this "prefix"
110 std::string Prefix;
111};
112
113llvm::json::Value toJSON(const AttrPathCompleteParams &Params);
114bool fromJSON(const llvm::json::Value &Params, AttrPathCompleteParams &R,
115 llvm::json::Path P);
116
118 std::vector<std::string> Items;
119 bool IsIncomplete = false;
120};
121
122llvm::json::Value toJSON(const AttrPathCompleteResponse &Params);
123bool fromJSON(const llvm::json::Value &Params, AttrPathCompleteResponse &R,
124 llvm::json::Path P);
125
127 std::optional<std::string> Description;
128 std::optional<std::string> Name;
129};
130
131llvm::json::Value toJSON(const OptionType &Params);
132bool fromJSON(const llvm::json::Value &Params, OptionType &R,
133 llvm::json::Path P);
134
136 std::optional<std::string> Description;
137 std::vector<lspserver::Location> Declarations;
138 std::vector<lspserver::Location> Definitions;
139 std::optional<std::string> Example;
140 std::optional<std::string> Default;
141 std::optional<OptionType> Type;
142};
143
144llvm::json::Value toJSON(const OptionDescription &Params);
145bool fromJSON(const llvm::json::Value &Params, OptionDescription &R,
146 llvm::json::Path P);
147
149 std::string Name;
150 std::optional<OptionDescription> Description;
151};
152
153llvm::json::Value toJSON(const OptionField &Params);
154bool fromJSON(const llvm::json::Value &Params, OptionField &R,
155 llvm::json::Path P);
156
158
160 std::vector<OptionField> Items;
161 bool IsIncomplete = false;
162};
163
164llvm::json::Value toJSON(const OptionCompleteResponse &Params);
165bool fromJSON(const llvm::json::Value &Params, OptionCompleteResponse &R,
166 llvm::json::Path P);
167
168} // namespace nixd
constexpr std::string_view Exit
Definition AttrSet.h:35
constexpr std::string_view EvalExpr
Definition AttrSet.h:30
constexpr std::string_view OptionInfo
Definition AttrSet.h:33
constexpr std::string_view AttrPathInfo
Definition AttrSet.h:31
constexpr std::string_view OptionComplete
Definition AttrSet.h:34
constexpr std::string_view AttrPathComplete
Definition AttrSet.h:32
std::string EvalExprParams
Definition AttrSet.h:39
bool fromJSON(const llvm::json::Value &Params, Configuration::Diagnostic &R, llvm::json::Path P)
llvm::json::Value toJSON(const PackageDescription &Params)
Definition AttrSet.cpp:73
Selector PackageInfoParams
Definition AttrSet.h:45
OptionDescription OptionInfoResponse
Definition AttrSet.h:157
std::vector< std::string > Selector
A list of strings that "select"s into a attribute set.
Definition AttrSet.h:43
Selector AttrPathInfoParams
Definition AttrSet.h:48
Selector OptionInfoParams
Definition AttrSet.h:46
std::optional< std::string > EvalExprResponse
Definition AttrSet.h:40
std::string Prefix
Search for packages prefixed with this "prefix".
Definition AttrSet.h:110
std::vector< std::string > Items
Definition AttrSet.h:118
std::optional< ValueDescription > ValueDesc
Definition AttrSet.h:100
ValueMeta Meta
General value description.
Definition AttrSet.h:95
PackageDescription PackageDesc
Package description of the attribute path, if available.
Definition AttrSet.h:98
std::vector< OptionField > Items
Definition AttrSet.h:160
std::vector< lspserver::Location > Definitions
Definition AttrSet.h:138
std::optional< std::string > Description
Definition AttrSet.h:136
std::optional< std::string > Example
Definition AttrSet.h:139
std::optional< OptionType > Type
Definition AttrSet.h:141
std::vector< lspserver::Location > Declarations
Definition AttrSet.h:137
std::optional< std::string > Default
Definition AttrSet.h:140
std::optional< OptionDescription > Description
Definition AttrSet.h:150
std::string Name
Definition AttrSet.h:149
std::optional< std::string > Description
Definition AttrSet.h:127
std::optional< std::string > Name
Definition AttrSet.h:128
std::optional< std::string > Name
Definition AttrSet.h:51
std::optional< std::string > Version
Definition AttrSet.h:53
std::optional< std::string > PName
Definition AttrSet.h:52
std::optional< std::string > Description
Definition AttrSet.h:54
std::optional< std::string > LongDescription
Definition AttrSet.h:55
std::optional< std::string > Position
Definition AttrSet.h:56
std::optional< std::string > Homepage
Definition AttrSet.h:57
Using nix's ":doc" method to retrieve value's additional information.
Definition AttrSet.h:83
std::int64_t Arity
Definition AttrSet.h:85
std::vector< std::string > Args
Definition AttrSet.h:86
std::string Doc
Definition AttrSet.h:84
General metadata of all nix::Values.
Definition AttrSet.h:65
std::optional< lspserver::Location > Location
Location of the value.
Definition AttrSet.h:75
int Type
Type of this value.
Definition AttrSet.h:67