Skip to content
LSIF generator for JSonnet
Go ANTLR Jsonnet
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd/lsif-jsonnet
dumper
parser
protocol
refs
test_data
types
.gitignore
Jsonnet.g4
LICENSE
README.md
go.mod
go.sum

README.md

Language Server Indexing Format Implementation for JSonnet

🚨 This implementation is still in very early stage and follows the latest LSIF specification closely.

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

JSonnet is a data templating language related to JSON.

Implementation

In true open-source spirit the implementation is made from these parts:

  • The parser is generated by Antlr4 from a grammar file modified from this Github Gist.

  • 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.

Status

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.

Usage

  • Build the cmd/lsif-jsonnet cli the usual way with Go.
  • The cli mimics the flags of the jsonnet cli, so you can specify libsonnet search paths with -J and the output file with -o.
  • 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.

Re-generate parser

After installing Antlr4 and the Go target you can run this command from the repo root:

antlr -Dlanguage=Go -o parser Jsonnet.g4

Testing and validating LSIF output

lsif-util is a commandline tool for validating the generated LSIF data syntactically. It also supports producing dot graphs that can be turned into PNG images with dot.

  • Validate: lsif-util validate data.lsif
  • Visualize: lsif-util visualize data.lsif --distance 2 | dot -Tpng -o image.png
You can’t perform that action at this time.