New Features in GoLand 2021.2
A selection of useful features from GoLand 2021.2
GoLand 2021.2 was released on July 29th, 2021! For more information about what's new in this release, check out our What's New Page or browse the tips below.
Check out DataGrip 2021.2 What's New and WebStorm 2021.2 What's New to read all about the new features related to database and modern web development included in GoLand.
Convert Slice to Array Pointer
With Go 1.17, it is possible to covert a slice to an array pointer.
Optimize your code by removing bounds checks when using slices and arrays.
Go 1.17 brings a new language change: Converting a slice to an array pointer yields a pointer to the underlying array of the slice. If the length of the slice is less than the length of the array, a run-time panic occurs.
Run gofmt After the Builtin Formatter
Ensure that your code is always formatted with gofmt.
To use this feature, check the On code reformat option under Settings/Preferences | Editor | Code Style | Go | Other.
Now you can use the default shortcut, ⌘⌥L (macOS) / Ctrl+Alt+L (Windows/Linux), to trigger the builtin formatter.
You can also search for Run gofmt in the IDE Settings/Preferences, and activate the option as described above.
Load go.mod Changes Manually
Take control of when go.mod files are refreshed.
Make all your changes then run go list at the push of a button.
Navigate to Settings/Preferences | Build, Execution, Deployment | Build Tools and select External changes instead of Any changes.
Then, edit your go.mod
file, and when you are done, press the button in the top-right corner of the editor to refresh these changes.
Declare a Targeted Go Version in go.mod
The IDE is aware of targeted Go versions so you can make the most of them
The IDE reads the go directive in the go.mod file when it analyzes files.
You don't need to do anything to use this feature. However, the IDE might suggest new operations based on the difference between the project SDK and the targeted Go version via go.mod.
Detect Unused Dependencies in go.mod Files
Cleanup go.mod files and keep them lean
Be on top of your dependencies and quickly locate unused modules with this inspection.
Open a go.mod
file and look out for dependency lines marked with grey.
Multiple Projects in one IDE Window
Work with multiple projects at once from the same IDE window.
Stop switching between IDE windows and keep all your projects in the same window.
Select the Attach feature when opening an existing project or creating a new one.
When your work is done, right-click on the project you want to detach and select Remove from Project View.
Reload Browser Pages on Save
Work on your frontend then switch to the browser to see how it looks like
The IDE can automatically reload the page opened in a browser after you make changes to an HTML file, or the linked CSS and JavaScript files.
First, open the file from the IDE via the icon on the upper right-side of the editor or via View | Open in Browser | "browser name".
Reloading is triggered whenever changes are saved in the IDE, either automatically or using Press ⌘S (macOS) / Ctrl+S (Windows/Linux), or when changes are made to a file externally.
Completion for Parameter Types
Better code completion makes working on modern web frontends faster and more enjoyable.
The IDE will show you completion suggestions based on the type used in the function call for the parameters in the function body.
You don't need to do anything to use this feature as the IDE will automatically infer the code suggestions based on what you typed already.
Pro tip: Use the Smart Type Completion, ⌃⇧␣ (macOS) / Ctrl+Shift+Space (Windows/Linux), to narrow-down the list further.
Live Template for Arrow Function
Create arrow functions quicker thanks to builtin customizable templates.
Live templates are a great way to quickly write common/repeating code. Arrow functions are no exception from this, so we introduced the arf live template to create them.
In any JavaScript file, type arf and follow up with Enter or Tab to complete the template and generate the corresponding code.
Support for TypeScript Types in JSDoc
Give the IDE new powers thanks to TypeScript-based types.
Declare the type in the JSDoc section above your object/function call and watch the IDE be able to infer the properties and methods of the target object.
Refactor Names in React useState Hooks
Rename both values of from useState hooks at once
Invoke the Rename refactoring, ⇧F6 (macOS) / Shift+F6 (Windows/Linux) and the IDE will detect automatically when it's invoked on a useState hook in a React application and offer to rename all names associated with them.
Code Completion for Classnames and More in React Code
Spend less time typing or explore the possibilities for various CSS class names in React aps.
You don't need to do anything special to use this feature. When using the classnames and clsx libraries, the IDE will show completion suggestions for your CSS classes and resolve all symbols in string literals and properties with literal names.
Sign Git Commits with GPG Keys
Improve the security of your commits by using GPG keys.
Configure the git client with the correct key. Then, head over to Settings/Preferences | Version Control | Git and check the option Configure GPG Key... to turn on this feature.
Run Tests Before Commit
Make sure your tests pass before reaching the CI/CD pipeline.
Invoke the Commit feature using ⌘K (macOS) / Ctrl+K (Windows/Linux), then select the Commit options and check the Run Tests option, then select which test configuration you wish to run.
Note: You must have the Use non-modal commit interface activated before you can use this feature. Check your settings under Settings/Preferences | Version Control | Commit.
You can use the Compound configuration type to run more than a single run configuration.
Run Inspections Before Commit
Catch all issues before your code before you commit it.
Committing error-free code reduces the time it takes for reviews to go happen and makes everyone happy. Since not all errors may be caught by tests, you can choose to run Inspections before a commit. This will improve your chances to have fewer bugs in code.
Invoke the Commit using ⌘K (macOS) / Ctrl+K (Windows/Linux), then select the Commit options, and select the Analyze code feature.
Cleanup Code Before Commit
Remove all the redundant parenthesis and other unneeded code before commit.
Sometimes an extra pair of parenthesis make their way into our code. Since it's not needed to improve the clarity or help the code function in any way, it's better to remove it. That's why, it's useful to run a Cleanup step before the code reaches upstream.
Invoke the Commit using ⌘K (macOS) / Ctrl+K (Windows/Linux), then select the Commit options, and select the Cleanup feature.
Quick Documentation for Keys in Dockerfiles and docker-compose.yaml Files
Learn about what the keys mean, find out how to use them, or what values they accept
As with any regular programming language supported by the IDE, place the cursor on a key in a Dockerfile
or a docker-compose.yaml
then invoke the Quick Documentation feature via F1 (macOS) / Ctrl+Q (Windows/Linux) and learn more about the desired key.
Restart a Running Container
Start with a container from zero, faster.
Sometimes you need to start with the application from scratch, and rebuilding the container is not needed. That's where the Restart feature comes in and helps you.
Select one or multiple running containers that you want to restart, then click Restart in the Services window.
Pause and Unpause Containers
Test what happens to microservices when they try to talk with an unavailable service.
When you need to test how a microservice behaves when another one is unavailable, use the pause feature. Then resume it without the hassle of starting the container from scratch.
Select one or multiple running containers that you want to pause or resume, then click on the Pause or Resume button in the Services window.
Inspect Port Mapping for Errors in docker-compose.yaml Files
Check if the ports are correctly mapped or not
Open a docker-compose.yaml
file and go to any ports mapping section to see if it contains any messages or not.
Inspect size_size Values for Errors in docker-compose.yaml Files
Check if the shm_size values contain any errors
Open a docker-compose.yaml
file and go to any shm_size value to see if it contains any messages or not.
Inspect device_cgroup_rules Values for Errors
Check if the device_cgroup_rules values contain any errors.
Open a docker-compose.yaml
file and go to any device_cgroup_rules value to see if it contains any messages or not.
Configure Custom Namespaces Manually
Use all the features you need even if the plugin cannot process the namespaces automatically
If the plugin cannot automatically infer the available Kubernetes namespaces, now you can configure them manually. This will solve the problem when the user does not have the required permissions to perform namespace listing.
Go to Settings/Preferences | Build, Execution, Deployment | Kubernetes and configure the namespace in the corresponding section.
Note: You must have the Kubernetes plugin provided by JetBrains installed for this action to work.
Run actions on save
Perform various tasks after you save the files you work on
If you want to perform tasks on save, you can now use the Actions on save feature to reformat the source code, optimize imports, rearrange it, run cleanup, or even upload it to a specified sever.
How to use:
Turn on the actions you want to perform on save in the Settings/Preferences | Tools | Actions on Save section of the IDE.
Cleanup Unused IDE Directories
If you stopped using an older version of the IDE, it's the right time to do some cleanup.
Whenever you upgrade your IDE to a new major version, it leaves behind all its configuration, caches, logs, and other directories so you can return to it any time you want. However, you might not want to keep those old caches or logs for too long, as they can slowly add up. Don't worry, the IDE will help you do all the cleanup.
The IDE will automatically clean up any cache and log directories that were last updated more than 180 days ago. To trigger this process manually, go to Help | Delete Leftover IDE Directories....
Note: The system settings and plugins directories will stay intact.
Search Text in Local History
Find exactly what you are looking for, even if you removed it
With the new Search field to the Local History dialog you quickly get to the necessary text in your revisions.
Invoke Local History on a file, then press the Find shortcut, ⌘F (macOS) / Ctrl+F (Windows/Linux).
Select the Builtin Terminal Cursor Shape
Make the terminal your own, with the cursor shape you want
Select the desired shape between Block, Underline, and Vertical under Settings/Preferences | Tools | Terminal | Cursor shape.
Select the Builtin Terminal Shell
Run multiple shells from the same UI with ease
Use the shell that you need in each Terminal tabs with only a few clicks.
Click on the ⋁ button next to the existing tabs and select which shell to use. You can also create a new SSH session from it, if you have any servers configured or configure a new one.
Create a Scratch File from Selection
Create scratches faster and get the contents you want to test pre-populated.
Select a portion of the code, press ⌘⌥⏎ (macOS) / Ctrl+Alt+Enter (Windows/Linux), then choose Create new scratch file from selection to quickly create a new scratch containing the same code.
Remove Empty Scratches Automatically
Let the IDE handle the cleanup after testing your ideas
Remove all the contents of a scratch file the close it. The IDE will automatically remove it.