Fix completion of paths directly under the root directory

This commit is contained in:
devangpratap 2026-09-15 11:15:04 -04:00
parent bab67650e2
commit fd904d45d8
2 changed files with 13 additions and 1 deletions

View file

@ -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)
}

View file

@ -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) {