mirror of
https://github.com/NixOS/nix
synced 2025-06-29 10:31:15 +02:00
Make 'nix edit' etc. work again
This commit is contained in:
parent
1790698a74
commit
bb4d35dcca
15 changed files with 108 additions and 82 deletions
|
@ -106,7 +106,7 @@ std::pair<Value *, PosIdx> findAlongAttrPath(EvalState & state, const std::strin
|
|||
}
|
||||
|
||||
|
||||
std::pair<std::string, uint32_t> findPackageFilename(EvalState & state, Value & v, std::string what)
|
||||
std::pair<SourcePath, uint32_t> findPackageFilename(EvalState & state, Value & v, std::string what)
|
||||
{
|
||||
Value * v2;
|
||||
try {
|
||||
|
@ -120,19 +120,41 @@ std::pair<std::string, uint32_t> findPackageFilename(EvalState & state, Value &
|
|||
// toString + parsing?
|
||||
auto pos = state.forceString(*v2);
|
||||
|
||||
auto colon = pos.rfind(':');
|
||||
if (colon == std::string::npos)
|
||||
throw ParseError("cannot parse meta.position attribute '%s'", pos);
|
||||
auto fail = [pos]() {
|
||||
throw ParseError("cannot parse 'meta.position' attribute '%s'", pos);
|
||||
};
|
||||
|
||||
std::string filename(pos, 0, colon);
|
||||
unsigned int lineno;
|
||||
try {
|
||||
lineno = std::stoi(std::string(pos, colon + 1, std::string::npos));
|
||||
std::string_view prefix = "/virtual/";
|
||||
|
||||
if (!hasPrefix(pos, prefix)) fail();
|
||||
pos = pos.substr(prefix.size());
|
||||
|
||||
auto slash = pos.find('/');
|
||||
if (slash == std::string::npos) fail();
|
||||
size_t number = std::stoi(std::string(pos, 0, slash));
|
||||
pos = pos.substr(slash);
|
||||
|
||||
std::shared_ptr<InputAccessor> accessor;
|
||||
for (auto & i : state.inputAccessors)
|
||||
if (i.second->number == number) {
|
||||
accessor = i.second;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!accessor) fail();
|
||||
|
||||
auto colon = pos.rfind(':');
|
||||
if (colon == std::string::npos) fail();
|
||||
std::string filename(pos, 0, colon);
|
||||
auto lineno = std::stoi(std::string(pos, colon + 1, std::string::npos));
|
||||
|
||||
return {SourcePath{ref(accessor), CanonPath(filename)}, lineno};
|
||||
|
||||
} catch (std::invalid_argument & e) {
|
||||
throw ParseError("cannot parse line number '%s'", pos);
|
||||
fail();
|
||||
abort();
|
||||
}
|
||||
|
||||
return { std::move(filename), lineno };
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue