lsp icon indicating copy to clipboard operation
lsp copied to clipboard

Generate types from metamodel

Open michaelpj opened this issue 2 years ago • 7 comments

This generates all the LSP types from the LSP metamodel, a new machine-readable format they have produced.

This requires a pretty formidable amount of TH, but in return we get a hopefully much better maintenance process, and we won't always be behind or wrong as we have been. There are also some nice touches, like on GHC >9.2 we can now actually attach doucmentation to things we generate with TH, so we can transfer all the documentation from the metamodel to Haddock.

This is going to result in a lot of churn, enough so that I think it should be a new top-major version of lsp-types. In particular:

  • Various inconsistencies with the spec got fixed.
  • We aim for scrupulously matching the spec, even when that is weird, so there's a lot more A |? Null rather than Maybe A than there used to be.
  • The new version makes heavy use of anonymous records to handle the anonymous structure literals in the spec.
  • I took a fairly heavy-handed approach to avoiding name clashes in a reasonably future-proof way, but that means that a bunch of names changed, notably the constructors of Method/SMethod.

This still needs a bunch of work:

  • [ ] lsp-test tests are broken for some reason
  • [ ] More documentation and tidying in CodeGen
  • [ ] Changelog
  • [ ] Explain how to update the metamodel in the README
  • [ ] Tidy up the generated documentation so that links go to the generated types not the LSP spec.
  • [ ] Ensure everything builds on all versions of GHC we support.

Plus a bunch of other TODOs in the code. Any help would be welcome, but here are the top things I'm interested in feedback on:

  1. How does the new version look? Is the organization okay? I'll try and get some Haddock with the new documentation in place soonish so people can look at that without building it.
  2. The gnarly TH. Anyone who wants to dive in is more than welcome, it's not too bad but it would be nice if we could figure out a way to make it less gnarly.

michaelpj avatar Sep 19 '22 21:09 michaelpj

@thomasjm @drsooch might be of interest

michaelpj avatar Sep 19 '22 21:09 michaelpj

@sjakobi I think you're the main maintainer of the dhall language server, which is one of the main non-HLS users of this package that I know of. I'd really appreciate your thoughts!

michaelpj avatar Sep 21 '22 11:09 michaelpj

Guide for reviewers:

  • Metamodel stuff is in the Metamodel hierarchy, including the types for reading the metamodel and the code generation itself, which is the most gnarly part
    • The easiest way to review the generated code at the moment is either to build the haddock or to use -ddump-splices on the Generated module.
  • Most of the rest of the Language.LSP.Types hierarchy is just a cut down version of what was there before due to much of it being generated
    • There is some new stuff in Message to handle some typed/untyped versions of things
  • Everything in the rest of the project is just adapting to the changes. Might be interesting to take a glance at to see the sort of changes that this will cause.

michaelpj avatar Sep 21 '22 13:09 michaelpj

@sjakobi I think you're the main maintainer of the dhall language server, which is one of the main non-HLS users of this package that I know of. I'd really appreciate your thoughts!

Unfortunately, I'm not very familiar with the dhall-lsp-server internals at all – I've mostly been bumping bounds. Maybe @Gabriella439 has thoughts on this change.

sjakobi avatar Sep 26 '22 11:09 sjakobi

My take is that you should just do whatever you need to do. We'll figure out a way to adapt downstream

Gabriella439 avatar Sep 26 '22 23:09 Gabriella439

I honestly, don't think there is much to change. The TH generation seems sensible, I don't think there's much to change honestly. Codegen is pretty much straightforward, no matter what language you are using. I made some general code nit picks that honestly you can just ignore. There were one or two actual suggestions that I think are worth it. Otherwise lgtm.

drsooch avatar Oct 07 '22 00:10 drsooch

operators Also not sure why the operator-like constructors appear like this on my Haddock. It seems to just be for Record Fields

drsooch avatar Oct 07 '22 01:10 drsooch

Any update here? I'm going to address some lsp-test parts, some new features from 3.16 spec attracted me.

July541 avatar Mar 19 '23 04:03 July541

I have a partially-rewritten version that generates Haskell source instead. I wasn't able to get this version to work with GHC 9, and the thought of trying to make it work with multiple GHC versions made me scared. So I decided to switch to generating source. I need to finish it, basically...

michaelpj avatar Mar 22 '23 18:03 michaelpj

Closing in favour of https://github.com/haskell/lsp/pull/478

michaelpj avatar May 19 '23 15:05 michaelpj