From fd904d45d83cb20657321fdc49da56ea652273a6 Mon Sep 17 00:00:00 2001 From: devangpratap <115096812+devangpratap@users.noreply.github.com> Date: Tue, 15 Sep 2026 11:15:04 -0400 Subject: [PATCH] Fix completion of paths directly under the root directory --- tools/cli/files.go | 2 +- tools/cli/files_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/cli/files.go b/tools/cli/files.go index 72e256f2b..453f400af 100644 --- a/tools/cli/files.go +++ b/tools/cli/files.go @@ -65,7 +65,7 @@ func CompleteFiles(prefix string, callback func(*FileEntry), cwd string) error { joinable_prefix = prefix } else { idx := strings.LastIndex(prefix, utils.Sep) - if idx > 0 { + if idx > -1 { joinable_prefix = prefix[:idx+1] base_dir = filepath.Dir(location) } diff --git a/tools/cli/files_test.go b/tools/cli/files_test.go index a61268f98..3b2b1de87 100644 --- a/tools/cli/files_test.go +++ b/tools/cli/files_test.go @@ -89,6 +89,18 @@ func TestCompleteFiles(t *testing.T) { test_candidates("odir/f", "odir/four.txt") test_candidates("x") + // a prefix whose only separator is the leading one, such as /us + if entries, err := os.ReadDir(utils.Sep); err == nil && len(entries) > 0 { + name := entries[0].Name() + prefix := utils.Sep + name[:1] + found := false + CompleteFiles(prefix, func(entry *FileEntry) { + found = found || strings.TrimSuffix(entry.CompletionCandidate, utils.Sep) == utils.Sep+name + }, "") + if !found { + t.Fatalf("Did not get %#v as a completion candidate for prefix: %#v", utils.Sep+name, prefix) + } + } } func TestCompleteExecutables(t *testing.T) {