My auto-complete / intellisense stopped working after upgrading from the Go extension here of Visual Studio Code: https://github.com/microsoft/vscode-go
I've opened an issue in there, but I'm thinking this might have to do with gocode.
I'm running Windows 10, Go version 1.5.1, Visual Studio Code 0.10.5 and Go extension 0.6.21. Was working fine before updating and I was using Go extension 0.6.17.
Problem is suggestions / intellisense works for internal package, but every external package I have no longer give suggestions when writing . or ctrl+space. Even net/http or core Go package does not work.
I wanted to try and run gocode myself to see what it's actually returning, so I've looked into the code for the extension and it is executing a child process similar to that: gocode -f=json autocomplete filename offset.
Not really sure how to get offset or what it represents, number of bytes for position that triggers the auto-complete? In any case, when I run this I got no output and I do not return to the prompt, I have to CTRL+C to return.
I'm unable to find anything interesting on Google either, probably wrongly searching or not exactly knowing what to search for.
Does someone would have an idea, goal of running gocode was to see if in fact the gocode was returning suggestion for external package than if yes, there's something with the extension.
If gocode does not returns anything, well it means it's not working properly now, anything I can do?
Thanks
Edit 1: Log from gocode following kostya answer
2015/12/23 07:26:11 Import path "github.com/gocraft/web" was not resolved
2015/12/23 07:26:11 Gocode's build context is:
2015/12/23 07:26:11 GOROOT: c:\go
2015/12/23 07:26:11 GOPATH:
2015/12/23 07:26:11 GOOS: windows
2015/12/23 07:26:11 GOARCH: amd64
2015/12/23 07:26:11 GBProjectRoot: ""
2015/12/23 07:26:11 lib-path: ""
It seems my GOPATH variable is not evaluated, but it's set, and when I run echo %GOPATH% I receive the correct value.
Try running gocode server process in the console and observe the output:
gocode close
gocode -debug -s
Make sure that you are running the latest version of gocode:
go get -u github.com/mdempsky/gocode
You might want to run the following command to build gocode instead (though I believe you won't be able to use debug method that I suggested in this case):
go get -u -ldflags -H=windowsgui github.com/mdempsky/gocode
as suggested at https://github.com/mdempsky/gocode
Related
I have project in Go. After I set up debugger and launch in Visual Code,
it failed with this error output. I am using go 1.13.4 in /usr/local/go
/usr/lib/go-1.10/src/crypto/tls/cipher_suites.go:18:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/chacha20poly1305 expects import "golang.org/x/crypto/chacha20poly1305"
/usr/lib/go-1.10/src/crypto/x509/x509.go:36:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/cryptobyte expects import "golang.org/x/crypto/cryptobyte"
/usr/lib/go-1.10/src/crypto/x509/x509.go:37:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/cryptobyte/asn1 expects import "golang.org/x/crypto/cryptobyte/asn1"
/usr/lib/go-1.10/src/crypto/tls/key_agreement.go:20:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/crypto/curve25519 expects import "golang.org/x/crypto/curve25519"
/usr/lib/go-1.10/src/net/http/h2_bundle.go:48:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/net/idna expects import "golang_org/x/text/internal/export/idna"
/usr/lib/go-1.10/src/net/http/transport.go:32:2: code in directory /usr/lib/go-1.10/src/vendor/golang_org/x/net/proxy expects import "golang.org/x/net/proxy"
This seems to happen when you have a newer version of Go available on your PATH.
I worked around it by uninstalling Go 1.13 from /usr/local, but there may be better ways to handle it if you need to have multiple versions installed.
I had the VSCode Go debugger working with go.goroot set to a Go 1.11 install I was using for my project. I installed Go 1.13 into /usr/local to test out a feature and then ran into this same error.
If you have a different Go version on the PATH it seems like it's using that compiler, but compiling against the standard library sources in your other Go version. In later Go versions this directory has been renamed back to vendor/golang.org, and it doesn't recognize the golang_org hack that was used previously:
https://github.com/golang/go/commit/4d00937cecdea85b6f1eb894a6d28a53f5f2ff8a#diff-44c7c5a1dcc556d22e115d30ec0f11c9
I'm not certain if this is a general problem with Delve, or an issue with how the VSCode Go extension calls it, but the simplest solution in my situation was to uninstall Go 1.13 and the debugger started working again.
Your problem has nothing to do with the debugger. If you would have searched for the key parts of these errors, you would have discovered that the error is due to the fact since v1.4 Go supports so-called "canonical imports".
Most probably some packages in your project were vendored using their "hosting" URLs (such as github.com/what/ever) instead of their canonical URLs suggested by the error message.
The proper solution is to revendor the affecting packages the correct way.
If you merely want the code to build "as is" no matter what, you could edit the code of these packages to remove "canonical import comments" from them.
Im new to go and I have been unable to find any thing online for my issue.
I have downloaded this code https://github.com/hashicorp/http-echo and I would like to set it up so I can run this command.
$ http-echo -listen=:8080 -text="hello world"
I have been getting quite a few different path issues.
Currently I have the code sitting in this directory.
/Users/jon/go/src/github.com/hashicorp
When I try and install it I get this error
$ go install http-echo
can't load package: /usr/local/go/src/http-echo/handlers.go:9:2: non-standard import "github.com/hashicorp/http-echo/version" in standard package "http-echo"
Where should I keep go projects on an OSX computer, and how do I get this to install or compile?
The code currently seems to be in /usr/local/go/src/http-echo. Packages should always reside in the directory $GOPATH/src/package-name, e.g.: $GOPATH/src/github.com/hashicorp/http-echo. (unless you're using go modules).
It should work if you move the source to the correct path (/Users/jon/go/src/github.com/hashicorp/http-echo). Then execute:
go install github.com/hashicorp/http-echo
Even easier would be to use go get to download the package in the first place. Simply run the following command from any directory:
go get github.com/hashicorp/http-echo
And http-echo is automagically installed.
If you still get an error after this, make sure $GOPATH/bin is in your $PATH.
I have latest IntelliJ Ultimate EAP and latest Gogland and the problem occurs on both under MacOS Sierra.
I'm trying to debug a go application by creating a debug profile for Go Application and the Run Kind is configured to Package, which contains the package name of the current project.
under Go tool arguments I have -ldflags="-linkmode internal" configured.
When I start a debug session while having some breakpoints, it would run but not stop at these breakpoints.
what am I missing?
thanks
update
ok I was able to reproduce the issue with the following project:
test1.go contains:
package main
const Numb uint64 = 5
test2.go contains:
package main
import "fmt"
func main() {
fmt.Println(Numb);
}
I Created a Go Application run/debug configuration with the following parameters:
Run kind: package
Package: github.com/kfirufk/test
Working Directory: /usr/local/Cellar/go/1.8.1/src/github.com/kfirufk/test/
when I choose a breakpoint on test2.go line 6 (the first and only line of code in the main function) and I start a debug session, I see the following output:
"/Users/ufk/Library/Application Support/IntelliJIdea2017.1/Go/lib/dlv/mac/dlv" --listen=localhost:53111 --headless=true exec /private/var/folders/cn/n7rwdd_95_l54s3zdnbxvw040000gn/T/Unnamedgo --
GOROOT=/usr/local/Cellar/go/1.8.1/libexec
GOPATH=/usr/local/opt/go
/usr/local/Cellar/go/1.8.1/libexec/bin/go build -o /private/var/folders/cn/n7rwdd_95_l54s3zdnbxvw040000gn/T/Unnamedgo -gcflags "-N -l" github.com/kfirufk/test
API server listening at: 127.0.0.1:53111
5
I get the program's output properly but Intellij did not stop in the required breakpoint.
the problem is reproduced on Intellij 2017.1.3 with Go Lang Plugin 0.171.1928 on MacOS Sierra 10.12.4.
update
trying to play with intellij's delve to try to understand better what's going on:
/Users/ufk/Library/Application\ Support/IntelliJIdea2017.1/intellij-go/lib/dlv/mac/dlv exec ./test
then I executed:
(dlv) step
and received:
Command failed: could not find FDE for PC 0x78bc000
did I fail to understand how to use delve or is something doesn't work properly here ?
update
yeap.. with continue the debugger works properly with both versions of delve (installed from homebrew and the intellij's version). but still intellij works the same, doesn't stop at breakpoints. i create a breakpoint at test2.go at the line when I print the variable.
any ideas ?
Ok.. I finally got it. I got mixed up with the GOROOT structure and GOPATH structure and I placed my project in GOROOT instead of GOPATH.
this is what I did to resolve the issue
I completely deleted go with brew uninstall --force go, then reinstalled go with the following environment variables:
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
then I placed my project at ~/golang/src/github.com/kfirufk/windy-server
and I was finally able to properly debug go applications.
thank you all for assisting me! :)
For my case (VSCode on Ubuntu 20.04), if the project is inside a symbolic link directory (or sub-dir of a symbolic dir), vscode will shows "unverified" breakpoints and
"Error on CreateBreakpoint: could not find file ..."
which leads to not stop on breakpoints.
cd \`readlink -f <project dir>\` && code .
will be ok.
For me, issue resolved adding:
export GOROOT="/usr/local/go"
to $HOME/.profile.
EDIT:
I'm using LiteIde X35.2, with Delve Debugger
Version: 1.1.0
Build: $Id: 1990ba12450cab9425a2ae62e6ab988725023d5c $
under:
DISTRIB=LinuxMint VERSION=18.3 CODENAME=sylvia
RELEASE=#41~16.04.1-Ubuntu SMP Wed Oct 10 20:16:04 UTC 2018
UBUNTU_CODENAME=xenial KERNEL=4.15.0-38-generic HDWPLATFORM=x86_64
DESKTOP_SESSION=XFCE WINDOWS_MANAGER=XFWM4
DESKTOP_COMPONENTS=kdevtmpfs gnome-keyring-d xfce4-session xfce4-panel
xfce4-volumed polkit-gnome-au xfce4-power-man xfce4-terminal
gnome-pty-helpe
GTK=libgtk-3-0:amd64 3.18.9-1ubuntu3.3 GStreamer=gst-launch-1.0
version 1.8.3 GStreamer 1.8.3
https://launchpad.net/distros/ubuntu/+source/gstreamer1.0
In my case, the process was already running at that port and didn't close. So I had to manually stop the process and run again from IntelliJ.
In my case (GoLand), the problem was with the flag -trimpath not being set in my debug configurations:
"Run", "Debug...", "Edit Configurations."
In the templates item, go to "Go Test" option and add the argument -trimpath in "Go tool arguments"
You can also set in your environment with:
go env -w GOFLAGS="-trimpath"
That also works for the "attach to process" debugging option.
You can see GoLand IDE Logs in the menu "Help", "Show Log Files". It will make your life easier.
Reference: https://youtrack.jetbrains.com/issue/GO-8277
I switched from go 1.6 to 1.4.2 for faster compilation. When I recompile the earlier compiled binary of 1.6, I get the following error:
import go/pkg/darwin_amd64/github.com/Sirupsen/logrus.a: object is
[darwin amd64 go1.6 X:none] expected [darwin amd64 go1.4.2 X:precisestack]
I have already tried go build -a - which works without any error. And have also tried go install -a and go build - both of these commands throw the above mentioned error.
I already know that, if I delete by go/pkg folder, then it will work. That is the answer of the already existing SO question
I wanted to know, if there is another way to resolve this using go tools, other than deleting the pkg folder.
Most likely due to previous compiles. Just delete your $GOLANG/pkg and you are good to go!
another way to resolve this using go tools, other than deleting the pkg folder.
The go tool chain is unlikely to be modified to handle this corner use case.
I'm trying out Go for the first time. I was following these docs and wanted to run the go tour locally, but I haven't figured out how to get it to work.
Where is the tool "tour" supposed to be found?
I'm on OSX 10.11.3, and I installed Go via Homebrew
my Go entries in .zshrc
export GOPATH=$HOME/code/Go
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
tour is not installed by default with an installation of go. You need to go get it:
go get golang.org/x/tour/gotour
Docs: https://github.com/golang/tour/
I had a problem too. This's my solution, on OSX let try
gotour
With version go1.8.1 darwin/amd64
It works for me using go1.4, but not with go1.7. If you just run go tool, it gives you a list of known tools. They seem to have removed it from tools.
$ gvm use go1.7
$ go tool
addr2line
api
asm
cgo
compile
cover
dist
doc
fix
link
nm
objdump
pack
pprof
trace
vet
yacc
$ gym use go1.4
$ go tool
6a
6c
6g
6l
addr2line
cgo
cover
dist
fix
nm
objdump
pack
pprof
tour # <--- here
vet
yacc
Firstly, it is no longer gotour. And secondly, for the time being, the tour package is located at: golang.org/x/website/tour as opposed to what A Tour of Go Welcome Page says.
So, at least for now:
The correct way to get tour is:
go get golang.org/x/website/tour
Or,
go install golang.org/x/website/tour#latest
After which you can run the command in the terminal:
$ tour
2021/06/22 17:46:48 Serving content from /home/user/go/pkg/mod/golang.org/x/website/tour#v0.0.0-20210616181959-e0d934b43647
2021/06/22 17:46:48 A browser window should open. If not, please visit http://127.0.0.1:3999
2021/06/22 17:46:52 accepting connection from: 127.0.0.1:33192
To find out where it has been installed, you can do which tour:
$ which tour
/home/user/go/bin//tour
reference
Because of changes in Go package management and introduction of modules, this has changed since the original question. Thus, for future reference (as this is the first Google result), if you have not configured GOPATH environment variable
go get golang.org/x/tour
$HOME/go/bin/tour
Note that the executable is called "tour" instead of "gotour".
Source (with full explanation of why and details): https://stephencharlesweiss.com/getting-going-with-golang/
I've got:
golang.org/x/tour/gotour has moved to golang.org/x/tour
So, this works for me:
go get golang.org/x/tour
then:
tour
When you install go, tour is not installed by default. You need to do a go get golang.org/x/tour/gotour. This downloads gotour in your workspace.
If you configured your PATH properly, gotour command from anywhere in the terminal will open up your browser, but if PATH is not configured properly, do a
$GOPATH/bin/gotour
This command can be used from anywhere in your command line and it opens tour in your default browser
http://whipperstacker.com/2015/09/27/how-to-run-the-go-tour-locally/
https://github.com/golang/tour/blob/master/README.md
Once gotour is installed, it’s executable like other executables are typically stored in the bin directory of your workspace. Inside the bin directory ./gotour will invoke or start gotour, elsewhere the gotour will need to be preceded by a path to where the executable is located. In other words $GOPATH/bin/gotour will invoke or start gotour when you are not inside the bin directory.