Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

Support Go Modules #46

Closed
joefitzgerald opened this issue Aug 24, 2018 · 13 comments
Closed

Support Go Modules #46

joefitzgerald opened this issue Aug 24, 2018 · 13 comments

Comments

@joefitzgerald
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

myitcv commented Sep 3, 2018

Linking back to golang/go#24661

@myitcv
Copy link

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
Copy link

@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
Copy link

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
Copy link

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
Copy link

@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
Copy link

@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
Copy link

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:

@stamblerre
Copy link
Collaborator

I think this issue can be closed. gopls handles completion for projects using Go modules.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants