commercialhaskell / stack-ide

Stack-based JSON interface to ide-backend
98 stars 23 forks source link

Refine protocol serialization #27

Closed mgsloan closed 9 years ago

mgsloan commented 9 years ago

I figure now is a good time to revisit the current protocol serialization, as stack-mode hasn't yet been updated to the one based on Aeson TH. The old protocol looked quite nice, but it used JsonGrammar. JsonGrammar is very cool, but not very battle hardened and tricky to get started with. By using Aeson TH we can avoid a lot of boilerplate.

We can get something closer to the old protocol by doing stuff like this, and adding record fields:

$(deriveJSON (defaultOptions
  { constructorTagModifier = fromMaybe (error "Expected Request prefix") . stripPrefix "Request"
  , sumEncoding = TaggedObject { tagFieldName = "request", contentsFieldName = "contents" }
  }) ''Request)

If we actually do this, then this particular naming pattern could be turned into a new TH function, so that we don't need a bunch of boilerplate.

Another part of this work on refining the serialization would be to add records labels.

chrisdone commented 9 years ago

This seems practically the same as the current invocation of derving JSON in the format of the fields. How does it differ?

mgsloan commented 9 years ago

Merely shorter constructor names, because it eliminates the common prefix. I've considered it a bit further, though, and the default aeson encoding is decent enough. I think record fields are probably still worthwhile, though.

chrisdone commented 9 years ago

I vote to leave the protocol format as it is and concentrate effort on having a mode that works reliably, until that point we have two birds in the bush and yet more time delaying this ever happening.

mgsloan commented 9 years ago

Agreed!