Exemplo n.º 1
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
}
Exemplo n.º 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
}
Exemplo n.º 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()
}
Exemplo n.º 4
0
func Init(p *project.Project) error {
	tmpPath := p.GetProjectPath() + "/.tmp"
	os.MkdirAll(tmpPath, 0755)
	return p.SaveTempProject(tmpPath)
}