Exemplo n.º 1
0
func (m *mGocodeComplete) checkOpts() {
	opts := map[string]string{
		"propose-builtins": "false",
	}

	if m.Builtins {
		opts["propose-builtins"] = "true"
	}

	osArch := runtime.GOOS + "_" + runtime.GOARCH
	goroot, gopaths := envRootList(m.Env)
	pl := []string{}

	add := func(p string) {
		if p != "" {
			pl = append(pl, filepath.Join(p, "pkg", osArch))
		}
	}

	add(goroot)
	for _, p := range gopaths {
		add(p)
	}

	opts["lib-path"] = strings.Join(pl, string(filepath.ListSeparator))

	for k, v := range opts {
		if mGocodeVars.opts[k] != v {
			mGocodeVars.opts[k] = v
			gocode.GoSublimeGocodeSet(k, v)
		}
	}
}
Exemplo n.º 2
0
func (m *mGocodeComplete) Call() (interface{}, string) {
	e := ""
	res := M{}

	if m.Src == "" {
		// this is here for testing, the client should always send the src
		s, _ := ioutil.ReadFile(m.Fn)
		m.Src = string(s)
	}

	if m.Src == "" {
		return res, "No source"
	}

	pos := 0
	for i, _ := range m.Src {
		pos += 1
		if pos > m.Pos {
			pos = i
			break
		}
	}

	src := []byte(m.Src)
	fn := m.Fn
	if !filepath.IsAbs(fn) {
		fn = filepath.Join(orString(m.Dir, m.Home), orString(fn, "_.go"))
	}

	mGocodeVars.lck.Lock()
	defer mGocodeVars.lck.Unlock()

	builtins := "false"
	if m.Builtins {
		builtins = "true"
	}
	if mGocodeVars.lastBuiltins != builtins {
		gocode.GoSublimeGocodeSet("propose-builtins", builtins)
	}

	gopath := orString(m.Env["GOPATH"], os.Getenv("GOPATH"))
	if gopath != mGocodeVars.lastGopath {
		p := []string{}
		osArch := runtime.GOOS + "_" + runtime.GOARCH
		for _, s := range filepath.SplitList(gopath) {
			p = append(p, filepath.Join(s, "pkg", osArch))
		}
		libpath := strings.Join(p, string(filepath.ListSeparator))
		gocode.GoSublimeGocodeSet("lib-path", libpath)
		mGocodeVars.lastGopath = gopath
	}

	if m.calltip {
		res["calltips"] = completeCalltip(src, fn, pos)
	} else {
		l := gocode.GoSublimeGocodeComplete(src, fn, pos)
		res["completions"] = l

		if m.Autoinst && len(l) == 0 {
			autoInstall(AutoInstOptions{
				Src: m.Src,
				Env: m.Env,
			})
		}
	}

	return res, e
}