which ide now can support go1.18 workspace - go

I use this command to init workspace
go work init mypkg example
My code can run but the goland 2021.3 can not support it very well.Is there a way to solve it?

I believe goland has its own parsing implementation, so you will have to wait for an official update.
If you want to try out go1.18beta you can use VSCode or any other editor/IDE which uses gopls. The go extension in VSCode uses gopls which provides some support for generics and workspaces. It is not perfect yet, but that is to be expected with beta software.

Related

Why would this particular package fail to be auto-imported?

I'm using VSCode with a few Go projects, in a workspace. I've got pretty standard VSCode settings, and I'm using the Go extension with gopls.
When in my code I'm using a package which has been installed in my current module, it is auto-imported successfully (i.e. "github.com/gosimple/slug").
But when I'm using spew the auto-import happens to be "app/env/pkg/mod/github.com/davecgh/go-spew#v1.1.1/spew" instead of "github.com/davecgh/go-spew/spew", everytime.
It also happens (only sometimes) with another package, "github.com/google/uuid".
Now I don't think it's related to these particular packages in any way, but I'm struggling to find a cause to this, and why only these packages.
vscode 1.68.1
go 1.18
gopls 0.9.0

Is there an alternative to get the Golang code completion in VS Code without installing Go?

My goal is to use Go exclusively on Docker. In other words, I try my best not to install Go directly to my computer. And, I am writing the code on a VS Code and use the "Go" extension.
The problem is that when I create a main.go it throws an error:
Failed to find the "go" binary in either GOROOT() or PATH(/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin). Check PATH, or Install Go and reload the window. If PATH isn't what you expected, see https://github.com/golang/vscode-go/issues/971
Is there an alternative to get the code completion feature in VS Code?
This should be achievable using the Remote Development Extension pack. VSCode has good documentation on using containers as your development enviroment. This will allow you to enjoy all of the Go extension's features without needing Go to be installed directly on your machine. You can opt to install the extensions in the container as well.
See Developing inside a Container

Is it possible to get documents info like GoLand for VScode in Go?

Before I used VScode for Go development and recently I've tried to use GoLand and found out there's a feature in GoLand that it will show the document info for the functions when mousing over, like the pics below.
Is it possible to set up in VSCode?
I am not sure about inclusion of example snippets in the documentation hover, but for regular documentation, that should work in VSCode if you use the go extension.
If not, I guess there is another issue so the go extension (and the language server) couldn't correctly process the project.

Shortcut to install libraries in Goland

I'm following the instructions in https://golang.org/doc/code.html#Library and trying to use Goland. I'm surprised though that I can't find a fast way to install the library I'm writing. According to the tutorial, you should use install to install your code in the pkg or bin folders, yet I can't find a way to do this in Goland other than writing it in the console.
What am I missing?
There are two ways to import Go packages using GoLand:
copy-paste the code that needs the package into the IDE and then on the import declaration use Show Intention to see the list of actions available and choose the first one, go get -t <package-name>/...
copy the URL of the Github repository into your clipboard, switch to the IDE and use the pop-up to run go get on the package. The pop-up disappears after a few seconds.
I've attached the image which shows these options.
This will download libraries in the correct GOPATH directory and run go install as part of the go get action.
As for installing the libraries that you are developing in GOPATH/pkg, there is no need for that, as soon as you run any configuration from the IDE, be it an application or a test that depend on those libraries, the IDE will install those libraries as well.

Install exp/html in Go

It looks like Go doesn't support HTML web parsing tools/packages yet, despite it already providing XML scraping via encoding/xml. So how can I install exp/html package in Go?
As far as I know, all the answers, at least I stumbled upon on the Web with 10 minutes worth of searching, didn't return the correct answer; when I tried to run those, I got the error cannot find package XXX in YYY or no Go source files in XXX.
So as of now, can I install it without re-compling and setting the whole Go environment from scratch? Or am I missing something?
I'm on OS X 10.8 and run Go version 1.1, which I installed from OS X package installer.
For your information, these code didn't make it.
go get code.google.com/p/go/src/pkg/exp/html
go get code.google.com/p/go.exp/inotify
Thanks.
I just tried:
go get code.google.com/p/go.net/html
and it seemed to work.
I have a feeling it's been moved from the exp library to the new net library.
EDIT: Documentation & browseable repo.
With go 1.4 (November 9th, 2014), you will have to type:
go get golang.org/x/net/html
See:
"New Import paths for Go sub-repositories".
"Go 1.4 subrepo renaming".

Resources