-
Notifications
You must be signed in to change notification settings - Fork 645
User-written packages fail to import with go.mod. GO111MOD=on #1942
Comments
This is not a VS Code problem. This is because that's not the way you import packages if you use Go Modules :-) When using Go, there is no such thing as a relative path. This will not work with "go build main.go" from the commandline either, given your scenario. When you do an import, Go looks for the package in: GOROOT/src In your go.mod, your own package name is defined in the first line as module , typically "github.com/username/packagename" if you're using Github at least. Your import statement in main.go should be: import "/packtest" And you don't need to turn GO111MODULE=on, if you're outside GOPATH it just works from Go 1.11 and onwards. |
And even w/ the "/packtest" line, there was still no auto-fill of the package methods. :/ P.S. Then again, I might just be doing something utterly wrong! |
@dreamheld After updating the import statement to "vstest/packtest" and adding a line that uses the package, I am able to get the completions when using the latest beta version of this extension If you are using the same beta version, did you get the prompts to install the fork of gocode? And did you install it? Can you try killing all running processes for |
@uudashr In the above code set-up, if I run |
I wasn't able to respond to this last night, but I think my issue was indeed that I never killed gocode process. The new beta (as of 20 min ago) seems to do the autocomplete for methods fine, but doesn't fill out the import statement automatically anymore. Also, package/method highlighting for the new package seems off. I'll poke more at it though |
My mistakes... |
Thanks @uudashr! It works now.
You mean that in a file where If yes, then I can confirm that @uudashr's updated Run |
@ramya-rao-a , nope. I've updated @uudashr 's tool and everything works swimmingly with automatically adding the import statement and auto-completing the 'packtest' package name. The only two issues remaining, it seems:
|
It also works if the any other symbol from the imported package is used already. This is being tracked in #1944 and I have an upstream issue for that in stamblerre/gocode#3
Can you share a screenshot for this? |
@ramya-rao-a , there! I'm not sure if I broke it somehow and the solution is trivial. |
I dont see any color issue ..... |
Ah, geez! My screen was in the night mode. so everything looked yellow. Duh... I apologize for wasting you time! |
lol.... I'll close this issue then. Thanks for reporting @dreamheld, it helped us catch and fix a bug! |
The issue is not with the custom packages vendored through online repos, but with those that you would write for your application yourself. They do not import and are invisible to VSCode.
Steps to Reproduce:
Create a new directory (vstest) outside of the current GOPATH.
Navigate to the new directory and run $go mod init vstest
Create a subfolder "packtest" with a packtest.go in it.
3.a packtest.go contains:
package packtest import "fmt" //PackPrint tests the autocomplete of user packages in vscode func PackPrint(){fmt.Println("PackTest Called")
Navigate back up to the vstest folder and create main.go.
In main.go try to call packtest.PackPrint(). It fails. Not only VSCode doesn't auto-complete the new package, it doesn't import it either. It also doesn't have it listed in the "Add Import..." option.
(go.autocompleteUnimportedPackages": true)
(env GO111MODULE=on)
Using the import statement like 'import "packtest"' doesn't seem to work either. package main gets highlighted in red with the error "Build vstest: cannot find module for path packtest".
The text was updated successfully, but these errors were encountered: