From 74a6bbb3463be9c30a133a80d4e5bbdbd0b6ee2c Mon Sep 17 00:00:00 2001 From: Josh Baum Date: Tue, 28 Jul 2020 10:34:50 -0400 Subject: [PATCH] internal/lsp: enhance fillstruct and fillreturns to fill with variables In the previous implementation, we always created a default value for each type in the struct or return statement in fillstruct and fillreturns, respectively. Now, we try to find a variable in scope that matches the expected type. If we find multiple matches, we choose the variable that is named most similarly to the type. If we do not find a variable that matches, we maintain the previous functionality. Change-Id: I3acb7e27476afaa71aaff9ffb69445913575e2b6 Reviewed-on: https://go-review.googlesource.com/c/tools/+/245130 Run-TryBot: Josh Baum TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/analysisinternal/analysis.go | 117 + .../lsp/analysis/fillreturns/fillreturns.go | 44 +- .../analysis/fillreturns/testdata/src/a/a.go | 15 + .../fillreturns/testdata/src/a/a.go.golden | 15 + .../lsp/analysis/fillstruct/fillstruct.go | 30 +- .../testdata/lsp/primarymod/fillstruct/a.go | 36 + .../lsp/primarymod/fillstruct/a.go.golden | 3563 +++++++++++++++++ internal/lsp/testdata/lsp/summary.txt.golden | 2 +- 8 files changed, 3806 insertions(+), 16 deletions(-) diff --git a/internal/analysisinternal/analysis.go b/internal/analysisinternal/analysis.go index eb75680fdb..e25f4a4096 100644 --- a/internal/analysisinternal/analysis.go +++ b/internal/analysisinternal/analysis.go @@ -14,6 +14,7 @@ import ( "strings" "golang.org/x/tools/go/ast/astutil" + "golang.org/x/tools/internal/lsp/fuzzy" ) var ( @@ -302,3 +303,119 @@ func WalkASTWithParent(n ast.Node, f func(n ast.Node, parent ast.Node) bool) { return f(n, parent) }) } + +// FindMatchingIdents finds all identifiers in 'node' that match any of the given types. +// 'pos' represents the position at which the identifiers may be inserted. 'pos' must be within +// the scope of each of identifier we select. Otherwise, we will insert a variable at 'pos' that +// is unrecognized. +func FindMatchingIdents(typs []types.Type, node ast.Node, pos token.Pos, info *types.Info, pkg *types.Package) map[types.Type][]*ast.Ident { + matches := map[types.Type][]*ast.Ident{} + // Initialize matches to contain the variable types we are searching for. + for _, typ := range typs { + if typ == nil { + continue + } + matches[typ] = []*ast.Ident{} + } + seen := map[types.Object]struct{}{} + ast.Inspect(node, func(n ast.Node) bool { + if n == nil { + return false + } + // Prevent circular definitions. If 'pos' is within an assignment statement, do not + // allow any identifiers in that assignment statement to be selected. Otherwise, + // we could do the following, where 'x' satisfies the type of 'f0': + // + // x := fakeStruct{f0: x} + // + assignment, ok := n.(*ast.AssignStmt) + if ok && pos > assignment.Pos() && pos <= assignment.End() { + return false + } + if n.End() > pos { + return n.Pos() <= pos + } + ident, ok := n.(*ast.Ident) + if !ok || ident.Name == "_" { + return true + } + obj := info.Defs[ident] + if obj == nil || obj.Type() == nil { + return true + } + if _, ok := obj.(*types.TypeName); ok { + return true + } + // Prevent duplicates in matches' values. + if _, ok = seen[obj]; ok { + return true + } + seen[obj] = struct{}{} + // Find the scope for the given position. Then, check whether the object + // exists within the scope. + innerScope := pkg.Scope().Innermost(pos) + if innerScope == nil { + return true + } + _, foundObj := innerScope.LookupParent(ident.Name, pos) + if foundObj != obj { + return true + } + // The object must match one of the types that we are searching for. + if idents, ok := matches[obj.Type()]; ok { + matches[obj.Type()] = append(idents, ast.NewIdent(ident.Name)) + } + // If the object type does not exactly match any of the target types, greedily + // find the first target type that the object type can satisfy. + for typ := range matches { + if obj.Type() == typ { + continue + } + if equivalentTypes(obj.Type(), typ) { + matches[typ] = append(matches[typ], ast.NewIdent(ident.Name)) + } + } + return true + }) + return matches +} + +func equivalentTypes(want, got types.Type) bool { + if want == got || types.Identical(want, got) { + return true + } + // Code segment to help check for untyped equality from (golang/go#32146). + if rhs, ok := want.(*types.Basic); ok && rhs.Info()&types.IsUntyped > 0 { + if lhs, ok := got.Underlying().(*types.Basic); ok { + return rhs.Info()&types.IsConstType == lhs.Info()&types.IsConstType + } + } + return types.AssignableTo(want, got) +} + +// FindBestMatch employs fuzzy matching to evaluate the similarity of each given identifier to the +// given pattern. We return the identifier whose name is most similar to the pattern. +func FindBestMatch(pattern string, idents []*ast.Ident) ast.Expr { + fuzz := fuzzy.NewMatcher(pattern) + var bestFuzz ast.Expr + highScore := float32(-1) // minimum score is -1 (no match) + for _, ident := range idents { + // TODO: Improve scoring algorithm. + score := fuzz.Score(ident.Name) + if score > highScore { + highScore = score + bestFuzz = ident + } else if score == -1 { + // Order matters in the fuzzy matching algorithm. If we find no match + // when matching the target to the identifier, try matching the identifier + // to the target. + revFuzz := fuzzy.NewMatcher(ident.Name) + revScore := revFuzz.Score(pattern) + if revScore > highScore { + highScore = revScore + bestFuzz = ident + } + } + } + return bestFuzz +} diff --git a/internal/lsp/analysis/fillreturns/fillreturns.go b/internal/lsp/analysis/fillreturns/fillreturns.go index d194cd3670..039b7c3259 100644 --- a/internal/lsp/analysis/fillreturns/fillreturns.go +++ b/internal/lsp/analysis/fillreturns/fillreturns.go @@ -89,7 +89,7 @@ outer: return nil, nil } - // Get the function that encloses the ReturnStmt. + // Get the function type that encloses the ReturnStmt. var enclosingFunc *ast.FuncType for _, n := range path { switch node := n.(type) { @@ -106,6 +106,18 @@ outer: continue } + // Find the function declaration that encloses the ReturnStmt. + var outer *ast.FuncDecl + for _, p := range path { + if p, ok := p.(*ast.FuncDecl); ok { + outer = p + break + } + } + if outer == nil { + return nil, nil + } + // Skip any return statements that contain function calls with multiple return values. for _, expr := range ret.Results { e, ok := expr.(*ast.CallExpr) @@ -126,13 +138,17 @@ outer: // For each value in the return function declaration, find the leftmost element // in the return statement that has the desired type. If no such element exits, // fill in the missing value with the appropriate "zero" value. - for i, result := range enclosingFunc.Results.List { - typ := info.TypeOf(result.Type) - + var retTyps []types.Type + for _, ret := range enclosingFunc.Results.List { + retTyps = append(retTyps, info.TypeOf(ret.Type)) + } + matches := + analysisinternal.FindMatchingIdents(retTyps, file, ret.Pos(), info, pass.Pkg) + for i, retTyp := range retTyps { var match ast.Expr var idx int for j, val := range remaining { - if !matchingTypes(info.TypeOf(val), typ) { + if !matchingTypes(info.TypeOf(val), retTyp) { continue } if !analysisinternal.IsZeroValue(val) { @@ -149,12 +165,22 @@ outer: fixed[i] = match remaining = append(remaining[:idx], remaining[idx+1:]...) } else { - zv := analysisinternal.ZeroValue(pass.Fset, file, pass.Pkg, - info.TypeOf(result.Type)) - if zv == nil { + idents, ok := matches[retTyp] + if !ok { + return nil, fmt.Errorf("invalid return type: %v", retTyp) + } + // Find the identifer whose name is most similar to the return type. + // If we do not find any identifer that matches the pattern, + // generate a zero value. + value := analysisinternal.FindBestMatch(retTyp.String(), idents) + if value == nil { + value = analysisinternal.ZeroValue( + pass.Fset, file, pass.Pkg, retTyp) + } + if value == nil { return nil, nil } - fixed[i] = zv + fixed[i] = value } } diff --git a/internal/lsp/analysis/fillreturns/testdata/src/a/a.go b/internal/lsp/analysis/fillreturns/testdata/src/a/a.go index 74c87e06f7..44cb25ffa3 100644 --- a/internal/lsp/analysis/fillreturns/testdata/src/a/a.go +++ b/internal/lsp/analysis/fillreturns/testdata/src/a/a.go @@ -6,6 +6,7 @@ package fillreturns import ( "errors" + "go/ast" ast2 "go/ast" "io" "net/http" @@ -120,3 +121,17 @@ func gotTooMany() int { } return 0, 5, false // want "wrong number of return values \\(want 1, got 3\\)" } + +func fillVars() (int, string, ast.Node, bool, error) { + eint := 0 + s := "a" + var t bool + if true { + err := errors.New("fail") + return // want "wrong number of return values \\(want 5, got 0\\)" + } + n := ast.NewIdent("ident") + int := 3 + var b bool + return "" // want "wrong number of return values \\(want 5, got 1\\)" +} diff --git a/internal/lsp/analysis/fillreturns/testdata/src/a/a.go.golden b/internal/lsp/analysis/fillreturns/testdata/src/a/a.go.golden index 69140d06f5..1435ea09a5 100644 --- a/internal/lsp/analysis/fillreturns/testdata/src/a/a.go.golden +++ b/internal/lsp/analysis/fillreturns/testdata/src/a/a.go.golden @@ -6,6 +6,7 @@ package fillreturns import ( "errors" + "go/ast" ast2 "go/ast" "io" "net/http" @@ -120,3 +121,17 @@ func gotTooMany() int { } return 5 // want "wrong number of return values \\(want 1, got 3\\)" } + +func fillVars() (int, string, ast.Node, bool, error) { + eint := 0 + s := "a" + var t bool + if true { + err := errors.New("fail") + return eint, s, nil, false, err // want "wrong number of return values \\(want 5, got 0\\)" + } + n := ast.NewIdent("ident") + int := 3 + var b bool + return int, "", n, b, nil // want "wrong number of return values \\(want 5, got 1\\)" +} diff --git a/internal/lsp/analysis/fillstruct/fillstruct.go b/internal/lsp/analysis/fillstruct/fillstruct.go index 047458ad33..495d64652f 100644 --- a/internal/lsp/analysis/fillstruct/fillstruct.go +++ b/internal/lsp/analysis/fillstruct/fillstruct.go @@ -114,7 +114,7 @@ func run(pass *analysis.Pass) (interface{}, error) { name = "anonymous struct" } pass.Report(analysis.Diagnostic{ - Message: fmt.Sprintf("Fill %s with default values", name), + Message: fmt.Sprintf("Fill %s", name), Pos: expr.Pos(), End: expr.End(), }) @@ -172,18 +172,36 @@ func SuggestedFix(fset *token.FileSet, rng span.Range, content []byte, file *ast line := 2 // account for 1-based lines and the left brace var elts []ast.Expr + var fieldTyps []types.Type for i := 0; i < fieldCount; i++ { field := obj.Field(i) - // Ignore fields that are not accessible in the current package. if field.Pkg() != nil && field.Pkg() != pkg && !field.Exported() { + fieldTyps = append(fieldTyps, nil) continue } - - value := populateValue(fset, file, pkg, field.Type()) - if value == nil { + fieldTyps = append(fieldTyps, field.Type()) + } + matches := analysisinternal.FindMatchingIdents(fieldTyps, file, rng.Start, info, pkg) + for i, fieldTyp := range fieldTyps { + if fieldTyp == nil { continue } + idents, ok := matches[fieldTyp] + if !ok { + return nil, fmt.Errorf("invalid struct field type: %v", fieldTyp) + } + + // Find the identifer whose name is most similar to the name of the field's key. + // If we do not find any identifer that matches the pattern, generate a new value. + // NOTE: We currently match on the name of the field key rather than the field type. + value := analysisinternal.FindBestMatch(obj.Field(i).Name(), idents) + if value == nil { + value = populateValue(fset, file, pkg, fieldTyp) + } + if value == nil { + return nil, nil + } tok.AddLine(line - 1) // add 1 byte per line if line > tok.LineCount() { @@ -194,7 +212,7 @@ func SuggestedFix(fset *token.FileSet, rng span.Range, content []byte, file *ast kv := &ast.KeyValueExpr{ Key: &ast.Ident{ NamePos: pos, - Name: field.Name(), + Name: obj.Field(i).Name(), }, Colon: pos, Value: value, diff --git a/internal/lsp/testdata/lsp/primarymod/fillstruct/a.go b/internal/lsp/testdata/lsp/primarymod/fillstruct/a.go index 74e681cf4e..1fc1c55857 100644 --- a/internal/lsp/testdata/lsp/primarymod/fillstruct/a.go +++ b/internal/lsp/testdata/lsp/primarymod/fillstruct/a.go @@ -96,3 +96,39 @@ var _ = []ast.BasicLit{ } var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} diff --git a/internal/lsp/testdata/lsp/primarymod/fillstruct/a.go.golden b/internal/lsp/testdata/lsp/primarymod/fillstruct/a.go.golden index 5bf579ee8d..6dade08fe1 100644 --- a/internal/lsp/testdata/lsp/primarymod/fillstruct/a.go.golden +++ b/internal/lsp/testdata/lsp/primarymod/fillstruct/a.go.golden @@ -1,3 +1,145 @@ +-- suggestedfix_a_100_25 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{ + ValuePos: 0, + Kind: 0, + Value: "", +}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_100_30 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -442,6 +584,1259 @@ var _ = []ast.BasicLit{{ Value: "", }} //@suggestedfix("}", "refactor.rewrite") +-- suggestedfix_a_120_18 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{ + X: x, + } //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_122_18 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{ + X: x, + } //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_123_18 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{ + str: s, + } //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_125_18 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{ + str: s, + } //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_126_20 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + var _ = multiFill{ + num: n, + strin: s, + arr: []int{}, + } //@suggestedfix("}", "refactor.rewrite") + + var compLit *ast.CompositeLit + var _ = assignStruct{} + +} + +-- suggestedfix_a_130_20 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{ + num: n, + strin: s, + arr: []int{}, + } //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_132_20 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{ + num: n, + strin: s, + arr: []int{}, + } //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_133_23 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{ + n: node, + } //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_135_23 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{ + n: node, + } //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_18_21 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -544,6 +1939,182 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_20_21 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{ + foo: 0, +} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_22_21 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -757,6 +2328,183 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_27_22 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{ + foo: 0, + bar: "", +} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_29_1 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -1076,6 +2824,42 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_33_1 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -1287,6 +3071,323 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_34_22 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{ + bar: "", + basic: basicStruct{}, +} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_36_16 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{ + ExportedInt: 0, +} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_36_22 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -1827,6 +3928,186 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_46_21 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{ + m: map[string]int{}, + s: []int{}, + c: make(chan int), + c1: make(<-chan int), + a: [2]string{}, +} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_48_21 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -2040,6 +4321,183 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_52_19 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{ + fn: func(i int) int { + }, +} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_52_21 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -2364,6 +4822,42 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_58_19 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -2475,6 +4969,147 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +-- suggestedfix_a_58_25 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{ + fn: func(i int, s string) (string, int) { + }, +} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_60_25 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -2685,6 +5320,183 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_64_24 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{ + fn: func() { + }, +} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_64_25 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -3117,6 +5929,183 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_75_13 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{ + X: &Foo{}, + Y: &Foo{}, +} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_77_13 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -3443,6 +6432,188 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_86_24 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{ + m: map[*ast.CompositeLit]ast.Field{}, + s: []ast.BadExpr{}, + a: [3]token.Token{}, + c: make(chan ast.EmptyStmt), + fn: func(ast_decl ast.DeclStmt) ast.Ellipsis { + }, + st: ast.CompositeLit{}, +} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_88_24 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -3775,6 +6946,184 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + +-- suggestedfix_a_94_30 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{ + b: new(bool), + s: new(string), + i: new(int), +} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + {}, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_95_3 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -3879,6 +7228,42 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_96_30 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -3987,6 +7372,148 @@ var _ = []ast.BasicLit{ var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") +-- suggestedfix_a_97_3 -- +// Copyright 2020 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. + +package fillstruct + +import ( + "go/ast" + "go/token" + + "golang.org/x/tools/internal/lsp/fillstruct/data" +) + +var foop int + +type basicStruct struct { + foo int +} + +var _ = basicStruct{} //@suggestedfix("}", "refactor.rewrite") + +type twoArgStruct struct { + foo int + bar string +} + +var _ = twoArgStruct{} //@suggestedfix("}", "refactor.rewrite") + +type nestedStruct struct { + bar string + basic basicStruct +} + +var _ = nestedStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = data.B{} //@suggestedfix("}", "refactor.rewrite") + +type typedStruct struct { + m map[string]int + s []int + c chan int + c1 <-chan int + a [2]string +} + +var _ = typedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStruct struct { + fn func(i int) int +} + +var _ = funStruct{} //@suggestedfix("}", "refactor.rewrite") + +type funStructCompex struct { + fn func(i int, s string) (string, int) +} + +var _ = funStructCompex{} //@suggestedfix("}", "refactor.rewrite") + +type funStructEmpty struct { + fn func() +} + +var _ = funStructEmpty{} //@suggestedfix("}", "refactor.rewrite") + +type Foo struct { + A int +} + +type Bar struct { + X *Foo + Y *Foo +} + +var _ = Bar{} //@suggestedfix("}", "refactor.rewrite") + +type importedStruct struct { + m map[*ast.CompositeLit]ast.Field + s []ast.BadExpr + a [3]token.Token + c chan ast.EmptyStmt + fn func(ast_decl ast.DeclStmt) ast.Ellipsis + st ast.CompositeLit +} + +var _ = importedStruct{} //@suggestedfix("}", "refactor.rewrite") + +type pointerBuiltinStruct struct { + b *bool + s *string + i *int +} + +var _ = pointerBuiltinStruct{} //@suggestedfix("}", "refactor.rewrite") + +var _ = []ast.BasicLit{ + { + ValuePos: 0, + Kind: 0, + Value: "", + }, //@suggestedfix("}", "refactor.rewrite") +} + +var _ = []ast.BasicLit{{}} //@suggestedfix("}", "refactor.rewrite") + +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_98_25 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -4091,6 +7618,42 @@ var _ = []ast.BasicLit{{ Value: "", }} //@suggestedfix("}", "refactor.rewrite") +type iStruct struct { + X int +} + +type sStruct struct { + str string +} + +type multiFill struct { + num int + strin string + arr []int +} + +type assignStruct struct { + n ast.Node +} + +func fill() { + var x int + var _ = iStruct{} //@suggestedfix("}", "refactor.rewrite") + + var s string + var _ = sStruct{} //@suggestedfix("}", "refactor.rewrite") + + var n int + _ = []int{} + if true { + arr := []int{1, 2} + } + var _ = multiFill{} //@suggestedfix("}", "refactor.rewrite") + + var node *ast.CompositeLit + var _ = assignStruct{} //@suggestedfix("}", "refactor.rewrite") +} + -- suggestedfix_a_99_3 -- // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/internal/lsp/testdata/lsp/summary.txt.golden b/internal/lsp/testdata/lsp/summary.txt.golden index 35bed3d946..f8ff795d04 100644 --- a/internal/lsp/testdata/lsp/summary.txt.golden +++ b/internal/lsp/testdata/lsp/summary.txt.golden @@ -12,7 +12,7 @@ DiagnosticsCount = 44 FoldingRangesCount = 2 FormatCount = 6 ImportCount = 8 -SuggestedFixCount = 31 +SuggestedFixCount = 35 FunctionExtractionCount = 11 DefinitionsCount = 63 TypeDefinitionsCount = 2