@@ -3,16 +3,13 @@ package codegen
33import (
44 "embed"
55 "fmt"
6- "go/ast"
76 "io"
87 "reflect"
9- "strings"
108 "text/template"
119 "unicode"
1210
1311 "github.com/cloudquery/plugin-sdk/schema"
1412 "github.com/iancoleman/strcase"
15- "golang.org/x/tools/go/packages"
1613)
1714
1815type TableOptions func (* TableDefinition )
@@ -75,12 +72,6 @@ func WithExtraColumns(columns []ColumnDefinition) TableOptions {
7572 }
7673}
7774
78- func WithDescriptionsEnabled () TableOptions {
79- return func (t * TableDefinition ) {
80- t .descriptionsEnabled = true
81- }
82- }
83-
8475func defaultTransformer (name string ) string {
8576 return strcase .ToSnake (name )
8677}
@@ -111,11 +102,6 @@ func NewTableFromStruct(name string, obj interface{}, opts ...TableOptions) (*Ta
111102 return nil , fmt .Errorf ("expected struct, got %s" , e .Kind ())
112103 }
113104
114- comments := make (map [string ]string )
115- if t .descriptionsEnabled {
116- comments = readStructComments (e .Type ().PkgPath (), e .Type ().Name ())
117- }
118-
119105 t .Columns = append (t .Columns , t .extraColumns ... )
120106
121107 for i := 0 ; i < e .NumField (); i ++ {
@@ -139,10 +125,9 @@ func NewTableFromStruct(name string, obj interface{}, opts ...TableOptions) (*Ta
139125 // generate a PathResolver to use by default
140126 pathResolver := fmt .Sprintf ("schema.PathResolver(%q)" , field .Name )
141127 column := ColumnDefinition {
142- Name : t .nameTransformer (field .Name ),
143- Type : columnType ,
144- Resolver : pathResolver ,
145- Description : strings .ReplaceAll (comments [field .Name ], "`" , "'" ),
128+ Name : t .nameTransformer (field .Name ),
129+ Type : columnType ,
130+ Resolver : pathResolver ,
146131 }
147132 t .Columns = append (t .Columns , column )
148133 }
@@ -161,29 +146,3 @@ func (t *TableDefinition) GenerateTemplate(wr io.Writer) error {
161146 }
162147 return nil
163148}
164-
165- func readStructComments (pkgPath string , structName string ) map [string ]string {
166- cfg := & packages.Config {Mode : packages .NeedFiles | packages .NeedSyntax }
167- pkgs , err := packages .Load (cfg , pkgPath )
168- if err != nil {
169- panic (err )
170- }
171- comments := make (map [string ]string , 0 )
172- for _ , p := range pkgs {
173- for _ , f := range p .Syntax {
174- ast .Inspect (f , func (n ast.Node ) bool {
175- if st , ok := n .(* ast.TypeSpec ); ok {
176- if st .Name .Name == structName {
177- for _ , field := range st .Type .(* ast.StructType ).Fields .List {
178- if len (field .Names ) > 0 {
179- comments [field .Names [0 ].Name ] = field .Doc .Text ()
180- }
181- }
182- }
183- }
184- return true
185- })
186- }
187- }
188- return comments
189- }
0 commit comments