GoLand 2021.1 Reaches Beta!

The release of GoLand 2021.1 is just around the corner, and today we can announce that GoLand 2021.1 Beta is ready for you to try.

GoLand 2021.1

The Beta version is quite stable in comparison to the Early Access Program builds, but please keep in mind that there may still be a couple of rough edges here and there.

Beta builds are usually the last builds in the EAP cycle that do not require a subscription to use.

GoLand 2021.1 allows you to build and run your program remotely via Docker, SSH, and WSL 2. You will find the new features from Go 1.16 supported, including //go:embed, code generation from JSON, and dozens of quick-fixes for easy error handling.

As usual, you can get the build via the Toolbox App, download it from our website, or use a snap package (for Ubuntu). Or you can update using GoLand, just select Automatically check updates for Early Access Program in Settings/Preferences | Appearance & Behavior | System Settings | Updates.

Download GoLand 2021.1 Beta

If you want an interactive introduction to the new features, the new What’s New in GoLand 2021.1 course is already available for you on the Learn GoLand tab of the Welcome screen.

Run Targets

In GoLand 2021.1 you can develop on your machine, with all the source code available to you locally, and target remote computers to run your code. Currently, the IDE supports Docker, SSH, and WSL 2 (Windows Subsystem for Linux). In settings, choose Run | Manage Targets…, click the Add icon (+), and select the targets you want to work with. After completing the configuration, you need to specify the Run Configuration from Run | Edit Configurations… and select the target you want to work with.

Please note that Run Targets support is still in its early stages, and you might encounter some limitations.

Go 1.16

Support for //go:embed

Starting with Go 1.16, you’ll be able to embed files and directories into a Go binary at build time.

Embedding works on a few types of variables: string, []byte, and embed.FS. You need to declare these variables at the top level of your package, which means that function bodies cannot contain them. Finally, you need to add the //go:embed directive for embedding to work.

GoLand provides code highlighting, navigation from references inside the embed directive to files and folders in your project, Rename refactoring, Find Usages, code completion, and a few code inspections. For example, GoLand will notify you if you try to embed files into a variable of the wrong type.

Detecting incorrect usages of (t/b).Fatal

GoLand warns you about invalid calls to the testing.T method Fatal within a goroutine created during the test. The dedicated quick-fix will rewrite the code calling t.Fatal (or a similar method) so that it signals the test failure using t.Error and exits the goroutine early using a return statement.

Detecting incorrect usages of asn1.Unmarshal

In Go 1.16, go vet detects incorrect usages of asn1.Unmarshal, making sure that the value in which a slice of bytes is unmarshaled is not nil. GoLand 2021.1 provides a similar check with a quick-fix to resolve this problem.

Working with JSON

It’s now much easier to create JSON and XML tags for all the exported fields in the struct.

When you use Alt+Enter to invoke Add key to tags on the struct or on any field in the struct, GoLand adds a tag to all fields in the struct with field names. If you want to change the style of the field name for all tags, press Alt+Enter again on any key and choose Change field name style in tags. The supported styles are fieldName, FieldName, field-name, and field_name.

You can update all tag values at once with the Update key value in tags intention action. Press Alt+Enter on any tag value in your struct and GoLand will add carets at the end of the tag values in every field.

Additionally, the IDE provides a completion for well-known tokens inside tag values provided by SDK for JSON, XML, and ASN.1 code.

Generate a struct with fields and tags from JSON in no time by simply copy-pasting JSON data into the editor. If you want to adjust the JSON before generating a struct, press Alt+Enter to invoke the Generate type from JSON intention. GoLand will open the Generate Go type from the JSON window with the copied JSON. You can tune it as you wish in the window, then press the Generate button and your struct will be ready to go. Of course, it’s also possible to paste JSON into the window manually.

Additionally, it’s possible to convert JSON inside an already existing empty struct. To do so, just click this empty struct and call the Generate struct fields from JSON intention action by pressing Alt+Enter or by using the Generate menu.

Additionally, GoLand will notify you if you use invalid JSON code in the Generate Go type from JSON window.

Last but not least, GoLand 2021.1 supports the newline-delimited JSON Lines at used for working with structured data and logs. The IDE will recognize .jsonl, .jslines, .ldjson, and .ndjson file types.

In this format, files contain several lines, and each new line is a JSON object separated by a newline character. Commas are required at neither the beginning nor end of lines, and there is no need to enclose the entirety of the file contents in square or curly braces.

Handle errors with ease

The Unhandled Error code inspection has gained a whole family of quick-fixes:

  • The Handle error quick-fix assigns call results to variables and generates an if error not nil check.
  • The Wrap error handling in a closure quick-fix, which is available for defer and go statements, produces code similar to Handle error but wraps everything in a closure.
  • We’ve extended the Ignore explicitly application area to include defer and go statements. The quick-fix assigns the call results to blank variables and wraps everything in a closure.

