MCPcopy Create free account
hub / github.com/coder/guts / NewGolangParser

Function NewGolangParser

convert.go:54–82  ·  view source on GitHub ↗

NewGolangParser returns a new GoParser object. This object is responsible for converting Go types into the intermediate typescript AST representation. All configuration of the GoParser should be done before calling 'ToTypescript'. For usage, see 'ExampleGeneration' in convert_test.go.

()

Source from the content-addressed store, hash-verified

52// 'ToTypescript'.
53// For usage, see 'ExampleGeneration' in convert_test.go.
54func NewGolangParser() (*GoParser, error) {
55 fileSet := token.NewFileSet()
56 config := &packages.Config{
57 // Just accept the fact we need these flags for what we want. Feel free to add
58 // more, it'll just increase the time it takes to parse.
59 Mode: packages.NeedTypes | packages.NeedName | packages.NeedTypesInfo |
60 packages.NeedTypesSizes | packages.NeedSyntax | packages.NeedDeps,
61 Tests: false,
62 Fset: fileSet,
63 //Dir: "/home/steven/go/src/github.com/coder/guts",
64 Context: context.Background(),
65 }
66
67 return &GoParser{
68 fileSet: fileSet,
69 config: config,
70 Pkgs: make(map[string]*packages.Package),
71 Reference: make(map[string]bool),
72 referencedTypes: newReferencedTypes(),
73 Prefix: make(map[string]string),
74 Skips: make(map[string]struct{}),
75 typeOverrides: map[string]TypeOverride{
76 // Some hard coded defaults
77 "error": func() bindings.ExpressionType {
78 return ptr(bindings.KeywordString)
79 },
80 },
81 }, nil
82}
83
84// PreserveComments will attempt to preserve any comments associated with
85// the golang types. This feature is still a work in progress, and may not

Callers 6

loadTypescriptFunction · 0.92
ExampleNewGolangParserFunction · 0.92
TestGenerationFunction · 0.92
TestNotNullMapsFunction · 0.92
mainFunction · 0.92
parseExpressionFunction · 0.85

Calls 2

newReferencedTypesFunction · 0.85
ptrFunction · 0.70

Tested by 4

loadTypescriptFunction · 0.74
ExampleNewGolangParserFunction · 0.74
TestGenerationFunction · 0.74
TestNotNullMapsFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…