Test move declaration refactoring: extracting declarations to the destination file.

-- capabilities.json --
{
	"experimental":{"interactiveResolve":{"inputTypes":["string"]}}
}

-- settings.json --
{
	"moveDeclaration": true
}

-- flags --
-ignore_extra_diags

-- go.mod --
module golang.org/lsptests/movedecledits

go 1.20

-- src/func.go --
package src

func Add(a, b int) int { //@codeaction(re"Add", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_func)
	return a + b
}

-- @move_func/src/func.go --
package src



-- src/type.go --
package src

type Point struct { //@codeaction(re"Point", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_type)
	X int
	Y int
}

-- @move_type/src/type.go --
package src



-- src/newfile.go --
package src

// Cross-package move to a new file: dest/newfile.go does not exist yet and must be created.
func Multiply(x, y int) int { //@codeaction(re"Multiply", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/newfile.go"}`, result=move_new_file)
	return x * y
}

-- @move_new_file/src/newfile.go --
package src

// Cross-package move to a new file: dest/newfile.go does not exist yet and must be created.


-- src/samepkg_new.go --
package src

// Same-package move to a new file: src/created.go does not exist yet and must be created.
func Separate() string { //@codeaction(re"Separate", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/src/created.go"}`, result=move_samepkg_new_file)
	return "same package new file"
}

-- @move_samepkg_new_file/src/samepkg_new.go --
package src

// Same-package move to a new file: src/created.go does not exist yet and must be created.


-- src/header.go --
// Copyright 2026 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.20

package src

func WithHeader() string { //@codeaction(re"WithHeader", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/src/header_created.go"}`, result=move_samepkg_header)
	return "header"
}


-- @move_samepkg_header/src/header.go --
// Copyright 2026 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.20

package src




-- src/spec.go --
package src

type (
	First int
	Second string //@codeaction(re"Second", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_subset_spec)
)

-- @move_subset_spec/src/spec.go --
package src

type (
	First int
	 //@codeaction(re"Second", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_subset_spec)
)

-- src/counter.go --
package src

type Counter struct { //@codeaction(re"Counter", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_decl_with_method)
	Count int
}

func (c *Counter) Inc() {
	c.Count++
}

-- @move_decl_with_method/src/counter.go --
package src





-- src/iota.go --
package src

const (
	Zero = iota
	One
	Two
)

-- src/helper.go --
package src

func HelperForTest() int { //@codeaction(re"HelperForTest", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/src/helper_test.go"}`, result=move_to_test_file)
	return 42
}

-- @move_to_test_file/src/helper.go --
package src



-- src/helper_test.go --
package src

import "testing"

func TestExisting(t *testing.T) {}

-- src/spec_group.go --
package src

// Moving Mover also moves its dependency mover: two of the four specs move.
var (
	Stay     = 1
	Mover    = mover //@codeaction(re"Mover", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_spec_subset_multi)
	mover    = 2
	AlsoStay = 3
)

-- @move_spec_subset_multi/dest/dest.go --
package dest

func Existing() {}

var Mover    = mover

var mover    = 2
-- @move_spec_subset_multi/src/spec_group.go --
package src

// Moving Mover also moves its dependency mover: two of the four specs move.
var (
	Stay     = 1
	 //@codeaction(re"Mover", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_spec_subset_multi)
	
	AlsoStay = 3
)

-- src/whole_group.go --
package src

// Moving Whole also moves whole, so every spec in the group moves.
var (
	Whole = whole //@codeaction(re"Whole", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_whole_gendecl)
	whole = 1
)

-- @move_whole_gendecl/dest/dest.go --
package dest

func Existing() {}

var (
	Whole = whole //@codeaction(re"Whole", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_whole_gendecl)
	whole = 1
)
-- @move_whole_gendecl/src/whole_group.go --
package src

// Moving Whole also moves whole, so every spec in the group moves.


-- src/middle.go --
package src

// Only Middle is removed; its neighbors stay.
func Above() {}

func Middle() { //@codeaction(re"Middle", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_remove_middle)
}

func Below() {}

-- @move_remove_middle/dest/dest.go --
package dest

func Existing() {}

func Middle() { //@codeaction(re"Middle", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_remove_middle)
}
-- @move_remove_middle/src/middle.go --
package src

// Only Middle is removed; its neighbors stay.
func Above() {}



func Below() {}

-- src/split_type.go --
package src

// Split's method is in another file; both are removed from their own files.
type Split struct { //@codeaction(re"Split", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_remove_split)
}

-- @move_remove_split/dest/dest.go --
package dest

func Existing() {}

func (s Split) Method() {}

type Split struct { //@codeaction(re"Split", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_remove_split)
}
-- @move_remove_split/src/split_methods.go --
package src



func KeepMe() {}

-- @move_remove_split/src/split_type.go --
package src

// Split's method is in another file; both are removed from their own files.


-- src/split_methods.go --
package src

func (s Split) Method() {}

func KeepMe() {}

-- dest/dest.go --
package dest

func Existing() {}

-- @move_to_test_file/src/helper_test.go --
package src

import "testing"

func TestExisting(t *testing.T) {}

func HelperForTest() int { //@codeaction(re"HelperForTest", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/src/helper_test.go"}`, result=move_to_test_file)
	return 42
}
-- @move_func/dest/dest.go --
package dest

func Existing() {}

func Add(a, b int) int { //@codeaction(re"Add", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_func)
	return a + b
}
-- @move_type/dest/dest.go --
package dest

func Existing() {}

type Point struct { //@codeaction(re"Point", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_type)
	X int
	Y int
}
-- @move_new_file/dest/newfile.go --
package dest

func Multiply(x, y int) int { //@codeaction(re"Multiply", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/newfile.go"}`, result=move_new_file)
	return x * y
}
-- @move_samepkg_new_file/src/created.go --
package src

func Separate() string { //@codeaction(re"Separate", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/src/created.go"}`, result=move_samepkg_new_file)
	return "same package new file"
}
-- @move_samepkg_header/src/header_created.go --
// Copyright 2026 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.20

package src

func WithHeader() string { //@codeaction(re"WithHeader", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/src/header_created.go"}`, result=move_samepkg_header)
	return "header"
}
-- @move_subset_spec/dest/dest.go --
package dest

func Existing() {}

type Second string
-- @move_decl_with_method/dest/dest.go --
package dest

func Existing() {}

type Counter struct { //@codeaction(re"Counter", "refactor.move.moveDeclaration", answers=`{"file":"file://$WORKDIR/dest/dest.go"}`, result=move_decl_with_method)
	Count int
}

func (c *Counter) Inc() {
	c.Count++
}
