| 1 |
This test checks the behavior of the 'fill struct' code action. |
| 2 |
See fill_struct_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 |
-- flags -- |
| 15 |
-ignore_extra_diags |
| 16 |
|
| 17 |
-- go.mod -- |
| 18 |
module golang.org/lsptests/fillstruct |
| 19 |
|
| 20 |
go 1.18 |
| 21 |
|
| 22 |
-- data/data.go -- |
| 23 |
package data |
| 24 |
|
| 25 |
type B struct { |
| 26 |
ExportedInt int |
| 27 |
unexportedInt int |
| 28 |
} |
| 29 |
|
| 30 |
-- a.go -- |
| 31 |
package fillstruct |
| 32 |
|
| 33 |
import ( |
| 34 |
"golang.org/lsptests/fillstruct/data" |
| 35 |
) |
| 36 |
|
| 37 |
type basicStruct struct { |
| 38 |
foo int |
| 39 |
} |
| 40 |
|
| 41 |
var _ = basicStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a1) |
| 42 |
|
| 43 |
type twoArgStruct struct { |
| 44 |
foo int |
| 45 |
bar string |
| 46 |
} |
| 47 |
|
| 48 |
var _ = twoArgStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a2) |
| 49 |
|
| 50 |
type nestedStruct struct { |
| 51 |
bar string |
| 52 |
basic basicStruct |
| 53 |
} |
| 54 |
|
| 55 |
var _ = nestedStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a3) |
| 56 |
|
| 57 |
var _ = data.B{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a4) |
| 58 |
-- @a1/a.go -- |
| 59 |
@@ -11 +11,3 @@ |
| 60 |
-var _ = basicStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a1) |
| 61 |
+var _ = basicStruct{ |
| 62 |
+ foo: 0, |
| 63 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a1) |
| 64 |
-- @a2/a.go -- |
| 65 |
@@ -18 +18,4 @@ |
| 66 |
-var _ = twoArgStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a2) |
| 67 |
+var _ = twoArgStruct{ |
| 68 |
+ foo: 0, |
| 69 |
+ bar: "", |
| 70 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a2) |
| 71 |
-- @a3/a.go -- |
| 72 |
@@ -25 +25,4 @@ |
| 73 |
-var _ = nestedStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a3) |
| 74 |
+var _ = nestedStruct{ |
| 75 |
+ bar: "", |
| 76 |
+ basic: basicStruct{}, |
| 77 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a3) |
| 78 |
-- @a4/a.go -- |
| 79 |
@@ -27 +27,3 @@ |
| 80 |
-var _ = data.B{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a4) |
| 81 |
+var _ = data.B{ |
| 82 |
+ ExportedInt: 0, |
| 83 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a4) |
| 84 |
-- a2.go -- |
| 85 |
package fillstruct |
| 86 |
|
| 87 |
type typedStruct struct { |
| 88 |
m map[string]int |
| 89 |
s []int |
| 90 |
c chan int |
| 91 |
c1 <-chan int |
| 92 |
a [2]string |
| 93 |
} |
| 94 |
|
| 95 |
var _ = typedStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a21) |
| 96 |
|
| 97 |
type funStruct struct { |
| 98 |
fn func(i int) int |
| 99 |
} |
| 100 |
|
| 101 |
var _ = funStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a22) |
| 102 |
|
| 103 |
type funStructComplex struct { |
| 104 |
fn func(i int, s string) (string, int) |
| 105 |
} |
| 106 |
|
| 107 |
var _ = funStructComplex{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a23) |
| 108 |
|
| 109 |
type funStructEmpty struct { |
| 110 |
fn func() |
| 111 |
} |
| 112 |
|
| 113 |
var _ = funStructEmpty{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a24) |
| 114 |
|
| 115 |
-- @a21/a2.go -- |
| 116 |
@@ -11 +11,7 @@ |
| 117 |
-var _ = typedStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a21) |
| 118 |
+var _ = typedStruct{ |
| 119 |
+ m: map[string]int{}, |
| 120 |
+ s: []int{}, |
| 121 |
+ c: make(chan int), |
| 122 |
+ c1: make(<-chan int), |
| 123 |
+ a: [2]string{}, |
| 124 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a21) |
| 125 |
-- @a22/a2.go -- |
| 126 |
@@ -17 +17,5 @@ |
| 127 |
-var _ = funStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a22) |
| 128 |
+var _ = funStruct{ |
| 129 |
+ fn: func(i int) int { |
| 130 |
+ panic("TODO") |
| 131 |
+ }, |
| 132 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a22) |
| 133 |
-- @a23/a2.go -- |
| 134 |
@@ -23 +23,5 @@ |
| 135 |
-var _ = funStructComplex{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a23) |
| 136 |
+var _ = funStructComplex{ |
| 137 |
+ fn: func(i int, s string) (string, int) { |
| 138 |
+ panic("TODO") |
| 139 |
+ }, |
| 140 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a23) |
| 141 |
-- @a24/a2.go -- |
| 142 |
@@ -29 +29,5 @@ |
| 143 |
-var _ = funStructEmpty{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a24) |
| 144 |
+var _ = funStructEmpty{ |
| 145 |
+ fn: func() { |
| 146 |
+ panic("TODO") |
| 147 |
+ }, |
| 148 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a24) |
| 149 |
-- a3.go -- |
| 150 |
package fillstruct |
| 151 |
|
| 152 |
import ( |
| 153 |
"go/ast" |
| 154 |
"go/token" |
| 155 |
) |
| 156 |
|
| 157 |
type Foo struct { |
| 158 |
A int |
| 159 |
} |
| 160 |
|
| 161 |
type Bar struct { |
| 162 |
X *Foo |
| 163 |
Y *Foo |
| 164 |
} |
| 165 |
|
| 166 |
var _ = Bar{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a31) |
| 167 |
|
| 168 |
type importedStruct struct { |
| 169 |
m map[*ast.CompositeLit]ast.Field |
| 170 |
s []ast.BadExpr |
| 171 |
a [3]token.Token |
| 172 |
c chan ast.EmptyStmt |
| 173 |
fn func(ast_decl ast.DeclStmt) ast.Ellipsis |
| 174 |
st ast.CompositeLit |
| 175 |
} |
| 176 |
|
| 177 |
var _ = importedStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a32) |
| 178 |
|
| 179 |
type pointerBuiltinStruct struct { |
| 180 |
b *bool |
| 181 |
s *string |
| 182 |
i *int |
| 183 |
} |
| 184 |
|
| 185 |
var _ = pointerBuiltinStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a33) |
| 186 |
|
| 187 |
var _ = []ast.UnaryExpr{ |
| 188 |
{}, //@codeaction("}", "refactor.rewrite.fillStruct", edit=a34) |
| 189 |
} |
| 190 |
|
| 191 |
var _ = []ast.UnaryExpr{{}} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a35) |
| 192 |
-- @a31/a3.go -- |
| 193 |
@@ -17 +17,4 @@ |
| 194 |
-var _ = Bar{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a31) |
| 195 |
+var _ = Bar{ |
| 196 |
+ X: &Foo{}, |
| 197 |
+ Y: &Foo{}, |
| 198 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a31) |
| 199 |
-- @a32/a3.go -- |
| 200 |
@@ -28 +28,10 @@ |
| 201 |
-var _ = importedStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a32) |
| 202 |
+var _ = importedStruct{ |
| 203 |
+ m: map[*ast.CompositeLit]ast.Field{}, |
| 204 |
+ s: []ast.BadExpr{}, |
| 205 |
+ a: [3]token.Token{}, |
| 206 |
+ c: make(chan ast.EmptyStmt), |
| 207 |
+ fn: func(ast_decl ast.DeclStmt) ast.Ellipsis { |
| 208 |
+ panic("TODO") |
| 209 |
+ }, |
| 210 |
+ st: ast.CompositeLit{}, |
| 211 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a32) |
| 212 |
-- @a33/a3.go -- |
| 213 |
@@ -36 +36,5 @@ |
| 214 |
-var _ = pointerBuiltinStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a33) |
| 215 |
+var _ = pointerBuiltinStruct{ |
| 216 |
+ b: new(bool), |
| 217 |
+ s: new(string), |
| 218 |
+ i: new(int), |
| 219 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a33) |
| 220 |
-- @a34/a3.go -- |
| 221 |
@@ -39 +39,5 @@ |
| 222 |
- {}, //@codeaction("}", "refactor.rewrite.fillStruct", edit=a34) |
| 223 |
+ { |
| 224 |
+ OpPos: 0, |
| 225 |
+ Op: 0, |
| 226 |
+ X: nil, |
| 227 |
+ }, //@codeaction("}", "refactor.rewrite.fillStruct", edit=a34) |
| 228 |
-- @a35/a3.go -- |
| 229 |
@@ -42 +42,5 @@ |
| 230 |
-var _ = []ast.UnaryExpr{{}} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a35) |
| 231 |
+var _ = []ast.UnaryExpr{{ |
| 232 |
+ OpPos: 0, |
| 233 |
+ Op: 0, |
| 234 |
+ X: nil, |
| 235 |
+}} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a35) |
| 236 |
-- a4.go -- |
| 237 |
package fillstruct |
| 238 |
|
| 239 |
import "go/ast" |
| 240 |
|
| 241 |
type iStruct struct { |
| 242 |
X int |
| 243 |
} |
| 244 |
|
| 245 |
type sStruct struct { |
| 246 |
str string |
| 247 |
} |
| 248 |
|
| 249 |
type multiFill struct { |
| 250 |
num int |
| 251 |
strin string |
| 252 |
arr []int |
| 253 |
} |
| 254 |
|
| 255 |
type assignStruct struct { |
| 256 |
n ast.Node |
| 257 |
} |
| 258 |
|
| 259 |
func fill() { |
| 260 |
var x int |
| 261 |
var _ = iStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a41) |
| 262 |
|
| 263 |
var s string |
| 264 |
var _ = sStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a42) |
| 265 |
|
| 266 |
var n int |
| 267 |
_ = []int{} |
| 268 |
if true { |
| 269 |
arr := []int{1, 2} |
| 270 |
} |
| 271 |
var _ = multiFill{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a43) |
| 272 |
|
| 273 |
var node *ast.CompositeLit |
| 274 |
var _ = assignStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a45) |
| 275 |
} |
| 276 |
|
| 277 |
-- @a41/a4.go -- |
| 278 |
@@ -25 +25,3 @@ |
| 279 |
- var _ = iStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a41) |
| 280 |
+ var _ = iStruct{ |
| 281 |
+ X: x, |
| 282 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=a41) |
| 283 |
-- @a42/a4.go -- |
| 284 |
@@ -28 +28,3 @@ |
| 285 |
- var _ = sStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a42) |
| 286 |
+ var _ = sStruct{ |
| 287 |
+ str: s, |
| 288 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=a42) |
| 289 |
-- @a43/a4.go -- |
| 290 |
@@ -35 +35,5 @@ |
| 291 |
- var _ = multiFill{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a43) |
| 292 |
+ var _ = multiFill{ |
| 293 |
+ num: n, |
| 294 |
+ strin: s, |
| 295 |
+ arr: []int{}, |
| 296 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=a43) |
| 297 |
-- @a45/a4.go -- |
| 298 |
@@ -38 +38,3 @@ |
| 299 |
- var _ = assignStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=a45) |
| 300 |
+ var _ = assignStruct{ |
| 301 |
+ n: node, |
| 302 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=a45) |
| 303 |
-- fillStruct.go -- |
| 304 |
package fillstruct |
| 305 |
|
| 306 |
type StructB struct{} |
| 307 |
|
| 308 |
type StructA struct { |
| 309 |
unexportedIntField int |
| 310 |
ExportedIntField int |
| 311 |
MapA map[int]string |
| 312 |
Array []int |
| 313 |
StructB |
| 314 |
} |
| 315 |
|
| 316 |
type StructA2 struct { |
| 317 |
B *StructB |
| 318 |
} |
| 319 |
|
| 320 |
type StructA3 struct { |
| 321 |
B StructB |
| 322 |
} |
| 323 |
|
| 324 |
func fill() { |
| 325 |
a := StructA{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct1) |
| 326 |
b := StructA2{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct2) |
| 327 |
c := StructA3{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct3) |
| 328 |
if true { |
| 329 |
_ = StructA3{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct4) |
| 330 |
} |
| 331 |
} |
| 332 |
|
| 333 |
-- @fillStruct1/fillStruct.go -- |
| 334 |
@@ -22 +22,7 @@ |
| 335 |
- a := StructA{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct1) |
| 336 |
+ a := StructA{ |
| 337 |
+ unexportedIntField: 0, |
| 338 |
+ ExportedIntField: 0, |
| 339 |
+ MapA: map[int]string{}, |
| 340 |
+ Array: []int{}, |
| 341 |
+ StructB: StructB{}, |
| 342 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct1) |
| 343 |
-- @fillStruct2/fillStruct.go -- |
| 344 |
@@ -23 +23,3 @@ |
| 345 |
- b := StructA2{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct2) |
| 346 |
+ b := StructA2{ |
| 347 |
+ B: &StructB{}, |
| 348 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct2) |
| 349 |
-- @fillStruct3/fillStruct.go -- |
| 350 |
@@ -24 +24,3 @@ |
| 351 |
- c := StructA3{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct3) |
| 352 |
+ c := StructA3{ |
| 353 |
+ B: StructB{}, |
| 354 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct3) |
| 355 |
-- @fillStruct4/fillStruct.go -- |
| 356 |
@@ -26 +26,3 @@ |
| 357 |
- _ = StructA3{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct4) |
| 358 |
+ _ = StructA3{ |
| 359 |
+ B: StructB{}, |
| 360 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct4) |
| 361 |
-- fillStruct_anon.go -- |
| 362 |
package fillstruct |
| 363 |
|
| 364 |
type StructAnon struct { |
| 365 |
a struct{} |
| 366 |
b map[string]any |
| 367 |
c map[string]struct { |
| 368 |
d int |
| 369 |
e bool |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
func fill() { |
| 374 |
_ := StructAnon{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_anon) |
| 375 |
} |
| 376 |
-- @fillStruct_anon/fillStruct_anon.go -- |
| 377 |
@@ -13 +13,8 @@ |
| 378 |
- _ := StructAnon{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_anon) |
| 379 |
+ _ := StructAnon{ |
| 380 |
+ a: struct{}{}, |
| 381 |
+ b: map[string]any{}, |
| 382 |
+ c: map[string]struct { |
| 383 |
+ d int |
| 384 |
+ e bool |
| 385 |
+ }{}, |
| 386 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_anon) |
| 387 |
-- fillStruct_nested.go -- |
| 388 |
package fillstruct |
| 389 |
|
| 390 |
type StructB struct { |
| 391 |
StructC |
| 392 |
} |
| 393 |
|
| 394 |
type StructC struct { |
| 395 |
unexportedInt int |
| 396 |
} |
| 397 |
|
| 398 |
func nested() { |
| 399 |
c := StructB{ |
| 400 |
StructC: StructC{}, //@codeaction("}", "refactor.rewrite.fillStruct", edit=fill_nested) |
| 401 |
} |
| 402 |
} |
| 403 |
|
| 404 |
-- @fill_nested/fillStruct_nested.go -- |
| 405 |
@@ -13 +13,3 @@ |
| 406 |
- StructC: StructC{}, //@codeaction("}", "refactor.rewrite.fillStruct", edit=fill_nested) |
| 407 |
+ StructC: StructC{ |
| 408 |
+ unexportedInt: 0, |
| 409 |
+ }, //@codeaction("}", "refactor.rewrite.fillStruct", edit=fill_nested) |
| 410 |
-- fillStruct_package.go -- |
| 411 |
package fillstruct |
| 412 |
|
| 413 |
import ( |
| 414 |
h2 "net/http" |
| 415 |
|
| 416 |
"golang.org/lsptests/fillstruct/data" |
| 417 |
) |
| 418 |
|
| 419 |
func unexported() { |
| 420 |
a := data.B{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_package1) |
| 421 |
_ = h2.Client{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_package2) |
| 422 |
} |
| 423 |
-- @fillStruct_package1/fillStruct_package.go -- |
| 424 |
@@ -10 +10,3 @@ |
| 425 |
- a := data.B{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_package1) |
| 426 |
+ a := data.B{ |
| 427 |
+ ExportedInt: 0, |
| 428 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_package1) |
| 429 |
-- @fillStruct_package2/fillStruct_package.go -- |
| 430 |
@@ -11 +11,8 @@ |
| 431 |
- _ = h2.Client{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_package2) |
| 432 |
+ _ = h2.Client{ |
| 433 |
+ Transport: nil, |
| 434 |
+ CheckRedirect: func(req *h2.Request, via []*h2.Request) error { |
| 435 |
+ panic("TODO") |
| 436 |
+ }, |
| 437 |
+ Jar: nil, |
| 438 |
+ Timeout: 0, |
| 439 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_package2) |
| 440 |
-- fillStruct_partial.go -- |
| 441 |
package fillstruct |
| 442 |
|
| 443 |
type StructPartialA struct { |
| 444 |
PrefilledInt int |
| 445 |
UnfilledInt int |
| 446 |
StructPartialB |
| 447 |
} |
| 448 |
|
| 449 |
type StructPartialB struct { |
| 450 |
PrefilledInt int |
| 451 |
UnfilledInt int |
| 452 |
} |
| 453 |
|
| 454 |
func fill() { |
| 455 |
a := StructPartialA{ |
| 456 |
PrefilledInt: 5, |
| 457 |
} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_partial1) |
| 458 |
b := StructPartialB{ |
| 459 |
/* this comment should disappear */ |
| 460 |
PrefilledInt: 7, // This comment should be blown away. |
| 461 |
/* As should |
| 462 |
this one */ |
| 463 |
} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_partial2) |
| 464 |
} |
| 465 |
|
| 466 |
-- @fillStruct_partial1/fillStruct_partial.go -- |
| 467 |
@@ -16 +16,3 @@ |
| 468 |
- PrefilledInt: 5, |
| 469 |
+ PrefilledInt: 5, |
| 470 |
+ UnfilledInt: 0, |
| 471 |
+ StructPartialB: StructPartialB{}, |
| 472 |
-- @fillStruct_partial2/fillStruct_partial.go -- |
| 473 |
@@ -23 +23 @@ |
| 474 |
+ UnfilledInt: 0, |
| 475 |
-- fillStruct_spaces.go -- |
| 476 |
package fillstruct |
| 477 |
|
| 478 |
type StructD struct { |
| 479 |
ExportedIntField int |
| 480 |
} |
| 481 |
|
| 482 |
func spaces() { |
| 483 |
d := StructD{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_spaces) |
| 484 |
} |
| 485 |
|
| 486 |
-- @fillStruct_spaces/fillStruct_spaces.go -- |
| 487 |
@@ -8 +8,3 @@ |
| 488 |
- d := StructD{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_spaces) |
| 489 |
+ d := StructD{ |
| 490 |
+ ExportedIntField: 0, |
| 491 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_spaces) |
| 492 |
-- fillStruct_unsafe.go -- |
| 493 |
package fillstruct |
| 494 |
|
| 495 |
import "unsafe" |
| 496 |
|
| 497 |
type unsafeStruct struct { |
| 498 |
x int |
| 499 |
p unsafe.Pointer |
| 500 |
} |
| 501 |
|
| 502 |
func fill() { |
| 503 |
_ := unsafeStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_unsafe) |
| 504 |
} |
| 505 |
|
| 506 |
-- @fillStruct_unsafe/fillStruct_unsafe.go -- |
| 507 |
@@ -11 +11,4 @@ |
| 508 |
- _ := unsafeStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_unsafe) |
| 509 |
+ _ := unsafeStruct{ |
| 510 |
+ x: 0, |
| 511 |
+ p: nil, |
| 512 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=fillStruct_unsafe) |
| 513 |
-- typeparams.go -- |
| 514 |
package fillstruct |
| 515 |
|
| 516 |
type emptyStructWithTypeParams[A any] struct{} |
| 517 |
|
| 518 |
var _ = emptyStructWithTypeParams[int]{} // no suggested fix |
| 519 |
|
| 520 |
type basicStructWithTypeParams[T any] struct { |
| 521 |
foo T |
| 522 |
} |
| 523 |
|
| 524 |
var _ = basicStructWithTypeParams[int]{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams1) |
| 525 |
|
| 526 |
type twoArgStructWithTypeParams[F, B any] struct { |
| 527 |
foo F |
| 528 |
bar B |
| 529 |
} |
| 530 |
|
| 531 |
var _ = twoArgStructWithTypeParams[string, int]{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams2) |
| 532 |
|
| 533 |
var _ = twoArgStructWithTypeParams[int, string]{ |
| 534 |
bar: "bar", |
| 535 |
} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams3) |
| 536 |
|
| 537 |
type nestedStructWithTypeParams struct { |
| 538 |
bar string |
| 539 |
basic basicStructWithTypeParams[int] |
| 540 |
} |
| 541 |
|
| 542 |
var _ = nestedStructWithTypeParams{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams4) |
| 543 |
|
| 544 |
func _[T any]() { |
| 545 |
type S struct{ t T } |
| 546 |
_ = S{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams5) |
| 547 |
|
| 548 |
type P struct{ t *T } |
| 549 |
_ = P{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams6) |
| 550 |
|
| 551 |
type Alias[u any] = struct { |
| 552 |
x u |
| 553 |
y *T |
| 554 |
} |
| 555 |
_ = Alias[string]{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams7) |
| 556 |
|
| 557 |
type Named[u any] struct { |
| 558 |
x u |
| 559 |
y T |
| 560 |
} |
| 561 |
_ = Named[int]{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams8) |
| 562 |
} |
| 563 |
-- @typeparams1/typeparams.go -- |
| 564 |
@@ -11 +11,3 @@ |
| 565 |
-var _ = basicStructWithTypeParams[int]{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams1) |
| 566 |
+var _ = basicStructWithTypeParams[int]{ |
| 567 |
+ foo: 0, |
| 568 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams1) |
| 569 |
-- @typeparams2/typeparams.go -- |
| 570 |
@@ -18 +18,4 @@ |
| 571 |
-var _ = twoArgStructWithTypeParams[string, int]{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams2) |
| 572 |
+var _ = twoArgStructWithTypeParams[string, int]{ |
| 573 |
+ foo: "", |
| 574 |
+ bar: 0, |
| 575 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams2) |
| 576 |
-- @typeparams3/typeparams.go -- |
| 577 |
@@ -22 +22 @@ |
| 578 |
+ foo: 0, |
| 579 |
-- @typeparams4/typeparams.go -- |
| 580 |
@@ -29 +29,4 @@ |
| 581 |
-var _ = nestedStructWithTypeParams{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams4) |
| 582 |
+var _ = nestedStructWithTypeParams{ |
| 583 |
+ bar: "", |
| 584 |
+ basic: basicStructWithTypeParams[int]{}, |
| 585 |
+} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams4) |
| 586 |
-- @typeparams5/typeparams.go -- |
| 587 |
@@ -33 +33,3 @@ |
| 588 |
- _ = S{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams5) |
| 589 |
+ _ = S{ |
| 590 |
+ t: *new(T), |
| 591 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams5) |
| 592 |
-- @typeparams6/typeparams.go -- |
| 593 |
@@ -36 +36,3 @@ |
| 594 |
- _ = P{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams6) |
| 595 |
+ _ = P{ |
| 596 |
+ t: new(T), |
| 597 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams6) |
| 598 |
-- @typeparams7/typeparams.go -- |
| 599 |
@@ -42 +42,4 @@ |
| 600 |
- _ = Alias[string]{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams7) |
| 601 |
+ _ = Alias[string]{ |
| 602 |
+ x: "", |
| 603 |
+ y: new(T), |
| 604 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams7) |
| 605 |
-- @typeparams8/typeparams.go -- |
| 606 |
@@ -48 +48,4 @@ |
| 607 |
- _ = Named[int]{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams8) |
| 608 |
+ _ = Named[int]{ |
| 609 |
+ x: 0, |
| 610 |
+ y: *new(T), |
| 611 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=typeparams8) |
| 612 |
-- issue63921.go -- |
| 613 |
package fillstruct |
| 614 |
|
| 615 |
// Test for golang/go#63921: fillstruct panicked with invalid fields. |
| 616 |
type invalidStruct struct { |
| 617 |
F int |
| 618 |
Undefined |
| 619 |
} |
| 620 |
|
| 621 |
func _() { |
| 622 |
// Note: fillstruct now skips invalid/unresolvable fields (like Undefined) |
| 623 |
// rather than aborting completely, it successfully fills the valid field F. |
| 624 |
invalidStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=issue63921) |
| 625 |
} |
| 626 |
-- @issue63921/issue63921.go -- |
| 627 |
@@ -12 +12,3 @@ |
| 628 |
- invalidStruct{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=issue63921) |
| 629 |
+ invalidStruct{ |
| 630 |
+ F: 0, |
| 631 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=issue63921) |
| 632 |
-- named/named.go -- |
| 633 |
package named |
| 634 |
|
| 635 |
type foo struct {} |
| 636 |
type aliasFoo = foo |
| 637 |
|
| 638 |
func _() { |
| 639 |
type namedInt int |
| 640 |
type namedString string |
| 641 |
type namedBool bool |
| 642 |
type namedPointer *foo |
| 643 |
type namedSlice []foo |
| 644 |
type namedInterface interface{ Error() string } |
| 645 |
type namedChan chan int |
| 646 |
type namedMap map[string]foo |
| 647 |
type namedSignature func(string) string |
| 648 |
type namedStruct struct{} |
| 649 |
type namedArray [3]foo |
| 650 |
type namedAlias aliasFoo |
| 651 |
|
| 652 |
type bar struct { |
| 653 |
namedInt namedInt |
| 654 |
namedString namedString |
| 655 |
namedBool namedBool |
| 656 |
namedPointer namedPointer |
| 657 |
namedSlice namedSlice |
| 658 |
namedInterface namedInterface |
| 659 |
namedChan namedChan |
| 660 |
namedMap namedMap |
| 661 |
namedSignature namedSignature |
| 662 |
namedStruct namedStruct |
| 663 |
namedArray namedArray |
| 664 |
namedAlias namedAlias |
| 665 |
} |
| 666 |
|
| 667 |
bar{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=named) |
| 668 |
} |
| 669 |
-- @named/named/named.go -- |
| 670 |
@@ -35 +35,14 @@ |
| 671 |
- bar{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=named) |
| 672 |
+ bar{ |
| 673 |
+ namedInt: 0, |
| 674 |
+ namedString: "", |
| 675 |
+ namedBool: false, |
| 676 |
+ namedPointer: nil, |
| 677 |
+ namedSlice: namedSlice{}, |
| 678 |
+ namedInterface: nil, |
| 679 |
+ namedChan: nil, |
| 680 |
+ namedMap: namedMap{}, |
| 681 |
+ namedSignature: nil, |
| 682 |
+ namedStruct: namedStruct{}, |
| 683 |
+ namedArray: namedArray{}, |
| 684 |
+ namedAlias: namedAlias{}, |
| 685 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=named) |
| 686 |
-- alias/alias.go -- |
| 687 |
package alias |
| 688 |
|
| 689 |
type foo struct {} |
| 690 |
type aliasFoo = foo |
| 691 |
|
| 692 |
func _() { |
| 693 |
type aliasInt = int |
| 694 |
type aliasString = string |
| 695 |
type aliasBool = bool |
| 696 |
type aliasPointer = *foo |
| 697 |
type aliasSlice = []foo |
| 698 |
type aliasInterface = interface{ Error() string } |
| 699 |
type aliasChan = chan int |
| 700 |
type aliasMap = map[string]foo |
| 701 |
type aliasSignature = func(string) string |
| 702 |
type aliasStruct = struct{ bar string } |
| 703 |
type aliasArray = [3]foo |
| 704 |
type aliasNamed = foo |
| 705 |
|
| 706 |
type bar struct { |
| 707 |
aliasInt aliasInt |
| 708 |
aliasString aliasString |
| 709 |
aliasBool aliasBool |
| 710 |
aliasPointer aliasPointer |
| 711 |
aliasSlice aliasSlice |
| 712 |
aliasInterface aliasInterface |
| 713 |
aliasChan aliasChan |
| 714 |
aliasMap aliasMap |
| 715 |
aliasSignature aliasSignature |
| 716 |
aliasStruct aliasStruct |
| 717 |
aliasArray aliasArray |
| 718 |
aliasNamed aliasNamed |
| 719 |
} |
| 720 |
|
| 721 |
bar{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=alias) |
| 722 |
} |
| 723 |
-- @alias/alias/alias.go -- |
| 724 |
@@ -35 +35,14 @@ |
| 725 |
- bar{} //@codeaction("}", "refactor.rewrite.fillStruct", edit=alias) |
| 726 |
+ bar{ |
| 727 |
+ aliasInt: 0, |
| 728 |
+ aliasString: "", |
| 729 |
+ aliasBool: false, |
| 730 |
+ aliasPointer: nil, |
| 731 |
+ aliasSlice: aliasSlice{}, |
| 732 |
+ aliasInterface: nil, |
| 733 |
+ aliasChan: nil, |
| 734 |
+ aliasMap: aliasMap{}, |
| 735 |
+ aliasSignature: nil, |
| 736 |
+ aliasStruct: aliasStruct{}, |
| 737 |
+ aliasArray: aliasArray{}, |
| 738 |
+ aliasNamed: aliasNamed{}, |
| 739 |
+ } //@codeaction("}", "refactor.rewrite.fillStruct", edit=alias) |
| 740 |
-- preserveformat/preserveformat.go -- |
| 741 |
package preserveformat |
| 742 |
|
| 743 |
type ( |
| 744 |
Node struct { |
| 745 |
Value int |
| 746 |
} |
| 747 |
Graph struct { |
| 748 |
Nodes []*Node `json:""` |
| 749 |
Edges map[*Node]*Node |
| 750 |
Other string |
| 751 |
} |
| 752 |
) |
| 753 |
|
| 754 |
func _() { |
| 755 |
_ := &Graph{ |
| 756 |
// comments at the start preserved |
| 757 |
Nodes: []*Node{ |
| 758 |
{Value: 0}, // comments in the middle preserved |
| 759 |
// between lines |
| 760 |
{Value: 0}, |
| 761 |
}, // another comment |
| 762 |
// comment group |
| 763 |
// below |
| 764 |
} //@codeaction("}", "refactor.rewrite.fillStruct", edit=preserveformat) |
| 765 |
} |
| 766 |
-- @preserveformat/preserveformat/preserveformat.go -- |
| 767 |
@@ -24 +24,2 @@ |
| 768 |
+ Edges: map[*Node]*Node{}, |
| 769 |
+ Other: "", |