-
Notifications
You must be signed in to change notification settings - Fork 283
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
Fix #1138 - vscode-python - Make 'author' parsing less strict #1141
Conversation
module Author = { | ||
[@deriving show] | ||
type t = option(string); | ||
|
||
let of_yojson_exn = | ||
fun | ||
| `String(v) => Some(v) | ||
| v => | ||
Yojson.Safe.( | ||
{ | ||
Util.member("name", v) |> Util.to_string_option; | ||
} | ||
); | ||
|
||
let of_yojson = json => | ||
tryToResult(~msg="Error parsing author", () => of_yojson_exn(json)); | ||
|
||
let to_yojson = _author => `Null; | ||
}; |
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.
Wow, that's a lot of ceremony for what's basically just a single function in a combinator-based API.
I wonder if we should consider using ocaml-decoders
instead. There are of course other benefits too, like decoding directly into the data structure we actually want, rather than using an intermediary representation for the JSON structure and having another layer of conversion code.
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'm open to exploring it! It would be nice to streamline it - we have a lot of one-off JSON parsing logic like this all over.
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.
Do you have one which is just converted into a different data structure? I could convert that to ocaml-decoders
to get a taste and show you how it's look.
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 imagine there are probably a ton of opportunities here: https://github.com/onivim/oni2/blob/5d88ef8e359789c650698ba02e2c5daf7ad664a8/src/Extensions/ExtHostProtocol.re
That handles a lot of the JSON serialization <-> deserialization coming in/out of the extension host. A great place to simplify!
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'll bring in this change for now, since it gets us to the next layer of issues with vscode-python
- but interested to see how we can improve with ocaml-decoders
.
Fixes #1138