6#include <nix/attr-path.hh>
7#include <nix/nixexpr.hh>
8#include <nix/store-api.hh>
18void fillString(nix::EvalState &State, nix::Value &
V,
19 const std::vector<std::string_view> &AttrPath,
20 std::optional<std::string> &
Field) {
23 State.forceValue(
Select, nix::noPos);
24 if (
Select.type() == nix::ValueType::nString)
26 }
catch (std::exception &E) {
44std::optional<Location>
locationOf(nix::PosTable &PTable, nix::Value &
V) {
45 nix::PosIdx P =
V.determinePos(nix::noPos);
49 nix::Pos
NixPos = PTable[P];
50 const auto *
SP = std::get_if<nix::SourcePath>(&
NixPos.origin);
57 .character =
static_cast<int>(
NixPos.column - 1),
75 State.forceValue(
V, nix::noPos);
81 if (
File.type() == nix::ValueType::nString)
84 if (Line.type() == nix::ValueType::nInt &&
85 Column.type() == nix::ValueType::nInt) {
89 static_cast<int>(Column.integer) - 1};
90 Loc.range = {Pos, Pos};
96 State.forceValue(
V, nix::noPos);
97 if (
V.type() != nix::ValueType::nList)
112 State,
V, State.symbols.create(
"declarationPositions"));
117 }
catch (nix::AttrPathNotFound &E) {
133 if (
V.type() == nix::ValueType::nAttrs) [[
likely]] {
135 if (
auto *
It =
V.attrs->find(State.symbols.create(
"type"));
142 if (
auto *
It =
V.attrs->find(State.symbols.create(
"example"));
143 It !=
V.attrs->end()) {
144 State.forceValue(*
It->value,
It->pos);
150 std::ostringstream
OS;
151 It->value->print(State.symbols,
OS);
161 std::unique_ptr<OutboundPort> Out)
176 const std::string &Name,
179 nix::Expr *AST = state().parseExprFromString(
180 Name, state().rootPath(nix::CanonPath::fromCwd()));
181 state().eval(AST, Nixpkgs);
184 }
catch (
const nix::BaseError &
Err) {
187 }
catch (
const std::exception &
Err) {
197 Reply([&]() -> llvm::Expected<RespT> {
199 if (AttrPath.empty())
200 return error(
"attrpath is empty!");
203 state().forceValue(
V, nix::noPos);
208 }
catch (
const nix::BaseError &
Err) {
210 }
catch (
const std::exception &
Err) {
222 state().forceValue(Scope, nix::noPos);
224 if (Scope.type() != nix::ValueType::nAttrs) {
229 std::vector<std::string> Names;
237 Scope.attrs->lexicographicOrder(state().
symbols)) {
239 const std::string Name = state().symbols[
Attr.name];
240 if (Name.starts_with(
Params.Prefix)) {
242 Names.emplace_back(Name);
248 Reply(std::move(Names));
250 }
catch (
const nix::BaseError &
Err) {
253 }
catch (
const std::exception &
Err) {
263 if (AttrPath.empty()) {
277 }
catch (
const nix::BaseError &
Err) {
280 }
catch (
const std::exception &
Err) {
293 state().forceValue(Scope, nix::noPos);
295 if (Scope.type() != nix::ValueType::nAttrs) {
312 Scope.attrs->lexicographicOrder(state().
symbols)) {
314 std::string Name = state().symbols[
Attr.name];
315 if (Name.starts_with(
Params.Prefix)) {
333 }
catch (
const nix::BaseError &
Err) {
336 }
catch (
const std::exception &
Err) {
Dedicated worker for evaluating attrset.
Types used in nixpkgs 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.
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)
constexpr std::string_view EvalExpr
constexpr std::string_view OptionInfo
constexpr std::string_view AttrPathInfo
constexpr std::string_view OptionComplete
constexpr std::string_view AttrPathComplete
bool fromJSON(const llvm::json::Value &Params, Configuration::Diagnostic &R, llvm::json::Path P)
Selector AttrPathInfoParams
std::optional< std::string_view > getFieldString(nix::EvalState &State, nix::Value &V, std::string_view Field)
bool isOption(nix::EvalState &State, nix::Value &V)
bool checkField(nix::EvalState &State, nix::Value &V, std::string_view Field, std::string_view Pred)
Check if value V is an attrset, has the field, and equals to Pred.
nix::Value & selectStrings(nix::EvalState &State, nix::Value &V, const std::vector< std::string > &AttrPath)
Given an attrpath in nix::Value V, select it.
nix::Value selectOptions(nix::EvalState &State, nix::Value &V, std::vector< nix::Symbol >::const_iterator Begin, std::vector< nix::Symbol >::const_iterator End)
Select the option declaration list, V, dive into "submodules".
std::vector< nix::Symbol > toSymbols(nix::SymbolTable &STable, const std::vector< std::string > &Names)
Transform a vector of string into a vector of nix symbols.
nix::Value & selectAttr(nix::EvalState &State, nix::Value &V, nix::Symbol Attr)
Select attribute Attr.
nix::Value & selectStringViews(nix::EvalState &State, nix::Value &V, const std::vector< std::string_view > &AttrPath)
Given an attrpath in nix::Value V, select it.
void addMethod(llvm::StringRef Method, ThisT *This, void(ThisT::*Handler)(const Param &, Callback< Result >))
URIForFile uri
The text document's URI.
int line
Line position in a document (zero-based).
static URIForFile canonicalize(llvm::StringRef AbsPath, llvm::StringRef TUPath)
std::optional< std::string > Description
std::optional< std::string > Example
std::optional< OptionType > Type
std::vector< lspserver::Location > Declarations
std::optional< std::string > Description
std::optional< std::string > Name
std::optional< std::string > Name
std::optional< std::string > Version
std::optional< std::string > PName
std::optional< std::string > Description
std::optional< std::string > LongDescription
std::optional< std::string > Position
std::optional< std::string > Homepage