2.1 KiB
What
A language server for all three dialects of LIGO.
Design choices
The server contains 2 big parts:
- Grammars
- 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 GHC 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:
- An
ASTInfo
at each node, which contains theRange
of that node and preceeding comments. Sadly, but the comments after all the code in the module are lost. - Some structure;
- Ability to be just an
Error
instead of all above. An error containsRange
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 Functor
s
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:
- tree-sitter-clr (the Node.js one was usied during development)
- optionally, nix package manager
- 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.