aboutsummaryrefslogtreecommitdiff
path: root/src/nix/edit.cc
diff options
context:
space:
mode:
authorzimbatm <zimbatm@zimbatm.com>2019-10-23 17:21:10 +0200
committerzimbatm <zimbatm@zimbatm.com>2019-10-23 17:21:16 +0200
commit59c72497696eaafa294c34699795788d24d68c68 (patch)
treec3f1bbb3c270dc265d52f6bd657bfe5e9364e717 /src/nix/edit.cc
parent207a537343ace1d39ac125059456d832a5237f2e (diff)
libexpr: add findDerivationFilename
extract the derivation to filename:lineno heuristic
Diffstat (limited to 'src/nix/edit.cc')
-rw-r--r--src/nix/edit.cc23
1 files changed, 2 insertions, 21 deletions
diff --git a/src/nix/edit.cc b/src/nix/edit.cc
index 3a27b9cca..a4aa40bed 100644
--- a/src/nix/edit.cc
+++ b/src/nix/edit.cc
@@ -36,28 +36,9 @@ struct CmdEdit : InstallableCommand
auto v = installable->toValue(*state);
- Value * v2;
- try {
- auto dummyArgs = state->allocBindings(0);
- v2 = findAlongAttrPath(*state, "meta.position", *dummyArgs, *v);
- } catch (Error &) {
- throw Error("package '%s' has no source location information", installable->what());
- }
-
- auto pos = state->forceString(*v2);
- debug("position is %s", pos);
-
- auto colon = pos.rfind(':');
- if (colon == std::string::npos)
- throw Error("cannot parse meta.position attribute '%s'", pos);
-
- std::string filename(pos, 0, colon);
+ std::string filename;
int lineno;
- try {
- lineno = std::stoi(std::string(pos, colon + 1));
- } catch (std::invalid_argument & e) {
- throw Error("cannot parse line number '%s'", pos);
- }
+ std::tie(filename, lineno) = findDerivationFilename(*state, *v, installable->what());
stopProgressBar();