Contributing guide
Notes:
- Typos and small fix PRs are always welcome, no matter how small!
- For larger changes please create an issue to discuss it first
Dev process
-
Run tests with
test -
Re-generate LSP definitions with
generateLSP(if you changed any code inmetaorgeneratemodules, see below) -
Generate docs with
generateDocs, you should see the website in./website/folder -
Before pushing make sure you run
preCIwhich will- Reformat the code
- Run Scalafix
- Ensure your changes don't get tripped up by the boring, automatable steps of the build (like the ones mentioned above)
Structure
The project consists of 3 main modules
meta - which defines the meta-model of LSP specification
This module was essentially hand-crafted from the metaModel.schema.json file which you can find in the repository.
It defines what is a Request, Structure, OrType, etc. which are then used in the LSP specification itself.
It also defines json codecs and helper types to be able to parse the actual LSP specification from JSON.
generate - which converts LSP specification to Scala code
This module does all the heavy lifting required to massage the LSP spec into Scala-compatible domain model and subsequently Scala 3 code:
-
Apply type transformations
For example, convert anonymous structures into a named structure in the companion object
-
Define how types are rendered
i.e.
OrTypeis usually rendered as a Scala 3 Union, whereas a union with aNullcomponent will be rendered asOpt[A]whereAis a union type of remaining components -
Lay out JSON codecs to match both the
givensemantics of the language, and the API methods available in uPickle -
Render enumerations and type aliases
-
Selectively remove some types
For example,
LSPAnyis basically a JSON structure and there's no real reason to massage it (it's recursive, which makes things hard) so we need to replace it withujson.Valueeverywhere.
This module also defines a main class, which accepts a target path as an argument and, when run, generates all the LSP code in that location.
lsp - rendered LSP specification and runtime classes
The generated folder contains all the code generated by the generate module described above. Generated code is excluded from Scalafmt.
The rest of the code contains
- runtime datastructures required for LSP to run,
LSPBuilderto define Language Servers- integration with jsonrpclib
- runtime enumeration definitions
- some basic types (like
DocumentUrianduinteger) - specialised JSON codecs which are used as building blocks for more complex codecs in the generated code