<commit_before>package complete

import (
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
)

func File(buf []rune, pos int) ([]string, error) {
	i := strings.LastIndexAny(string(buf[:pos]), " '") + 1
	prefix := string(buf[i:pos])
	p, pend := filepath.Split(prefix)
	if p == "" {
		p = "."
	}
	if strings.HasPrefix(p, "~") {
		p = os.Getenv("HOME") + p[1:]
	}
	dir, err := os.Open(p)
	if err != nil {
		return nil, err
	}
	defer dir.Close()
	names := make([]string, 0, len(pend))
	dirnames, err := dir.Readdirnames(0)
	if err != nil {
		return nil, err
	}
	for _, name := range dirnames {
		if !strings.HasPrefix(name, pend) {
			continue
		}
		n := name[len(pend):]
		stat, err := os.Stat(filepath.Join(p, name))
		if err != nil {
			return nil, err
		}
		if stat.IsDir() {
			n += "/"
		}
		names = append(names, n)<commit_msg>Sort files which is the entries of file completion<commit_after>package complete

import (
	"io/ioutil"
	"os"
	"path/filepath"
	"sort"
	"strings"
)

func File(buf []rune, pos int) ([]string, error) {
	i := strings.LastIndexAny(string(buf[:pos]), " '") + 1
	prefix := string(buf[i:pos])
	p, pend := filepath.Split(prefix)
	if p == "" {
		p = "."
	}
	if strings.HasPrefix(p, "~") {
		p = os.Getenv("HOME") + p[1:]
	}
	dir, err := os.Open(p)
	if err != nil {
		return nil, err
	}
	defer dir.Close()
	names := make([]string, 0, len(pend))
	dirnames, err := dir.Readdirnames(0)
	if err != nil {
		return nil, err
	}
	sort.Strings(dirnames)
	for _, name := range dirnames {
		if !strings.HasPrefix(name, pend) {
			continue
		}
		n := name[len(pend):]
		stat, err := os.Stat(filepath.Join(p, name))
		if err != nil {
			return nil, err
		}
		if stat.IsDir() {
			n += "/"
		}
		names = append(names, n)
{'fraction_non_alphanumeric': 0.19442832269297736, 'fraction_numerical': 0.0046430644225188625, 'mean_word_length': 3.267326732673267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3264941', 'n_tokens_mistral': 757, 'n_tokens_neox': 701, 'n_words': 169}