<commit_before>// Copyright 2016 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package nvim

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

	"nvim-go/pathutil"

	"github.com/neovim-go/vim"
)

// CompleteFiles provides a "-complete=file" completion exclude the non go files.
func CompleteFiles(v *vim.Vim, a *vim.CommandCompletionArgs, dir string) (filelist []string, err error) {
	switch {
	case len(a.ArgLead) > 0:
		a.ArgLead = filepath.Clean(a.ArgLead)
		if pathutil.IsDir(a.ArgLead) { // abs or rel directory path
			files, err := ioutil.ReadDir(a.ArgLead)
			if err != nil {
				return nil, err
			}
			for _, f := range files {
				if filepath.Ext(f.Name()) == ".go" || f.IsDir() {
					filelist = append(filelist, a.ArgLead+string(filepath.Separator)+f.Name())
				}
			}
		} else { // lacking directory path or filename
			files, err := ioutil.ReadDir(dir)
			if err != nil {
				return nil, err
			}
			return matchFile(files, a.ArgLead), nil
		}

	default:
		files, err := ioutil.ReadDir(dir)
		if err != nil {
			return nil, err
		}
		for _, f := range files {
			if filepath.Ext(f.Name()) == ".go" || f.IsDir() {
				filelist = append(filelist, f.Name())
			}
		}
	}

	return filelist, nil
}
<commit_msg>nvim/complete: Fix check file extension use HasSuffix<commit_after>// Copyright 2016 <NAME>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package nvim

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

	"nvim-go/pathutil"

	"github.com/neovim-go/vim"
)

// CompleteFiles provides a "-complete=file" completion exclude the non go files.
func CompleteFiles(v *vim.Vim, a *vim.CommandCompletionArgs, dir string) (filelist []string, err error) {
	switch {
	case len(a.ArgLead) > 0:
		a.ArgLead = filepath.Clean(a.ArgLead)
		if pathutil.IsDir(a.ArgLead) { // abs or rel directory path
			files, err := ioutil.ReadDir(a.ArgLead)
			if err != nil {
				return nil, err
			}
			for _, f := range files {
				if strings.HasSuffix(f.Name(), ".go") || f.IsDir() {
					filelist = append(filelist, a.ArgLead+string(filepath.Separator)+f.Name())
				}
			}
		} else { // lacking directory path or filename
			files, err := ioutil.ReadDir(dir)
			if err != nil {
				return nil, err
			}
			return matchFile(files, a.ArgLead), nil
		}

	default:
		files, err := ioutil.ReadDir(dir)
		if err != nil {
			return nil, err
		}
		for _, f := range files {
			if filepath.Ext(f.Name()) == ".go" || f.IsDir() {
				filelist = append(filelist, f.Name())
			}
		}
	}

	return filelist, nil
}

{'fraction_non_alphanumeric': 0.14339198801946837, 'fraction_numerical': 0.0037439161362785474, 'mean_word_length': 3.042360060514372, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5368598', 'n_tokens_mistral': 1085, 'n_tokens_neox': 958, 'n_words': 270}