Language Server Indexing Format Implementation for JSonnet
Language Server Index Format
The purpose of the Language Server Index Format (LSIF) is to define a standard format for language servers or other programming tools to dump their knowledge about a workspace. This dump can later be used to answer language server LSP requests for the same workspace without running the language server itself. Since much of the information would be invalidated by a change to the workspace, the dumped information typically excludes requests used when mutating a document. So, for example, the result of a code complete request is typically not part of such a dump.
A first draft specification can be found here.
JSonnet is a data templating language related to JSON.
In true open-source spirit the implementation is made from these parts:
The protocol.go code was borrowed and modified from lsif-go.
The LSIF dumper is a modification of indexer.go from lsif-go.
The scope implementation is a modification of go.types.Scope.
Many thanks to the creators of these.
This was put together quickly to learn LSIF and JSonnet. It is missing many features, for example hover results, documentation comments (parser currently discards comments), error handling, the standard library is not covered. It has not seen code reviews, so it's highly likely that there are bugs, omissions and oversights. It can serve as a starting point for more production-ready implementations for JSonnet or other languages.
- Build the
cmd/lsif-jsonnetcli the usual way with Go.
- The cli mimics the flags of the
jsonnetcli, so you can specify
libsonnetsearch paths with
-Jand the output file with
- Run the cli on your jsonnet file and generate an LSIF data file.
- You can use the generated LSIF data file in VSCode with the LSIF plugin or when running a Sourcegraph instance. Feel free to fork and use the test-jsonnet-lsif repo as your test code.
antlr -Dlanguage=Go -o parser Jsonnet.g4
Testing and validating LSIF output
lsif-util validate data.lsif
lsif-util visualize data.lsif --distance 2 | dot -Tpng -o image.png