| 1 |
This test exercises the refactoring to remove unused parameters. |
| 2 |
See removeparam_resolve.txt for same test with resolve support. |
| 3 |
|
| 4 |
-- capabilities.json -- |
| 5 |
{ |
| 6 |
"textDocument": { |
| 7 |
"codeAction": { |
| 8 |
"dataSupport": false, |
| 9 |
"resolveSupport": {} |
| 10 |
} |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
-- go.mod -- |
| 15 |
module unused.mod |
| 16 |
|
| 17 |
go 1.18 |
| 18 |
|
| 19 |
-- a/a.go -- |
| 20 |
package a |
| 21 |
|
| 22 |
func A(x, unused int) int { //@codeaction("unused", "refactor.rewrite.removeUnusedParam", result=a) |
| 23 |
return x |
| 24 |
} |
| 25 |
|
| 26 |
-- @a/a/a.go -- |
| 27 |
package a |
| 28 |
|
| 29 |
func A(x int) int { //@codeaction("unused", "refactor.rewrite.removeUnusedParam", result=a) |
| 30 |
return x |
| 31 |
} |
| 32 |
|
| 33 |
-- a/a2.go -- |
| 34 |
package a |
| 35 |
|
| 36 |
func _() { |
| 37 |
A(1, 2) |
| 38 |
} |
| 39 |
|
| 40 |
-- a/a_test.go -- |
| 41 |
package a |
| 42 |
|
| 43 |
func _() { |
| 44 |
A(1, 2) |
| 45 |
} |
| 46 |
|
| 47 |
-- a/a_x_test.go -- |
| 48 |
package a_test |
| 49 |
|
| 50 |
import "unused.mod/a" |
| 51 |
|
| 52 |
func _() { |
| 53 |
a.A(1, 2) |
| 54 |
} |
| 55 |
|
| 56 |
-- b/b.go -- |
| 57 |
package b |
| 58 |
|
| 59 |
import "unused.mod/a" |
| 60 |
|
| 61 |
func f() int { |
| 62 |
return 1 |
| 63 |
} |
| 64 |
|
| 65 |
func g() int { |
| 66 |
return 2 |
| 67 |
} |
| 68 |
|
| 69 |
func _() { |
| 70 |
a.A(f(), 1) |
| 71 |
} |
| 72 |
|
| 73 |
var _ = g |
| 74 |
|
| 75 |
-- @a/a/a2.go -- |
| 76 |
package a |
| 77 |
|
| 78 |
func _() { |
| 79 |
A(1) |
| 80 |
} |
| 81 |
-- @a/a/a_test.go -- |
| 82 |
package a |
| 83 |
|
| 84 |
func _() { |
| 85 |
A(1) |
| 86 |
} |
| 87 |
-- @a/a/a_x_test.go -- |
| 88 |
package a_test |
| 89 |
|
| 90 |
import "unused.mod/a" |
| 91 |
|
| 92 |
func _() { |
| 93 |
a.A(1) |
| 94 |
} |
| 95 |
-- @a/b/b.go -- |
| 96 |
package b |
| 97 |
|
| 98 |
import "unused.mod/a" |
| 99 |
|
| 100 |
func f() int { |
| 101 |
return 1 |
| 102 |
} |
| 103 |
|
| 104 |
func g() int { |
| 105 |
return 2 |
| 106 |
} |
| 107 |
|
| 108 |
func _() { |
| 109 |
a.A(f()) |
| 110 |
} |
| 111 |
|
| 112 |
var _ = g |
| 113 |
-- field/field.go -- |
| 114 |
package field |
| 115 |
|
| 116 |
func Field(x int, field int) { //@codeaction("int", "refactor.rewrite.removeUnusedParam", result=field) |
| 117 |
} |
| 118 |
|
| 119 |
func _() { |
| 120 |
Field(1, 2) |
| 121 |
} |
| 122 |
-- @field/field/field.go -- |
| 123 |
package field |
| 124 |
|
| 125 |
func Field(field int) { //@codeaction("int", "refactor.rewrite.removeUnusedParam", result=field) |
| 126 |
} |
| 127 |
|
| 128 |
func _() { |
| 129 |
Field(2) |
| 130 |
} |
| 131 |
-- ellipsis/ellipsis.go -- |
| 132 |
package ellipsis |
| 133 |
|
| 134 |
func Ellipsis(...any) { //@codeaction("any", "refactor.rewrite.removeUnusedParam", result=ellipsis) |
| 135 |
} |
| 136 |
|
| 137 |
func _() { |
| 138 |
// TODO(rfindley): investigate the broken formatting resulting from these inlinings. |
| 139 |
Ellipsis() |
| 140 |
Ellipsis(1) |
| 141 |
Ellipsis(1, 2) |
| 142 |
Ellipsis(1, f(), g()) |
| 143 |
Ellipsis(h()) |
| 144 |
Ellipsis(i()...) |
| 145 |
} |
| 146 |
|
| 147 |
func f() int |
| 148 |
func g() int |
| 149 |
func h() (int, int) |
| 150 |
func i() []any |
| 151 |
|
| 152 |
-- @ellipsis/ellipsis/ellipsis.go -- |
| 153 |
package ellipsis |
| 154 |
|
| 155 |
func Ellipsis() { //@codeaction("any", "refactor.rewrite.removeUnusedParam", result=ellipsis) |
| 156 |
} |
| 157 |
|
| 158 |
func _() { |
| 159 |
// TODO(rfindley): investigate the broken formatting resulting from these inlinings. |
| 160 |
Ellipsis() |
| 161 |
Ellipsis() |
| 162 |
Ellipsis() |
| 163 |
Ellipsis() |
| 164 |
func(_ ...any) { |
| 165 |
Ellipsis() |
| 166 |
}(h()) |
| 167 |
Ellipsis() |
| 168 |
} |
| 169 |
|
| 170 |
func f() int |
| 171 |
func g() int |
| 172 |
func h() (int, int) |
| 173 |
func i() []any |
| 174 |
-- ellipsis2/ellipsis2.go -- |
| 175 |
package ellipsis2 |
| 176 |
|
| 177 |
func Ellipsis2(_, _ int, rest ...int) { //@codeaction("_", "refactor.rewrite.removeUnusedParam", result=ellipsis2) |
| 178 |
} |
| 179 |
|
| 180 |
func _() { |
| 181 |
Ellipsis2(1,2,3) |
| 182 |
Ellipsis2(h()) |
| 183 |
Ellipsis2(1,2, []int{3, 4}...) |
| 184 |
} |
| 185 |
|
| 186 |
func h() (int, int) |
| 187 |
|
| 188 |
-- @ellipsis2/ellipsis2/ellipsis2.go -- |
| 189 |
package ellipsis2 |
| 190 |
|
| 191 |
func Ellipsis2(_ int, rest ...int) { //@codeaction("_", "refactor.rewrite.removeUnusedParam", result=ellipsis2) |
| 192 |
} |
| 193 |
|
| 194 |
func _() { |
| 195 |
Ellipsis2(2, 3) |
| 196 |
func(_, blank0 int, rest ...int) { |
| 197 |
Ellipsis2(blank0, rest...) |
| 198 |
}(h()) |
| 199 |
Ellipsis2(2, []int{3, 4}...) |
| 200 |
} |
| 201 |
|
| 202 |
func h() (int, int) |
| 203 |
-- overlapping/overlapping.go -- |
| 204 |
package overlapping |
| 205 |
|
| 206 |
func Overlapping(i int) int { //@codeaction(re"(i) int", "refactor.rewrite.removeUnusedParam", err=re"overlapping") |
| 207 |
return 0 |
| 208 |
} |
| 209 |
|
| 210 |
func _() { |
| 211 |
x := Overlapping(Overlapping(0)) |
| 212 |
_ = x |
| 213 |
} |
| 214 |
|
| 215 |
-- effects/effects.go -- |
| 216 |
package effects |
| 217 |
|
| 218 |
func effects(x, y int) int { //@ diag("y", re"unused"), codeaction("y", "refactor.rewrite.removeUnusedParam", result=effects) |
| 219 |
return x |
| 220 |
} |
| 221 |
|
| 222 |
func f() int |
| 223 |
func g() int |
| 224 |
|
| 225 |
func _() { |
| 226 |
effects(f(), g()) |
| 227 |
effects(f(), g()) |
| 228 |
} |
| 229 |
-- @effects/effects/effects.go -- |
| 230 |
package effects |
| 231 |
|
| 232 |
func effects(x int) int { //@ diag("y", re"unused"), codeaction("y", "refactor.rewrite.removeUnusedParam", result=effects) |
| 233 |
return x |
| 234 |
} |
| 235 |
|
| 236 |
func f() int |
| 237 |
func g() int |
| 238 |
|
| 239 |
func _() { |
| 240 |
effects(f()) |
| 241 |
effects(f()) |
| 242 |
} |
| 243 |
-- recursive/recursive.go -- |
| 244 |
package recursive |
| 245 |
|
| 246 |
func Recursive(x int) int { //@codeaction("x", "refactor.rewrite.removeUnusedParam", result=recursive) |
| 247 |
return Recursive(1) |
| 248 |
} |
| 249 |
|
| 250 |
-- @recursive/recursive/recursive.go -- |
| 251 |
package recursive |
| 252 |
|
| 253 |
func Recursive() int { //@codeaction("x", "refactor.rewrite.removeUnusedParam", result=recursive) |
| 254 |
return Recursive() |
| 255 |
} |