New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Go Modules #46

Open
joefitzgerald opened this Issue Aug 24, 2018 · 12 comments

Comments

Projects
None yet
8 participants
@joefitzgerald

joefitzgerald commented Aug 24, 2018

Context: I maintain Atom's go-plus package for go support. I know @ramya-rao-a is also interested in ensuring vscode-go works well with go modules.

There are a variety of failure scenarios for the current master version of gocode when using go modules support (in particular without using vendor mode).

Over time, we may want to edit this issue to describe each of the failure modes and validate that they are fixed. My assumption is that the cache branch and a switch to use golang.org/x/tools/go/packages will both be required to get to completion. @mdempsky do you have specific plans here?

@myitcv

This comment has been minimized.

myitcv commented Aug 24, 2018

@joefitzgerald thanks for creating this issue; you just beat me to it 👍

Linking back to the umbrella Go issue: golang/go#24661

@mdempsky FYI I intend to take a stab at adding support via go/packages over the weekend, unless you already have this covered?

@fatih

This comment has been minimized.

fatih commented Aug 28, 2018

I agree with @myitcv, we should use go/packages (see: https://godoc.org/golang.org/x/tools/go/packages). One thing to note is that this is not backward compatible:

- The implementation depends on the Go 1.11 go command; support for earlier versions will be added soon.

I didn't use go/packages yet, but we should be aware of this limitation.

@ikgo

This comment has been minimized.

ikgo commented Sep 2, 2018

code below fix the problem.
internal/gbimporter/gbimporter.go
add import "golang.org/x/tools/go/packages"

func (i *importer) ImportFrom(path, srcDir string, mode types.ImportMode) (*types.Package, error) {
	buildDefaultLock.Lock()
	defer buildDefaultLock.Unlock()

	var src []string
	src = append(src, path)
	cfg := &packages.Config{
		Mode: packages.LoadTypes,
		Dir:  srcDir,
	}
	pkgs, err := packages.Load(cfg, src...)

	// origDef := build.Default
	// defer func() { build.Default = origDef }()

	// def := &build.Default
	// def.GOARCH = i.ctx.GOARCH
	// def.GOOS = i.ctx.GOOS
	// def.GOROOT = i.ctx.GOROOT
	// def.GOPATH = i.ctx.GOPATH
	// def.CgoEnabled = i.ctx.CgoEnabled
	// def.UseAllFiles = i.ctx.UseAllFiles
	// def.Compiler = i.ctx.Compiler
	// def.BuildTags = i.ctx.BuildTags
	// def.ReleaseTags = i.ctx.ReleaseTags
	// def.InstallSuffix = i.ctx.InstallSuffix

	// def.SplitPathList = i.splitPathList
	// def.JoinPath = i.joinPath

	// var result, err = i.underlying.ImportFrom(path, srcDir, mode)
	if len(pkgs) > 0 {
		return pkgs[0].Types, nil
	}
	return nil, err
}
@ikgo

This comment has been minimized.

ikgo commented Sep 2, 2018

working fork https://github.com/ikgo/gocode.git
check of go.mod existence added. in case doesn't exists the original code running

compatible with go 1.11 only

@myitcv

This comment has been minimized.

myitcv commented Sep 3, 2018

Linking back to golang/go#24661

@myitcv

This comment has been minimized.

myitcv commented Sep 3, 2018

@ikgo thanks for taking a look at this. I stopped my investigation after speaking to @ianthehat at GopherCon. Someone in his team is already working on helping to fix gocode, along with a number of other tools. See the issue linked in my previous comment, and also the group https://groups.google.com/forum/#!forum/golang-tools which arose from our discussions at GopherCon, in particular https://groups.google.com/d/msg/golang-tools/wNwFBDeZxhE/XFqiXQisBAAJ which are my notes from the sessions.

@lucastheisen

This comment has been minimized.

lucastheisen commented Sep 20, 2018

@myitcv , is this project what you are referring to when you say:

... @ianthehat at GopherCon. Someone in his team is already working on helping to fix gocode, along with a number of other tools

It is listed on the tooling updates to support modules issue as Beta support, but didn't work for me.

@fsouza

This comment has been minimized.

fsouza commented Sep 20, 2018

@lucastheisen it works fine here. How did you test it?

go get -u github.com/stamblerre/gocode
gocode close

Also, make sure you editor is not setting the option to complete from source (-source).

@myitcv

This comment has been minimized.

myitcv commented Sep 20, 2018

@lucastheisen

is this project what you are referring to when you say:

Yes; the changes in https://github.com/stamblerre/gocode will be made into a PR against this repo once they stabilise.

@lucastheisen

This comment has been minimized.

lucastheisen commented Sep 20, 2018

@fsouza , I probably should have elaborated...

It does download, install, and even run. But when used by vscode, it just hangs. If i go mod vendor, then move the project to the standard location under $GOPATH, then completion works as expected (type . after var and get list of context aware prop/func). Also, i checked my settings.json for anything that looks like it might set

the option to complete from source (-source).

but found nothing. Any idea where that might be hiding for vscode?

@mikkeloscar

This comment has been minimized.

mikkeloscar commented Sep 23, 2018

@stamblerre would you mind opening a PR here even if your work is not completely done yet? Would make it easier to follow along and tracking the progress.

@myitcv

This comment has been minimized.

myitcv commented Oct 5, 2018

Just adding a note here so that it can be referenced from any issues that ask about the future of gocode:

  • github.com/nsf/gocode is no longer maintained, per https://github.com/nsf/gocode/blob/master/README.md
  • This project, github.com/mdempsky/gocode, is the official replacement
  • Go modules support is being added in github.com/stamblerre/gocode
  • The changes in github.com/stamblerre/gocode will be merged into github.com/mdempsky/gocode once those changes stabilise
  • In the medium to longer term, the Go tools team are working on a language server to replace gocode and other individual tools

More details on this and progress on Go tooling in general can be found in the golang-tools group. We are currently holding fortnightly update calls; notes from the first sessions can be found here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment