-
Notifications
You must be signed in to change notification settings - Fork 123
feat: json-records content type support #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formatting & content type code looks basically good to go I think, but proper language support would be helpful if we can do it.
if (secondToLastChar === '}') { | ||
types.add('json-records'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be an alternative to JSON - not in addition. It's a bit confusing for both JSON & JSON records to appear in the list, and I think they are mutually exclusive because AFAICT 0x1e
can never appear within normal valid JSON content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -127,6 +127,40 @@ export const Formatters: { [key in ViewableContentType]: Formatter } = { | |||
} | |||
} | |||
}, | |||
'json-records': { | |||
language: 'json', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this approach, we're parsing & converting the JSON records to a sort-of equivalent JSON array, and then just showing that as JSON content.
This sort of works but it would be better to create a separate language I think. There's a few problems here I can see already:
- It's not an accurate representation of the content - it looks like you've received an array
[ ... ]
but you haven't really. - When you switch between this & normal JSON format on the same content, the formatting changes but the errors don't seem to reset (although, as in my other comment, we can fix this by just making JSON not appear in the dropdown) I think because they share the same
language
- Parsing & validation doesn't work properly - any parsing errors result in the content collapsing back to an
{}�{{...
unformatted string, which then just shows errors for the record separator characters (not the actual error in the content). We should be able to split & format the messages regardless of JSON parsing, and show nice errors inline.
Did you take a look at the XML support code? I think the same thing should be possible. If you want to look at Monaco's code for JSON support itself, the entrypoint is here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think the JSON-records
is a kind of variant of JSON, so I reused the json
language. Let me try to update this with a separate language
fixes httptoolkit/httptoolkit#772
This pull request introduces support for a new
json-records
content type, allowing for the parsing and formatting of JSON records separated by specific delimiters. Key changes include updates to content type handling, new utility functions, and enhancements to formatters for synchronous and asynchronous processing.Support for
json-records
content type:json-records
as a newViewableContentType
insrc/model/events/content-types.ts
, with associated mappings and logic for determining compatibility based on content structure. [1] [2] [3] [4]StreamMessage
class to identifyjson-records
content based on specific delimiters. [1] [2]Enhancements to formatters:
json-records
insrc/model/events/body-formatting.ts
to handle both synchronous and asynchronous parsing based on input size.json-records
formatter tosrc/services/ui-worker-formatters.ts
for asynchronous processing in worker threads.Utility function for buffer splitting:
splitBuffer
insrc/util/buffer.ts
to split aBuffer
into chunks using a specified separator, enabling efficient processing of JSON records.