google / google/go-dap

type generator: Use helper to identify duplicate fields to skip in message hierarchies

Open
#6 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
140
Forks
29
PR merge metrics
No merged PRs in 30d

Description

Move the logic from the long function that generates the go type into a helper with good function and inline comments. Possible names: shouldEmitField(), skipField()

Some fields are redefined in hierarchical types, but to ensure consistent translation between JSON & Go, we must limit each field to appear only once. We need skip two types of duplicate fields:
1) Parent definition defines field : type, child definition assigns a single value to that type => skip field in child
2) Parent definition defines field : "any", child definitions refines the type to something concrete => skip field in parent
NOTE: in case non-message types define the same

Programatic detection of these is tricky since we process one type at a time, so for now we just hardcode known fields/type pairs that fall into the above categories. Comments to document these cases will help.
"type" - use in ProtocolMessage, skip assignments in children (1)
"command" - use in Request and Response, skip assignments in children (1)
"event" - use in Event, skip assignments in all children (1)
"arguments" - skip any type in Request, use specific types in children (2)
"body" - skip any type in Response and Event, use specific types in children (2)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.