GoLand package index breaks when using multiple versions of the same module - go

I need to use both a v1 and alpha version of the google.golang.org/api/compute api in a project I'm working on. The need to use the alpha version came up after already using the v1 version for quite a bit of code, and I need to use both versions at once.
When I import the alpha version, GoLand indexing breaks and I lose auto completion and get a bunch of red text/lines in my packages that import alpha. Though, go will still build/run the code just fine.
I've tried clearing my GoLand cache and re-indexing, but am still having the same issue. I've also cleaned my go cache with go clean -modcache and go mod tidy to download and checksum everything again.
Is there something I'm missing that would make this an issue in GoLand, but my go code still builds and runs fine?

You can navigate to the package sources by pressing Command/CTRL+Click on the import statement and find compute-gen.go file and size limit warning. The IDE behaves as expected.
As a workaround, you can invoke Help | Edit Custome Properties... and add the following line idea.max.intellisense.filesize=8500000, restart GoLand. But please keep in mind that the IDE can be slow when dealing with large files even if they're not open in the editor.
You can read more about the idea.properties file here.

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

corrupting golang file when saving in visual studio code

When I save a golang file in visual studio code, it ends up being corrupted -- characters are removed, not in any pattern I have discerned. This has occurred at various times in the past, but has just now recurred. For details, see my bug report, "corrupting file when saving in visual studio code #49465"1.
In the meantime, what I can do until it's fixed? Perhaps I could return to an older version of gopls, but I don't know how to do that.
Any suggestions welcome. I'm stuck until I can successfully save and run my go programs.
Thanks!
Please try running the following command
GO111MODULE=on go get golang.org/x/tools/gopls#master golang.org/x/tools#master
or
GO111MODULE=on go get golang.org/x/tools/gopls#v0.3.2-pre1
In order to make progress on my project, I've downloaded the prior version of go. At least on Windows, the downgrade installs like any upgrade, including offering to remove the existing version.
And I backed up gopls to its previous version using the facilities of VS Code:
ctrl+shift+X to access extensions
right-click on Go
select Install Another Version
wait...wait...wait...
when the list of versions finally appears, select the one you want (I went back a month)
So, the underlying problem still exists, but I'm back in business. I hope these instructions can help someone else battling with the disappearing character bug.

Issue with using a modified version of a Go dependency

So here is the situation:
I have a fork of go-ipfs. It depends on go-ipfs-config. I need to modify go-ipfs-config and make go-ipfs depend on my modified version.
I forked the go-ipfs-config made my changes and made sure to update the path to be that of my forked version as can be seen here. I confirmed that this still builds successfully by running go build
Then I updated go.mod in go-ipfs to use my modified version. I used the replace directive to signify this intention which can be seen here
This is where things gets absolutely bunkers and I am no longer sure what is going on.
When i do go mod tidy to fetch the dependency i get the following output:
go: finding module for package github.com/dadepo/go-ipfs-config
go: found github.com/dadepo/go-ipfs-config in github.com/dadepo/go-ipfs-config v0.5.3
The crazy thing is that v0.5.3 does not exist in github.com/dadepo/go-ipfs-config!
Also the following line get added to go.mod :
github.com/dadepo/go-ipfs-config v0.5.3 // indirect
Which can even be seen here
I have run commands like go clean -modcache and go clean -r etc but does not seem to fix things!
Does anybody know what I am doing wrong? And also how to achieve the goal of making my version of a project depend on another modified version of its dependency?
Ok, so this is as a result of me not being aware of couple of things going on in the Go lang toolchain.
Apparently https://proxy.golang.org is a thing! It is a service operated by google that caches modules. So If you made a release, deleted it, chances are that the version is already cached in https://proxy.golang.org. This was exactly what happened in my case. I had made a 0.5.3 release, deleted it, but it is not really gone as the Google cache already got a hold of it.
So in case you are seeing versions that should not exist. This should be the first place you check. This documentation link also sheds some more light on the proxy and how it can be tweaked.
I found this out based on the conversation I had on the issue I opened reporting this behaviour. If you are curious, you can check it out here.

Module does not cache/save in golang test/build process. How do you work around this?

In one of my projects, using go modules. It has started to continually do a search for a module every single time I do anything. I include lots of modules, but only one does this (see below). How do I work around this?
> go test -run TestUodate
go: finding github.com/mohae/deepcopy latest
PASS
ok example.com/example/stuff 0.698s
This symptom looks like the one in https://golang.org/issue/29773, which is fixed at head (but not in go1.13beta1 or earlier releases). Try it using a go command built from head, which you can obtain easily using the gotip tool.
If you're still seeing this using gotip, please open an issue by filling out the template at https://golang.org/issue/new.

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.

Resources