lsp
lsp copied to clipboard
Generate types from metamodel
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 thanMaybe 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:
- 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.
- 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.
@thomasjm @drsooch might be of interest
@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!
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 theGenerated
module.
- The easiest way to review the generated code at the moment is either to build the haddock or to use
- 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
- There is some new stuff in
- 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.
@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.
My take is that you should just do whatever you need to do. We'll figure out a way to adapt downstream
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.
Also not sure why the operator-like constructors appear like this on my Haddock. It seems to just be for Record Fields
Any update here? I'm going to address some lsp-test parts, some new features from 3.16 spec attracted me.
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...
Closing in favour of https://github.com/haskell/lsp/pull/478