diff --git a/completers/nix_completer/cmd/action/flake.go b/completers/nix_completer/cmd/action/flake.go index 88e827f59a..28d32f405e 100644 --- a/completers/nix_completer/cmd/action/flake.go +++ b/completers/nix_completer/cmd/action/flake.go @@ -16,15 +16,16 @@ import ( // in the flake registry. // It takes in the subcommand being completed // -// nixpkgs#hello -// .#foo -func ActionFlakeRefs(fullCmd []string) carapace.Action { +// nixpkgs#hello +// .#foo +func ActionFlakeRefs() carapace.Action { return carapace.ActionMultiPartsN("#", 2, func(c carapace.Context) carapace.Action { switch len(c.Parts) { case 0: + // TODO add directory completion externally return nix.ActionFlakes().Suffix("#") default: - return ActionFlakeAttributes(fullCmd, c.Parts[0], c.Value) + return ActionFlakeAttributes(c.Parts[0]) } }) } @@ -33,16 +34,15 @@ func ActionFlakeRefs(fullCmd []string) carapace.Action { // Completions are only supplied for local flakes or flakes // in the registry. // -// hello -// packages.x86_64-linux.hello -func ActionFlakeAttributes(fullCmd []string, flake, flakePath string) carapace.Action { +// hello +// packages.x86_64-linux.hello +func ActionFlakeAttributes(flake string) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { // Get completions from the flake registry - c.Setenv("NIX_GET_COMPLETIONS", fmt.Sprint(len(fullCmd))) - completionArgs := append(fullCmd[1:], flake) + c.Setenv("NIX_GET_COMPLETIONS", "2") var stdout, stderr bytes.Buffer - cmd := c.Command("nix", completionArgs...) + cmd := c.Command("nix", "build", flake) cmd.Stdout = &stdout cmd.Stderr = &stderr @@ -68,8 +68,7 @@ func ActionFlakeAttributes(fullCmd []string, flake, flakePath string) carapace.A stdout.Reset() stderr.Reset() - completionArgs = append(fullCmd[1:], flake+"#"+flakePath) - cmd = c.Command("nix", completionArgs...) + cmd = c.Command("nix", "build", fmt.Sprintf("%v#%v", flake, c.Value)) cmd.Stdout = &stdout cmd.Stderr = &stderr diff --git a/completers/nix_completer/cmd/build.go b/completers/nix_completer/cmd/build.go index b10fdb4f36..374120a395 100644 --- a/completers/nix_completer/cmd/build.go +++ b/completers/nix_completer/cmd/build.go @@ -40,5 +40,8 @@ func init() { "profile": carapace.ActionFiles(), "reference-lock-file": carapace.ActionFiles("lock"), }) - carapace.Gen(buildCmd).PositionalCompletion(action.ActionFlakeRefs([]string{"nix", "build"})) + + carapace.Gen(buildCmd).PositionalCompletion( + action.ActionFlakeRefs(), + ) } diff --git a/completers/nix_completer/cmd/develop.go b/completers/nix_completer/cmd/develop.go index 0173096b4f..7c8b4a6a5f 100644 --- a/completers/nix_completer/cmd/develop.go +++ b/completers/nix_completer/cmd/develop.go @@ -51,5 +51,8 @@ func init() { "reference-lock-file": carapace.ActionFiles("lock"), "unset": os.ActionEnvironmentVariables(), }) - carapace.Gen(developCmd).PositionalCompletion(action.ActionFlakeRefs([]string{"nix", "develop"})) + + carapace.Gen(developCmd).PositionalCompletion( + action.ActionFlakeRefs(), + ) } diff --git a/pkg/actions/tools/nix/develop.go b/pkg/actions/tools/nix/develop.go index 79e12bbc94..40b0f7de20 100644 --- a/pkg/actions/tools/nix/develop.go +++ b/pkg/actions/tools/nix/develop.go @@ -51,7 +51,7 @@ func getCurrentSystem(c carapace.Context) (string, error) { } // Completes . -func actionDevShellsAndSystem(c carapace.Context, devShells *devShellsSchema) carapace.Action { +func actionDevShellsAndSystem(_ carapace.Context, devShells *devShellsSchema) carapace.Action { return carapace.ActionMultiPartsN(".", 2, func(c carapace.Context) carapace.Action { if len(c.Parts) == 0 { currentSystem, err := getCurrentSystem(c) diff --git a/pkg/actions/tools/nix/flake.go b/pkg/actions/tools/nix/flake.go index 7e48d6e696..37918becfb 100644 --- a/pkg/actions/tools/nix/flake.go +++ b/pkg/actions/tools/nix/flake.go @@ -25,12 +25,9 @@ func ActionFlakes() carapace.Action { vals = append(vals, name[1], fields[2], styleForRegistry(fields[0])) } } - return carapace.Batch( - carapace.ActionValues(".", "..").StyleF(style.ForPath), - carapace.ActionDirectories(), - carapace.ActionStyledValuesDescribed(vals...), - ).ToA() - }).Cache(time.Minute) + // TODO add directory completion externally + return carapace.ActionStyledValuesDescribed(vals...) + }).Cache(time.Minute).Tag("flakes") } func styleForRegistry(s string) string {