ligo/tools/lsp
2020-08-11 12:32:09 +04:00
..
camligo Initial commit of LIGO tooling 2020-08-11 12:31:49 +04:00
pascaligo Separate the namespaces for search 2020-08-11 12:32:08 +04:00
squirrel Remove unused traverseOnly 2020-08-11 12:32:09 +04:00
README.md Improve documentation 2020-08-11 12:32:03 +04:00

What

A language server for all three dialects of LIGO.

Design choices

The server contains 2 big parts:

  1. Grammars
  2. Server itself.

Grammars are in separate folders, in form of tree-sitter grammars. They are compiled via tree-sitter generate command in their respective folder.

Then they are linked as parser.c file with GHC toolchain. Because GHCi REPL is unable to link from outside of project folder, the parser.c is symlinked into vendor/ directory.

Right now only one parser is linked there; the name of symlink should be changed in future.

Server part invokes the TS-parser and then constructs a tree of haskell datatypes from the TS-tree. Then it is fed into AST.Parser (name will be changed), which constructs an universal AST from the tree of the respective language.

Parser uses the root Parser module which provides the combinators and monad to deal with ParseTree, produced from TS output.

The tree it produces has:

  1. An ASTInfo at each node, which contains the Range of that node and preceeding comments. Sadly, but the comments after all the code in the module are lost.
  2. Some structure;
  3. Ability to be just an Error instead of all above. An error contains Range as well.

It is possible to update the scopes in the tree, using updateTree function, which is a specialised custom traverse.

It is also possible to get the zipper-like chain of trees, covering some node, in ascending order - using spineTo function. If you have already pinned the scopes, you can just take first one and pull the scope out of it. Unless it is an Error node. We probably need th error nodes to be Functors as well as any other structures used to build the tree.

On top of all that is an event loop for handling messages from some lsp-client.

For developers

To compile and run, the following tools are needed:

  1. tree-sitter-clr (the Node.js one was usied during development)
  2. optionally, nix package manager
  3. haskell-stack

First, you need to generate the parser.c. For that, do

cd tools/lsp/pascaligo
tree-sitter generate

Then

cd ../squirrel
stack install

The executable is a language server.