Other quick-fixes

Quick-fix for type incompatibility inside composite literals

We’ve expanded the application area of the quick-fix that addresses type incompatibility. It now also suggests implementing an interface and converting to the expected type inside composite literals.

Create Type quick-fix generates missing fields

The Create Type quick-fix offers not only to create a type when GoLand notices you are using one that has not yet been defined, but also it will create fields for you as well.

Generate all getters and setters at once

Generating get and set methods for each field in huge structs can be rather tedious. You can now generate getters and setters for the whole struct all at once. Press Alt+Enter on any field name in the struct, then choose Generate getter and setters from the drop-down menu. GoLand will open the Select Fields window, where you can generate get and set methods for all the fields or just for the fields you need.

Refactorings

The Extract Type refactoring lets you extract a type from an existing one or convert an anonymous structure type to a named type. Press Ctrl+Alt+Shift+T on Windows/Linux or Ctrl+T on macOS to invoke it.

Go Modules

Sometimes you need to rename a module once you have sufficiently experimented with the project and done all your initial work. We’ve added a Rename refactoring to the go.mod file. It allows you to rename the module with a new name safely,without needing to do a search and replace in the project tree to replace the old module name.

Invoke the Rename refactoring on the module name with ⇧F6 on macOS or Shift+F6 on Windows/Linux. GoLand will open the Rename window, where you can change the current name, choose whether to change it in comments and strings, and open a preview of the refactoring. From the Refactoring Preview tab, you can navigate to all usages of this module name. You can use undo to quickly revert all changes implemented using the refactoring.

Postfix Completion

New varCheckError Postfix Completion

Type .vCE after an identifier that returns an error, and the IDE will automatically add default variable names and return the error from the function.

Formatter

Support for import grouping in the style of “goimports -local”

The built-in formatter can now group imports in the same way goimports -local does.

To enable this support, head over to Preferences/Settings | Editor | Code Style | Go | Imports and enable import grouping. Then you can specify which imports should be grouped into separate blocks.

Run & Debug

Run program with sudo using elevation service

GoLand 2021.1 allows you to run an extended sudo session. On the first run, GoLand will ask whether you want to keep sudo running or terminate it immediately. If you would like to

change your response, go to Preferences/Settings | Appearance & Behavior | System Settings | Process Elevation.

Please note that by enabling this option you grant GoLand and all third-party plugins access to your system.

Code Completion

We’ve enabled Machine Learning-Assisted Completion. This change introduces the early stages of code completion based on machine learning (ML), which is an alternative to the standard ranking mechanism.

This code completion applies sorting rules learned from data we have gathered anonymously during our EAPs, resulting in better suggestions. Note that we have not collected any source code, only information about interactions with the code completion UI.

Tick Mark position changes in the completion popup in Preferences/Settings | Editor | General | Code Completion to mark options reranked by ML completion with up/down arrow icons in the completion list.

UI improvements

Quick Access Menu

The Configuration widget, which was previously available in the bottom left-hand corner of the IDE, has been replaced with a quick access menu. This new menu appears in the top right-hand corner. Press the gear icon to switch themes or keymaps, navigate to plugins, or go to the settings.

Quick access to recent projects on Windows

You can now access your recent projects by right-clicking on the GoLand icon on the taskbar or on the Start menu in Windows.

Better tooltips display

Tooltips are now shown one after another to prevent them from overlapping.

Improved accessibility

We are continually working to make our IDE more accessible to all users. We’ve added more labels to UI elements on the Welcome screen, the Project Structure view, and the VCS log.

These elements and gutter icons are now read out correctly when a screen reader is enabled.

Font variations

You can now select the font variations from the Settings/Preferences | Editor | Font settings panel.

Other changes

Built-in HTML preview

We’ve added a new built-in browser preview that helps you quickly preview HTML files. Any changes you make to HTML files in the IDE, as well as in the linked CSS and JavaScript files, will be immediately saved, and the preview will update on the fly.

To open the preview, click on the GoLand logo in the widget located in the top right-hand corner of the editor.

Maximize editor tabs in the split view

Need more space when working on multiple files simultaneously in a split editor? Double-click the tab you’re working with to maximize the editor window for it. To bring that tab back to its original size, simply double-click it again.

Makefile Language plugin works by default

The Makefile Language plugin (previously 3rd-party), which provides GNU Make language support, is now bundled by default. Starting with GoLand 2021.1, you will get syntax highlighting, quick documentation, Find Usages for targets, and some navigation and code completion actions for Makefile right out of the box!

Visual Stage Separator in multistage Dockerfiles

It’s now easier than ever to read multistage Dockerfiles thanks to the separator lines that define boundaries between one stage and another. No more guesswork is needed to determine when a stage ends and when one begins.

That’s all for today! We always love hearing from you. Share your thoughts here in the comments, send us a message on Twitter, report any issues you find to our bug-tracker.

The GoLand team

Discover more