gotools/gopls/internal/test/marker/testdata/codeaction/removeparam.txt

This test exercises the refactoring to remove unused parameters.
See removeparam_resolve.txt for same test with resolve support.

-- go.mod --
module unused.mod

go 1.18

-- a/a.go --
package a

func A(x, unused int) int { //@codeaction("unused", "unused", "refactor.rewrite.removeUnusedParam", a)
	return x
}

-- @a/a/a.go --
package a

func A(x int) int { //@codeaction("unused", "unused", "refactor.rewrite.removeUnusedParam", a)
	return x
}

-- a/a2.go --
package a

func _() {
	A(1, 2)
}

-- a/a_test.go --
package a

func _() {
	A(1, 2)
}

-- a/a_x_test.go --
package a_test

import "unused.mod/a"

func _() {
	a.A(1, 2)
}

-- b/b.go --
package b

import "unused.mod/a"

func f() int {
	return 1
}

func g() int {
	return 2
}

func _() {
	a.A(f(), 1)
}

-- @a/a/a2.go --
package a

func _() {
	A(1)
}
-- @a/a/a_test.go --
package a

func _() {
	A(1)
}
-- @a/a/a_x_test.go --
package a_test

import "unused.mod/a"

func _() {
	a.A(1)
}
-- @a/b/b.go --
package b

import "unused.mod/a"

func f() int {
	return 1
}

func g() int {
	return 2
}

func _() {
	a.A(f())
}
-- field/field.go --
package field

func Field(x int, field int) { //@codeaction("int", "int", "refactor.rewrite.removeUnusedParam", field)
}

func _() {
	Field(1, 2)
}
-- @field/field/field.go --
package field

func Field(field int) { //@codeaction("int", "int", "refactor.rewrite.removeUnusedParam", field)
}

func _() {
	Field(2)
}
-- ellipsis/ellipsis.go --
package ellipsis

func Ellipsis(...any) { //@codeaction("any", "any", "refactor.rewrite.removeUnusedParam", ellipsis)
}

func _() {
	// TODO(rfindley): investigate the broken formatting resulting from these inlinings.
	Ellipsis()
	Ellipsis(1)
	Ellipsis(1, 2)
	Ellipsis(1, f(), g())
	Ellipsis(h())
	Ellipsis(i()...)
}

func f() int
func g() int
func h() (int, int)
func i() []any

-- @ellipsis/ellipsis/ellipsis.go --
package ellipsis

func Ellipsis() { //@codeaction("any", "any", "refactor.rewrite.removeUnusedParam", ellipsis)
}

func _() {
	// TODO(rfindley): investigate the broken formatting resulting from these inlinings.
	Ellipsis()
	Ellipsis()
	Ellipsis()
	var _ []any = []any{1, f(), g()}
	Ellipsis()
	func(_ ...any) {
		Ellipsis()
	}(h())
	var _ []any = i()
	Ellipsis()
}

func f() int
func g() int
func h() (int, int)
func i() []any
-- ellipsis2/ellipsis2.go --
package ellipsis2

func Ellipsis2(_, _ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite.removeUnusedParam", ellipsis2)
}

func _() {
	Ellipsis2(1,2,3)
	Ellipsis2(h())
	Ellipsis2(1,2, []int{3, 4}...)
}

func h() (int, int)

-- @ellipsis2/ellipsis2/ellipsis2.go --
package ellipsis2

func Ellipsis2(_ int, rest ...int) { //@codeaction("_", "_", "refactor.rewrite.removeUnusedParam", ellipsis2)
}

func _() {
	Ellipsis2(2, []int{3}...)
	func(_, blank0 int, rest ...int) {
		Ellipsis2(blank0, rest...)
	}(h())
	Ellipsis2(2, []int{3, 4}...)
}

func h() (int, int)
-- overlapping/overlapping.go --
package overlapping

func Overlapping(i int) int { //@codeactionerr(re"(i) int", re"(i) int", "refactor.rewrite.removeUnusedParam", re"overlapping")
	return 0
}

func _() {
	x := Overlapping(Overlapping(0))
	_ = x
}

-- effects/effects.go --
package effects

func effects(x, y int) int { //@ diag("y", re"unused"), codeaction("y", "y", "refactor.rewrite.removeUnusedParam", effects)
	return x
}

func f() int
func g() int

func _() {
	effects(f(), g())
	effects(f(), g())
}
-- @effects/effects/effects.go --
package effects

func effects(x int) int { //@ diag("y", re"unused"), codeaction("y", "y", "refactor.rewrite.removeUnusedParam", effects)
	return x
}

func f() int
func g() int

func _() {
	var x, _ int = f(), g()
	effects(x)
	{
		var x, _ int = f(), g()
		effects(x)
	}
}
-- recursive/recursive.go --
package recursive

func Recursive(x int) int { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", recursive)
	return Recursive(1)
}

-- @recursive/recursive/recursive.go --
package recursive

func Recursive() int { //@codeaction("x", "x", "refactor.rewrite.removeUnusedParam", recursive)
	return Recursive()
}