GoLand 2024.1 Help

Rename refactorings

Use the Rename refactoring to change names of symbols, files, and all the references to them throughout code.

Renaming local variables or private methods can be done easily inline since only the limited scope is affected. Renaming types, interfaces, or public methods could potentially impact a lot of files. Preview potential changes before you refactor.

Rename code in place

  1. In the editor start renaming a parameter, a method, or other code element. GoLand will display the Rename the usages of icon in the gutter.

  2. Click the gutter icon or press Alt+Enter and apply a suggestion.

    Rename inline

    GoLand renames the code element and updates its usages accordingly.

    Rename refactoring result

Rename a code element

  1. In the editor, select the element you want to rename. If you need to rename a file, select one in the Project tool window.

  2. Press Shift+F6 or go to Refactor | Rename in the main menu.

    When you invoke the rename Shift+F6 action, GoLand displays the Rename in comments and strings icon and the Rename in text occurrences icon next to the highlighted element.

    Rename variable

    You can press Tab to open the context menu and select the additional rename options.

    Additional Rename options

    If you want to see the Rename dialog with more options, click the More options link or press Shift+F6.

  3. You can perform the rename refactoring in-place or press Shift+F6 again to open the Rename dialog. Enter a new name of the element to enable the Preview and Refactor buttons.

    The Rename dialog

    You can specify additional options. For example, specify where to search for element occurrences, or what else to rename. You can also specify a scope for the refactoring.

  4. In the Refactoring Preview dialog, review potential changes and click Do Refactor.

The refactoring dialog

Next time you invoke the Rename refactoring, GoLand remembers the options you have specified inside the Rename dialog.

Rename methods in interfaces

You can rename methods that are declared in interfaces. When you rename the method, GoLand displays a context menu where you can select to rename method implementations as well.

  1. Right-click a method in an interface and select Refactor | Rename. Alternatively, place the caret at the method in the interface and press Shift+F6.

  2. In context menu select what you want to rename. To rename the method and all implementations, select Refactor method specification and all implementations. Otherwise, to refactor only selected method, select Refactor only current method.

  3. In the Change Signature dialog, change the method name in the Name field.

  4. Click Refactor.

    To preview your changes before refactoring, click Preview.

Rename methods in interfaces

Rename Go modules names

  1. Click the module name and navigate to Refactor | Rename. Alternatively, press Shift+F6.

  2. In the Rename dialog, configure the renaming options and click Refactor. Alternatively, click Preview to check all the usages of the module name in the project.

    Rename Go modules names
Last modified: 26 May 2024