# Move construct relocates a function within a file with comments intact. exec semedit refactor-move-declaration --file api/server.go --symbol Run --placement before_symbol --target-symbol Init stdout 'Successfully moved construct' cmp api/server.go .scratch/_want/api/server.go # A self-anchor still resolves the symbol before returning success. exec semedit refactor-move-declaration --file api/server.go --symbol Init --placement before_symbol --target-symbol Init ! exec semedit refactor-move-declaration --file api/server.go --symbol Missing --placement before_symbol --target-symbol Missing stderr 'symbol.*not found' cmp api/server.go .scratch/_want/api/server.go # Move a function between files in the same package and carry its required import. exec semedit refactor-move-declaration --file api/source.go --destination-file api/dest.go --symbol Normalize --placement file_end cmp api/source.go .scratch/_want/api/source.go cmp api/dest.go .scratch/_want/api/dest.go stdout 'import' # Resolve an implicit import name from the package instead of guessing from its path. exec semedit refactor-move-declaration --file api/alias_source.go --destination-file api/alias_dest.go --symbol UseNamed --placement file_end cmp api/alias_source.go .scratch/_want/api/alias_source.go cmp api/alias_dest.go .scratch/_want/api/alias_dest.go # Move an exported function across packages and update callers in the source and third packages. exec semedit refactor-move-declaration --file other/source.go --destination-file api/cross.go --symbol MoveMe --placement file_end stdout 'Successfully moved construct' cmp other/source.go .scratch/_want/other/source.go cmp api/cross.go .scratch/_want/api/cross.go cmp callers/use.go .scratch/_want/callers/use.go # A selected member of an iota group fails without moving its siblings or changing values. ! exec semedit refactor-move-declaration --file api/group.go --destination-file api/dest.go --symbol First --placement file_end stderr 'grouped constant with implicit expressions or iota' cmp api/group.go .scratch/_want/api/group.go # A single literal variable spec moves with its documentation while the sibling remains. exec semedit refactor-move-declaration --file api/group_var.go --destination-file api/group_var_dest.go --symbol GroupedB --placement before_symbol --target-symbol KeepGroupedVar cmp api/group_var.go .scratch/_want/api/group_var.go cmp api/group_var_dest.go .scratch/_want/api/group_var_dest.go # A grouped type member moves with its documentation, and the sibling remains unchanged. exec semedit refactor-move-declaration --file api/group_type.go --destination-file api/group_type_dest.go --symbol MoveType --placement before_symbol --target-symbol KeepGroupType cmp api/group_type.go .scratch/_want/api/group_type.go cmp api/group_type_dest.go .scratch/_want/api/group_type_dest.go exec go test ./... -- go.mod -- module example.com/move go 1.23 -- api/server.go -- package api // Init initializes the server. func Init() {} // Run starts the server execution. func Run() {} -- .scratch/_want/api/server.go -- package api // Run starts the server execution. func Run() {} // Init initializes the server. func Init() {} -- api/source.go -- package api import "strings" func Normalize(value string) string { return strings.TrimSpace(value) } -- api/dest.go -- package api func Existing() {} -- .scratch/_want/api/source.go -- package api -- .scratch/_want/api/dest.go -- package api import ( "strings" ) func Existing() {} func Normalize(value string) string { return strings.TrimSpace(value) } -- other/source.go -- package other import "strings" // MoveMe trims its input. func MoveMe(value string) string { return strings.TrimSpace(value) } func UseLocal() string { return MoveMe(" local ") } -- .scratch/_want/other/source.go -- package other import "example.com/move/api" func UseLocal() string { return api.MoveMe(" local ") } -- api/cross.go -- package api import "example.com/move/other" func ExistingCross() string { return other.MoveMe(" API ") } -- pkgdir/named.go -- package actualname func Value() string { return "ok" } -- api/alias_source.go -- package api import "example.com/move/pkgdir" func UseNamed() string { return actualname.Value() } -- .scratch/_want/api/alias_source.go -- package api -- api/alias_dest.go -- package api -- .scratch/_want/api/alias_dest.go -- package api import ( actualname "example.com/move/pkgdir" ) func UseNamed() string { return actualname.Value() } -- .scratch/_want/api/cross.go -- package api import ( "strings" ) func ExistingCross() string { return MoveMe(" API ") } // MoveMe trims its input. func MoveMe(value string) string { return strings.TrimSpace(value) } -- callers/use.go -- package callers import "example.com/move/other" func Call() string { return other.MoveMe(" x ") } -- .scratch/_want/callers/use.go -- package callers import "example.com/move/api" func Call() string { return api.MoveMe(" x ") } -- other/unrelated_linux.go -- //go:build linux package other func Unrelated() {} -- api/group.go -- package api const ( First = iota Second ) -- .scratch/_want/api/group.go -- package api const ( First = iota Second ) -- api/group_var.go -- package api var ( // GroupedA remains with its original declaration. GroupedA = 1 // GroupedB moves with this documentation. GroupedB = 2 ) -- api/group_var_dest.go -- package api func KeepGroupedVar() {} -- api/group_type.go -- package api type ( // KeepType remains in the source file. KeepType struct{} // MoveType travels with its declaration. MoveType struct{} ) -- api/group_type_dest.go -- package api type GroupTypeDestinationExisting struct{} func KeepGroupType() {} -- .scratch/_want/api/group_type.go -- package api type ( // KeepType remains in the source file. KeepType struct{} ) -- .scratch/_want/api/group_type_dest.go -- package api type GroupTypeDestinationExisting struct{} // MoveType travels with its declaration. type MoveType struct{} func KeepGroupType() {} -- .scratch/_want/api/group_var.go -- package api var ( // GroupedA remains with its original declaration. GroupedA = 1 ) -- .scratch/_want/api/group_var_dest.go -- package api // GroupedB moves with this documentation. var GroupedB = 2 func KeepGroupedVar() {}