Using the move refactoring
With the move refactoring, you can take any top-level named identifier from your code and move it either to a separate file or to a different package.
For example purposes, clone the Delve project from Github: git clone https://github.com/derekparker/delve
. For more information about Git, read the official Git documentation.
Move a function declaration to a new file
Open the Delve project in GoLand.
Navigate to
.Right-click the
SplitQuotedFields
function declaration and select . Alternatively, press F6.In the To file field, type
newsplit
.Click Refactor. The newsplit.go file is created with the function that we moved. The move refactoring does not only move declarations, but also adds the required imports, updates the references to the identifier, and performs a cleanup of the previous definition place of the identifier so that your code can still work.
Preview changes before the refactoring
Open the Delve project in GoLand.
Navigate to
.Right-click the
GoVersion
type and select . Alternatively, press F6.Specify a file path and a file name. For example, add
/gover
to the file path in the To directory field, and typegover
in the To file field.Select
AfterOrEqual
andIsDevel
identifiers for theGoVersion
type. GoLand displays a notification when the identifier is private and is not exported during the move operation.Click Preview. In the Find tool window, you can review refactoring changes and exclude Delete or remove Control+X code parts from the refactoring process.