In this update, we’ve added some new features for Go workspaces, generics, and more.
Syntax highlighting and navigation for go.work
One of the new and exciting features of the Go 1.18 release is workspaces. In GoLand 2022.1, we’ve added basic support for
In this update, you’ll find syntax highlighting in
go.work, as well as the ability to navigate to modules. To go to a module, press ⌘ (Ctrl for Windows/Linux) and click on its name, or place the cursor on a module’s name and press ⌘B (Ctrl+B).
We’re continuing to improve support for type parameters. So far, more than 250 generics-related issues have been fixed. In this update, we’ve added some new inspections and fixed some bugs.
Report usage without instantiation
If you try to use a generic type without instantiation, GoLand will display an error and suggest adding square brackets.
Report usage of a given type as a type parameter
Defining a named type on a passed type parameter is not permitted. As the Go documentation says, “the given type cannot be a type parameter” in a type definition. Usage of a given type as a type parameter is now highlighted as an error.
Report type arguments and parameters mismatch
You have to be consistent about the number of parameters in the type declaration and the number of arguments in type usages. The IDE will help to keep things in order by reporting mismatches between arguments and parameters.
Highlight missing arguments for conversion
GoLand now shows an error if a type conversion to a generic type is missing the expression to be converted.
Fill generic struct fields
In GoLand, you can automatically generate field names for a struct. Now you can do the same with generic structs.
Start typing the struct name, select it from the completion list, then place a caret between braces of a struct and press ⌥ ↩ (Alt+Enter) or ⌥ Space (Ctrl+Shift+I). The IDE will show you several options – you can fill in all of the fields or just the ones you need.
Support for the ‘all’ prefix in ‘//go:embed’
//go:embed directive allows you to embed files and folders into the application binary at compile time without using an external tool.
If you embed a directory, then all files beginning with a dot (
.) or underscore (
_) are excluded. To include them, you need to use the
all prefix. GoLand now supports this prefix.
To learn more about how to use
//go:embed, read this blog post.
Helm and Go templates
We’ve added two new context groups to our Live Templates – Go Template and Helm. There are several default templates in the Go Template group and one in the Helm group. You can add your custom live templates in both groups and link them to any of the added contexts.
That’s it for today. As always, your feedback and comments are appreciated. Get in touch with us on Twitter, leave your comments here, open an issue in our tracker, or drop us a message in the Gophers Slack #goland channel.