コード例 #1
0
func packages(cur cursor, f *file.File) Candidates {
	if cur.token.previous_token() {
		if cur.token.token().tok == token.PACKAGE {
			pkg := filepath.Base(filepath.Dir(f.GetPath()))
			cands := Candidates{NewCandidate("package", pkg, ""), NewCandidate("package", "main", "")}
			if len(cur.partial) > 1 {
				cands.SetPercent(cur.partial)
			}
			return cands
		}
	}
	return nil
}
コード例 #2
0
func Complete(p *project.Project, pfile *file.File, off int) Candidates {
	tmpPath := p.GetProjectPath() + "/.tmp/" + pfile.GetPath()
	pfile.SaveAs(tmpPath)

	src := pfile.GetBody()
	cur := getCursor(src, off)
	//	fmt.Println(src[off-3:off] + "|" + src[off:off+3])

	//TODO
	cands := gocode(p, tmpPath, cur)
	cands = append(cands, keywords(cur)...)
	cands = append(cands, packages(cur, pfile)...)
	cands = append(cands, funcsRecv(cur)...)

	cands.Sort()

	ret := Candidates{}

	ret = append(ret, Candidate{Name: cur.partial, Perc: 200})
	i := 0

	for _, c := range cands {
		if c.Perc < 0 && i > 10 {
			break
		}
		ret = append(ret, c)
		i++
	}

	return ret
}