Fix completion of symlinks to directories for directory arguments

This commit is contained in:
devangpratap 2026-09-15 14:09:41 -04:00
parent 0c19dbfa8f
commit 04082039be
2 changed files with 9 additions and 1 deletions

View file

@ -320,7 +320,7 @@ func DirectoryCompleter(title string, relative_to relative_to) CompletionFunc {
mg.NoTrailingSpace = true
mg.IsFiles = true
_ = CompleteFiles(word, func(entry *FileEntry) {
if entry.Mode.IsDir() {
if entry.IsDir {
mg.AddMatch(entry.CompletionCandidate)
}
}, cwd)

View file

@ -101,6 +101,14 @@ func TestCompleteFiles(t *testing.T) {
t.Fatalf("Did not get %#v as a completion candidate for prefix: %#v", utils.Sep+name, prefix)
}
}
// symlinks to directories are directories
os.Symlink(filepath.Join(tdir, "odir"), filepath.Join(tdir, "slink"))
c := NewCompletions()
DirectoryCompleter("", CWD)(c, "s", 0)
if len(c.Groups) != 1 || len(c.Groups[0].Matches) != 1 || c.Groups[0].Matches[0].Word != "slink/" {
t.Fatalf("Symlink to directory not completed by DirectoryCompleter: %#v", c.Groups)
}
}
func TestCompleteExecutables(t *testing.T) {