Skip to content
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

add go mod support #9

Closed
wants to merge 1 commit into from
Closed

add go mod support #9

wants to merge 1 commit into from

Conversation

windler
Copy link

@windler windler commented Aug 28, 2018

This is a PR to solve #8

Actually, I am not quite sure this is the way gopkgs should handle go modules. I just wanted to create a little POC how an implementation could look like.

Basic idea is to check wether there is a go.mod when -workDir is provided and then add the workdir to the list of source folders. When retrieving the package name, the implementation will check if the baseDir has a go.mod and read the module name.

Maybe the module name should be cached?

Feel free to comment, enhance or even reject this PR.

@uudashr
Copy link
Owner

uudashr commented Sep 2, 2018

go list all show the list all available packages
gopkgs also do the same.

Currently gopkgs can be used by IDE/Editor to list all available packages that can be imported to the .go. If you see the document, the GO111MODULE has three values on, off or auto. See module support. Means when module support enabled, then it ignore all the packages on GOPATH. Which the available packages only based on go.mod that traverse all to the dependencies.

go example, when I create go project with module support

$ mkdir myapp && cd myqpp
$ go mod init github.com/uudashr/myapp
$ go get github.com/uudashr/gopkgs

The go.mod will look like

$ cat go.mod
module github.com/uudashr/myapp

require (
	github.com/karrick/godirwalk v1.7.3 // indirect
	github.com/uudashr/gopkgs v1.3.2 // indirect
)

But when list the modules

$ go list -m all
github.com/uudashr/coursehub
github.com/karrick/godirwalk v1.7.3
github.com/pkg/errors v0.8.0
github.com/uudashr/gopkgs v1.3.2

This is what supposed to be provided by gopkgs, not packages from GOPATH. With additional all the built-in packages provided by go lang itself. That become the definition of all packages available to imports for module supported project.

Which I still can't find the built-in API for the module support, on how to read and traversing the packages. As you see github.com/pkg/errors are not defined on the go.mod, but it was defined by the godirwalk module as dependencies.

@windler
Copy link
Author

windler commented Sep 2, 2018

I see your point, did not think of that.

Which I still can't find the built-in API for the module support, on how to read and traversing the packages

Go itself seems to use internal api cmd/go/internal/modload. Until there is no explicit api to get all modules I see why you are thinking about whether or not this feature should be implemented in vscode-go.

@uudashr
Copy link
Owner

uudashr commented Sep 3, 2018

Maybe the only way to do it is by implement our own the module loader or create copy the internal cmd/go/internal/modload

@uudashr
Copy link
Owner

uudashr commented Sep 23, 2018

I think we can close this. See #8

@windler windler closed this Sep 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants