Ejemplo n.º 1
0
func (dir *DirSpec) ReadDir() ([]os.FileInfo, error) {
	ctx, err := dir.buildContext()
	if err != nil {
		return nil, err
	}

	return buildutil.ReadDir(ctx, dir.Path)
}
Ejemplo n.º 2
0
func addCompletions(completions []string, ctx *build.Context, root, dir, name string) []string {
	fis, err := buildutil.ReadDir(ctx, buildutil.JoinPath(ctx, root, dir))
	if err != nil {
		return completions
	}
	for _, fi := range fis {
		if !fi.IsDir() || strings.HasPrefix(fi.Name(), ".") {
			continue
		}
		if strings.HasPrefix(fi.Name(), name) {
			completions = append(completions, path.Join("/", dir, fi.Name())+"/")
		}
	}
	return completions
}
Ejemplo n.º 3
0
func completePackageArg(ctx *build.Context, cwd string, src io.Reader, arg string) (completions []string) {
	switch {
	case arg == ".":
		completions = []string{"./", "../"}
	case arg == "..":
		completions = []string{"../"}
	case strings.HasPrefix(arg, "."):
		// Complete using relative directory.
		bpkg, err := ctx.Import(".", cwd, build.FindOnly)
		if err != nil {
			return nil
		}
		dir, name := path.Split(arg)
		fis, err := buildutil.ReadDir(ctx, buildutil.JoinPath(ctx, bpkg.Dir, dir))
		if err != nil {
			return nil
		}
		for _, fi := range fis {
			if !fi.IsDir() || strings.HasPrefix(fi.Name(), ".") {
				continue
			}
			if strings.HasPrefix(fi.Name(), name) {
				completions = append(completions, path.Join(dir, fi.Name())+"/")
			}
		}
	case strings.HasPrefix(arg, "/"):
		// Complete using full import path.
		completions = completePackageArgByPath(ctx, cwd, arg)
	default:
		// Complete with package names imported in current file.
		for n := range readImports(cwd, src) {
			if strings.HasPrefix(n, arg) {
				completions = append(completions, n)
			}
		}
	}
	if len(completions) == 0 {
		completions = []string{arg}
	}
	sort.Strings(completions)
	return completions
}