diff options
Diffstat (limited to 'src/libcmd')
-rw-r--r-- | src/libcmd/installable-flake.cc | 4 | ||||
-rw-r--r-- | src/libcmd/installables.cc | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/libcmd/installable-flake.cc b/src/libcmd/installable-flake.cc index bb75b8ff0..615f70945 100644 --- a/src/libcmd/installable-flake.cc +++ b/src/libcmd/installable-flake.cc @@ -28,6 +28,10 @@ namespace nix { std::vector<std::string> InstallableFlake::getActualAttrPaths() { std::vector<std::string> res; + if (attrPaths.size() == 1 && attrPaths.front().starts_with(".")){ + res.push_back(attrPaths.front().substr(1)); + return res; + } for (auto & prefix : prefixes) res.push_back(prefix + *attrPaths.begin()); diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index b40632887..4ffc9af24 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -302,6 +302,11 @@ void completeFlakeRefWithFragment( completionType = ctAttrs; auto fragment = prefix.substr(hash + 1); + std::string prefixRoot = ""; + if (fragment.starts_with(".")){ + fragment = fragment.substr(1); + prefixRoot = "."; + } auto flakeRefS = std::string(prefix.substr(0, hash)); auto flakeRef = parseFlakeRef(expandTilde(flakeRefS), absPath(".")); @@ -310,6 +315,9 @@ void completeFlakeRefWithFragment( auto root = evalCache->getRoot(); + if (prefixRoot == "."){ + attrPathPrefixes.clear(); + } /* Complete 'fragment' relative to all the attrpath prefixes as well as the root of the flake. */ @@ -334,7 +342,7 @@ void completeFlakeRefWithFragment( auto attrPath2 = (*attr)->getAttrPath(attr2); /* Strip the attrpath prefix. */ attrPath2.erase(attrPath2.begin(), attrPath2.begin() + attrPathPrefix.size()); - completions->add(flakeRefS + "#" + concatStringsSep(".", evalState->symbols.resolve(attrPath2))); + completions->add(flakeRefS + "#" + prefixRoot + concatStringsSep(".", evalState->symbols.resolve(attrPath2))); } } } @@ -345,7 +353,7 @@ void completeFlakeRefWithFragment( for (auto & attrPath : defaultFlakeAttrPaths) { auto attr = root->findAlongAttrPath(parseAttrPath(*evalState, attrPath)); if (!attr) continue; - completions->add(flakeRefS + "#"); + completions->add(flakeRefS + "#" + prefixRoot); } } } |