Refactorings in GoLand: Rename refactoring

This is the last blog post in the series of refactorings so I wanted to save the most used refactoring the IDE has for last.

It’s one of the most powerful tools that I use and it works like magic every time. You might think that renaming things is pretty straightforward, but there are some lesser-known use cases which can really boost your productivity that I want to cover today.

But first, let’s start with this example code:

Let’s say that we want to rename the Position field to be a bit more explicit, like “JobTitle”.

We can press Shift+F6 and start renaming the field, press Enter when we are done, and that’s it.

Refactorings - Rename

However, if we change our example slightly to include a JSON string and try to call the refactoring again, then the IDE will suggest renaming the JSON field as well.

This is because the IDE understands that our string is of type string and can perform the Rename operation inside strings as well.

As with the other refactoring features, you can reject renaming the field at any time by selecting the usage you want to omit and pressing the Delete key.

If you press Shift + F6 twice, then you’ll get the following dialog which further allows you to configure where the rename operation takes place and how it should behave.

Refactorings - Rename 2

Since conflicts can appear during the rename operation, the IDE will also handle this for you and allow you to correct this before the code becomes polluted by an accidental naming collision.

Refactorings - Rename 3

This is not all. The rename operation is available across a wide range of languages and support tools as well.

For example, if we connect the IDE to a database, then it can also rename database fields directly from the query that we have.
We can see this in action in the example below:

Refactorings - Rename 4

To learn how to connect the IDE to a database, you can visit our documentation.

This concludes our short series on IDE refactoring tools. We went from changing function signatures to moving identifiers across files and even packages, to renaming them along with any other reference and even with database fields.

I hope you will find this series useful and it will increase your productivity whether you are just starting with Go, you are new to GoLand, or you are a more experienced user. In case you missed our previous posts, here’s the list of the previous topics in the series:

– Rename
Move & Copy
– Extract variable/constant
– Extract function/method
– Inline variable/constant
– Change Signature
Extract Interface (new in 2019.1)

Please let us know in the comments section below, on Twitter, or on our issue tracker your thoughts on this and what other topics we can handle in the future.

Feedback on the IDE itself is also welcome and we look forward to hearing from you on how to make your experience more enjoyable and productive.

About Florin Pățan

Developer Advocate at JetBrains
This entry was posted in Features, Tutorial and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *