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
}
Beispiel #2
0
func getArgs(p *project.Project) []string {
	cfg := p.GetConfig()
	cmdArgs := []string{"build"}

	if cfg.BuildOpt.BuildMode != "" {
		cmdArgs = append(cmdArgs, "-buildmode")
		cmdArgs = append(cmdArgs, cfg.BuildOpt.BuildMode)
	}

	if cfg.BuildOpt.LDFlags != "" {
		cmdArgs = append(cmdArgs, "-ldflags")
		cmdArgs = append(cmdArgs, cfg.BuildOpt.LDFlags)
	}

	cmdArgs = append(cmdArgs, "-v")

	if cfg.BuildOpt.ShowCommand == "1" {
		cmdArgs = append(cmdArgs, "-x")
	}

	if cfg.BuildOpt.Race == "1" {
		cmdArgs = append(cmdArgs, "-race")
	}

	if cfg.BuildOpt.Jobs != "" {
		cmdArgs = append(cmdArgs, "-p")
		cmdArgs = append(cmdArgs, cfg.BuildOpt.Jobs)
	}

	out := ""
	if cfg.BuildOpt.BuildOutDir != "" {
		out, _ = filepath.Abs(filepath.Join(p.GetProjectPath(), cfg.BuildOpt.BuildOutDir))
		out += "/"
		os.MkdirAll(out, 0755)
	}
	if cfg.BuildOpt.BuildOutFile != "" {
		out += cfg.BuildOpt.BuildOutFile
	} else {
		out = cfg.MainPkgPath
	}

	if out != "" {
		cmdArgs = append(cmdArgs, "-o")
		cmdArgs = append(cmdArgs, out)
	}

	if cfg.BuildOpt.BuildCMD != "" {
		cmdArgs = append(cmdArgs, strings.Fields(cfg.BuildOpt.BuildCMD)...)
	}

	cmdArgs = append(cmdArgs, cfg.MainPkgPath)
	return cmdArgs
}
Beispiel #3
0
func Build(p *project.Project) error {

	cmdArgs := getArgs(p)
	cmd := run.NewExec(filepath.Join(p.GetConfig().GoBin+"go"), cmdArgs, p.GetEnvs())
	if StdOut == nil {
		StdOut = os.Stdout
	}

	cmd.StdOut = StdOut
	cmd.StdErr = StdOut

	fmt.Fprintln(StdOut, "Build project:", p.GetConfig().ProjectName)
	fmt.Fprintln(StdOut, "Build path:", p.GetProjectPath())
	fmt.Fprintln(StdOut, "Build command:", filepath.Join(p.GetConfig().GoBin+"go"), cmdArgs)
	fmt.Fprintln(StdOut, "Build:")

	return cmd.Run()
}
Beispiel #4
0
func GetDepends(p *project.Project, downloadOnly bool) error {
	cmdArgs := []string{"get"}
	if downloadOnly {
		cmdArgs = append(cmdArgs, "-d")
	}
	cmdArgs = append(cmdArgs, "-v")
	cmdArgs = append(cmdArgs, p.GetConfig().MainPkgPath)
	cmd := run.NewExec(filepath.Join(p.GetConfig().GoBin+"go"), cmdArgs, p.GetEnvs())
	if StdOut == nil {
		StdOut = os.Stdout
	}

	cmd.StdOut = StdOut
	cmd.StdErr = StdOut

	fmt.Fprintln(StdOut, "Get project dependens:", p.GetConfig().ProjectName)
	fmt.Fprintln(StdOut, "Get command:", filepath.Join(p.GetConfig().GoBin+"go"), cmdArgs)
	fmt.Fprintln(StdOut, "Get:")

	return cmd.Run()
}
func gocode(p *project.Project, filename string, cur cursor) Candidates {
	out := bytes.NewBuffer([]byte{})
	cmd := run.NewExec("gocode", []string{"-f=json", "--in=" + filename, "autocomplete", strconv.Itoa(cur.offset)}, p.GetEnvs())
	cmd.StdOut = out
	cmd.Run()

	var cands Candidates
	pos := strings.Index(out.String()[1:], "[")
	buf := out.Bytes()
	if json.Unmarshal(buf[pos+1:len(buf)-1], &cands) == nil {
		if len(cur.partial) > 1 {
			cands.SetPercent(cur.partial)
		}
	}
	return cands
}
func Init(p *project.Project) error {
	tmpPath := p.GetProjectPath() + "/.tmp"
	os.MkdirAll(tmpPath, 0755)
	return p.SaveTempProject(tmpPath)
}