GoLand 2020.2 Reaches Beta with Upgrades for go.mod and Experimental Support for Generics

Posted on by Ekaterina Zharova

Today, GoLand 2020.2 reaches Beta. This means that we’ll end our flurry of new feature development, shift our focus onto perfecting what we’ve already done, and start counting down the days until the release party!

The Beta is quite stable in comparison to our Early Access Program builds, but keep in mind that there may still be some rough spots here and there.

Please note, as well, that this Beta build is the last build in the EAP cycle that does not require a subscription to use (if you are just looking to give GoLand a try). Betas are usually followed by a Release Candidate once we see that the build is good enough and that it’s ready to be installed on your machines.

This release cycle, we’ve packed the upcoming GoLand 2020.2 with new features for Go modules, better presentation of possible problems and weak places in your code, new code inspections, new code editing features such as the long-awaited Add Caret Per Selected Line, improvements to background processes to make them more transparent and quicker, and more!

Download GoLand 2020.2 BETA

Your feedback is vital to us, so please don’t hesitate to make yourself heard.

Let’s have a look at what’s new in the upcoming release. Choose a topic you are interested in, or go through the whole blog post to learn about each new feature.

Go Modules

Support for the GOMODCACHE environment variable

Starting with Go 1.15, it is possible to change the default location of the Go Modules cache from $GOPATH/pkg/mod to another folder by using the new GOMODCACHE environment variable.

To do that, just set GOMODCACHE in Preferences/Settings | Go Modules | Environment.

The IDE will recognize the custom location and use it for all subsequent actions with dependencies. The Sync dependencies quick-fix (available via Alt+Enter) will download dependencies to GOMODCACHE, resolve will lead there, and External Libraries will show dependencies in the new custom location as well.

Upgrades for the go.mod file

The Comment With Line Comment (Ctrl + / on Windows/Linux and ⌘/ on macOS) action is now available for the go.mod file.

GoLand now adds a closing brace immediately when you type the opening brace for replace, exclude, and require statements.

Generics a.k.a. Type Parameters

On June 16, the Go Team announced a draft design for generics, a.k.a. type parameters. Please visit the Golang documentation for the full details of the concept.

This is a major development, so we immediately set about working on adding support for it. GoLand 2020.2 Beta provides experimental support for generics that you can play with by turning on the Enable experimental support for generics a.k.a. type parameters setting in Settings/Preferences | Go.

This initial support provides syntax highlighting and basic reference resolution, and works in go2 files only.

Please note that work on generics is still in progress and we are currently far from providing full support.

Nonetheless, please share your impressions and any suggestions you may have. It really helps us polish what we’ve done so far, so we can make it reliable and stuff it with more advanced features.

Code Editing

To preview the result of an intention action or quick-fix before you apply it to your code, invoke the Show Context Action with the Alt+Enter shortcut, select the required intention action or quick-fix, and press Alt+Space on macOS or Ctrl+Shift+I on Windows and Linux.

The new Add Caret Per Selected Line action creates carets at the end of each selected line and deselects the lines. Invoke it using the shortcut Alt+Shift+G on Windows/Linux or⌥⇧G on macOS.

Configure wrapping for call arguments, function parameters, and composite literal elements in Preferences/Settings | Editor | Code Style | Go | Wrapping and Braces. Alternatively, you can use the Put arguments on separate lines and Put arguments on one line intention actions using Alt+Enter to split and join elements manually.

Code Inspections

GoLand 2020.2 has a new Inspections Widget! It’s located in the upper right-hand corner of the code editor, and shows the number of warnings, errors, and typos in the current file. You can go through them using the arrow icons or the Next Error action (F2).

The widget lets you configure the highlighting level (select from none, errors only, or all problems), change the severity level of inspections, and toggle the Compact View.

We’ve also added a Problems View tool window, which displays a list of warnings and errors in the current file, gives you a description of those problems, and lets you fix them immediately using Alt+Enter. Right-click on a problem in the Problems View tool window to move directly to the line of code where the error occurred. To open Problems View, click on the Inspection Widget or go to View | Tool Window | Problems.

GoLand 2020.2 now marks files which contain errors in the Project View in all cases to let you easier to spot them.

A new code inspection now handles possible problems with string(int) conversions which return the UTF-8 representation of the Unicode code point x instead of the expected decimal string representation of x. GoLand will notify you about such potential mistakes and provide dedicated quick-fixes.

GoLand will notify you about common erroneous usages of tests and examples, so you don’t need to call go vet explicitly for that anymore. The IDE also provides quick-fixes in simple cases; for example, it suggests renaming Testme to TestMe.

The Malformed struct tag code inspection will check that struct tags conform to Go conventions and notify you about potential problems.

Impossible interface type assertion code inspection checks for type assertions v.(T) and corresponding type-switch cases in which the static type V of v is an interface that cannot possibly implement the target interface T. This occurs when V and T contain methods with the same name but different signatures.

Take Variadic Arguments Under Сontrol

The Introduce Variable refactoring (Ctrl+Alt+V on Windows and Linux, or ⌘⌥ V on macOS) can pack some variadic arguments into a new slice variable, while Inline Variable (⌥⌘N on macOS and Ctrl+Alt+N on Linux and Windows), conversely, unpacks a slice into variadic arguments.

In addition, you can now handle issues with unpacked variadic arguments via the Unpack slice quick-fix.

References from Comments

The IDE displays references from comments to related package-level declarations and lets you navigate to them via the Navigate to Declaration or Usage action (⌘B on macOS and Ctrl+B on Windows/Linux).

Save Projects as Templates

You can now reuse projects or files by saving them as custom project templates: select Tools | Save Project as Template. The IDE will recreate the project tree with files, folders, and build configurations.

Under the Hood Processes

Better resolve for projects with a Vendor folder

With vendoring mode enabled, you build your application with only the dependency packages that are stored in the Vendor folder in your project.

Now if a project has a vendor folder and you’ve checked the Enable vendoring mode automatically setting in Settings/Preferences | Go | Go Modules, resolve will only use the vendor/ folder and will not consult the modules cache. An important advantage is that you discover unresolved dependencies faster.

Go list Commands

GoLand runs go list commands sequentially and provides a progress bar with information about the actual numbers of go list commands in the queue.

Version Control

WSL2 support for Git on Windows

GoLand 2020.2 will allow you to use Git from WSL2, which is natively available in the May update of Windows 10, version 2004. If Git is not installed in Windows, GoLand will automatically look for Git in WSL and use it from there. It will also automatically switch to Git from WSL for projects opened from WSL (via \wsl$ path).

Improved Git action dialogs

We’ve redesigned the Git dialogs for actions such as Merge, Pull, and Rebase to make them more consistent and informative. We’ve also made it easier to understand which Git command will be executed, and added the –rebase option to the Pull dialog and the –no-verify option to the Merge dialog.

Full support for GitHub pull requests

GitHub Pull Requests is fully equipped! Browse, assign, manage, and even merge pull requests, view the timeline and inline comments, submit comments and reviews, and accept changes without leaving GoLand.

Squash local commits from the log

You can now select a number of local commits in the Log tab of the Git tool window and squash them into one. This action is available from the right-click context menu.

Improved presentation of Compare branches results

Now when you are comparing 2 branches in GoLand, you’ll be able to see the commits of the compared branches in one view. The IDE will now open the logs of both branches being compared in the editor instead of in the VCS tool window, where there is not enough space to display all the information.