aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/edit.cc23
-rw-r--r--src/nix/repl.cc23
2 files changed, 3 insertions, 43 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();
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index d4334cf7f..5cfb408f7 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -481,28 +481,7 @@ bool NixRepl::processLine(string line)
lineno = 0;
} else {
// assume it's a derivation
- 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", arg);
- }
-
- 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);
-
- filename = std::string(pos, 0, colon);
- 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, arg);
}
// Open in EDITOR