diff --git a/internal/analysisinternal/analysis.go b/internal/analysisinternal/analysis.go index e25f4a4096..54a6992a12 100644 --- a/internal/analysisinternal/analysis.go +++ b/internal/analysisinternal/analysis.go @@ -198,8 +198,12 @@ func TypeExpr(fset *token.FileSet, f *ast.File, pkg *types.Package, typ types.Ty X: ast.NewIdent(pkgName), Sel: ast.NewIdent(t.Obj().Name()), } + case *types.Struct: + return ast.NewIdent(t.String()) + case *types.Interface: + return ast.NewIdent(t.String()) default: - return nil // TODO: anonymous structs, but who does that + return nil } } diff --git a/internal/lsp/testdata/lsp/primarymod/fillstruct/fill_struct_anon.go b/internal/lsp/testdata/lsp/primarymod/fillstruct/fill_struct_anon.go new file mode 100644 index 0000000000..b5d2337fd9 --- /dev/null +++ b/internal/lsp/testdata/lsp/primarymod/fillstruct/fill_struct_anon.go @@ -0,0 +1,14 @@ +package fillstruct + +type StructAnon struct { + a struct{} + b map[string]interface{} + c map[string]struct { + d int + e bool + } +} + +func fill() { + _ := StructAnon{} //@suggestedfix("}", "refactor.rewrite") +} diff --git a/internal/lsp/testdata/lsp/primarymod/fillstruct/fill_struct_anon.go.golden b/internal/lsp/testdata/lsp/primarymod/fillstruct/fill_struct_anon.go.golden new file mode 100644 index 0000000000..eb6ffd6613 --- /dev/null +++ b/internal/lsp/testdata/lsp/primarymod/fillstruct/fill_struct_anon.go.golden @@ -0,0 +1,20 @@ +-- suggestedfix_fill_struct_anon_13_18 -- +package fillstruct + +type StructAnon struct { + a struct{} + b map[string]interface{} + c map[string]struct { + d int + e bool + } +} + +func fill() { + _ := StructAnon{ + a: struct{}{}, + b: map[string]interface{}{}, + c: map[string]struct{d int; e bool}{}, + } //@suggestedfix("}", "refactor.rewrite") +} + diff --git a/internal/lsp/testdata/lsp/summary.txt.golden b/internal/lsp/testdata/lsp/summary.txt.golden index 651e8e971d..36120de60f 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 = 37 +SuggestedFixCount = 38 FunctionExtractionCount = 11 DefinitionsCount = 63 TypeDefinitionsCount = 2