libexpr: findDerivationFilename return Pos instead of tuple

This commit is contained in:
Jonas Chevalier 2019-10-28 21:22:38 +01:00
parent 59c7249769
commit ec448f8bb6
No known key found for this signature in database
GPG key ID: 71BAF6D40C1D63D7
4 changed files with 13 additions and 11 deletions

View file

@ -93,7 +93,7 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
} }
std::tuple<std::string, int> findDerivationFilename(EvalState & state, Value & v, std::string what) Pos findDerivationFilename(EvalState & state, Value & v, std::string what)
{ {
Value * v2; Value * v2;
try { try {
@ -110,14 +110,16 @@ std::tuple<std::string, int> findDerivationFilename(EvalState & state, Value & v
throw Error("cannot parse meta.position attribute '%s'", pos); throw Error("cannot parse meta.position attribute '%s'", pos);
std::string filename(pos, 0, colon); std::string filename(pos, 0, colon);
int lineno; unsigned int lineno;
try { try {
lineno = std::stoi(std::string(pos, colon + 1)); lineno = std::stoi(std::string(pos, colon + 1));
} catch (std::invalid_argument & e) { } catch (std::invalid_argument & e) {
throw Error("cannot parse line number '%s'", pos); throw Error("cannot parse line number '%s'", pos);
} }
return std::make_tuple(filename, lineno); Symbol file = state.symbols.create(filename);
return { file, lineno, 0 };
} }

View file

@ -4,15 +4,13 @@
#include <string> #include <string>
#include <map> #include <map>
#include <tuple>
namespace nix { namespace nix {
Value * findAlongAttrPath(EvalState & state, const string & attrPath, Value * findAlongAttrPath(EvalState & state, const string & attrPath,
Bindings & autoArgs, Value & vIn); Bindings & autoArgs, Value & vIn);
/* Heuristic to find the filename and lineno or a derivation. */ /* Heuristic to find the filename and lineno or a nix value. */
std::tuple<std::string, int> findDerivationFilename(EvalState & state, Pos findDerivationFilename(EvalState & state, Value & v, std::string what);
Value & v, std::string what);
} }

View file

@ -36,9 +36,9 @@ struct CmdEdit : InstallableCommand
auto v = installable->toValue(*state); auto v = installable->toValue(*state);
std::string filename; Pos pos = findDerivationFilename(*state, *v, installable->what());
int lineno; std::string filename(pos.file);
std::tie(filename, lineno) = findDerivationFilename(*state, *v, installable->what()); int lineno(pos.line);
stopProgressBar(); stopProgressBar();

View file

@ -481,7 +481,9 @@ bool NixRepl::processLine(string line)
lineno = 0; lineno = 0;
} else { } else {
// assume it's a derivation // assume it's a derivation
std::tie(filename, lineno) = findDerivationFilename(state, v, arg); Pos pos = findDerivationFilename(state, v, arg);
filename = pos.file;
lineno = pos.line;
} }
// Open in EDITOR // Open in EDITOR