Skip to content

Commit

Permalink
Make Source field in Breakpoint events optional (#67)
Browse files Browse the repository at this point in the history
* Make `Source` field in `Breakpoint` events optional

Fixes #66

* cmd/gentypes: update code generator to make Source a pointer

This updates the gentypes to make the Source field of Breakpoint
a pointer in the generated Go types.

For #66

Co-authored-by: Suzy Mueller <suzmue@golang.org>
  • Loading branch information
corneliusweig and suzmue committed Dec 6, 2022
1 parent cca6a33 commit c3d6893
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
19 changes: 12 additions & 7 deletions cmd/gentypes/gentypes.go
Expand Up @@ -62,10 +62,10 @@ func goFieldName(jsonPropName string) string {
// parsePropertyType takes the JSON value of a property field and extracts
// the Go type of the property. For example, given this map:
//
// {
// "type": "string",
// "description": "The command to execute."
// },
// {
// "type": "string",
// "description": "The command to execute."
// },
//
// It will emit "string".
func parsePropertyType(propValue map[string]interface{}) string {
Expand Down Expand Up @@ -132,8 +132,8 @@ func parsePropertyType(propValue map[string]interface{}) string {
//
// Example:
//
// "allOf": [ { "$ref": "#/definitions/ProtocolMessage" },
// {... type description ...} ]
// "allOf": [ { "$ref": "#/definitions/ProtocolMessage" },
// {... type description ...} ]
//
// Returns base type ProtocolMessage and a map representing type description.
// If there is no "allOf", returns an empty baseTypeName and descMap itself.
Expand Down Expand Up @@ -318,8 +318,13 @@ func emitToplevelType(typeName string, descJson json.RawMessage) string {
} else {
jsonTag += ",omitempty\"`"
}

if typeName == "Breakpoint" && goType == "Source" {
// Make the Source field in Breakpoint a pointer since a DAP client may distinguish
// between zero and nil source values.
goType = "*" + goType
}
fmt.Fprintf(&b, "\t%s %s %s\n", goFieldName(propName), goType, jsonTag)

}
}

Expand Down
20 changes: 10 additions & 10 deletions schematypes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c3d6893

Please sign in to comment.