Example language server (LSP) implementation for a toy language
Haskell
60
23 commits
updated Jul 21, 2021
Language server protocol example for a toy language implemented in Haskell, using the lsp Haskell library under the hood.
The "language" itself is very minimal to keep the implementation simple, but the LSP support aims to be somewhat realistic.
Syntax highlighting was not supported by the Language Server Protocol when
this was originally written... which is quite a serious instance of What. The. Fuck.
Apparently semantic highlighting finally comes with 3.16, but lsp does not
support that yet.
Instead, we have rudimentary syntax highlighting (in VS Code only) via TextMate grammars, which are an abomination on earth if I've seen one...
Our toy language consists of top-level declarations. Each declaration starts on a new line, and has the format:
indentifier : type = expression
There are three built-in types:
BoolNatColorExpressions are built up from literal constants, variables, a built-in infix operator
(plus), and can use parentheses. Declarations are checked against the type.
For colors, we have a fixed list of pre-defined colors. Color names are
prefixed by a hash # character.
the_truth : Bool = True
the_lie : Bool = the_truth
one : Nat = 1
fiftyfive : Nat = 50 + 4 + one
too_big : Nat = 12345
bad_number : Nat = (((666)))
ugly_col : Color = #black
nice_col : Color = #rainbow
lsp and megaparsec:$ cabal install lsp
$ cabal install megaparsec
ToyLang-IDE.exe and put it somewhere in the path:$ cabal install
npm (if not already installed)$ npm i vscode-languageclient
.toy, otherwise nothing will happen!You should see something like this:

To permanently install the extension, copy the whole project into the extension folder (?):
%USERPROFILE%\.vscode\extensions~/.vscode/extensions23 commits
Haskell
98.5%
JavaScript
1.5%
Example language server (LSP) implementation for a toy language
Haskell
60
23 commits
updated Jul 21, 2021
Language server protocol example for a toy language implemented in Haskell, using the lsp Haskell library under the hood.
The "language" itself is very minimal to keep the implementation simple, but the LSP support aims to be somewhat realistic.
Syntax highlighting was not supported by the Language Server Protocol when
this was originally written... which is quite a serious instance of What. The. Fuck.
Apparently semantic highlighting finally comes with 3.16, but lsp does not
support that yet.
Instead, we have rudimentary syntax highlighting (in VS Code only) via TextMate grammars, which are an abomination on earth if I've seen one...
Our toy language consists of top-level declarations. Each declaration starts on a new line, and has the format:
indentifier : type = expression
There are three built-in types:
BoolNatColorExpressions are built up from literal constants, variables, a built-in infix operator
(plus), and can use parentheses. Declarations are checked against the type.
For colors, we have a fixed list of pre-defined colors. Color names are
prefixed by a hash # character.
the_truth : Bool = True
the_lie : Bool = the_truth
one : Nat = 1
fiftyfive : Nat = 50 + 4 + one
too_big : Nat = 12345
bad_number : Nat = (((666)))
ugly_col : Color = #black
nice_col : Color = #rainbow
lsp and megaparsec:$ cabal install lsp
$ cabal install megaparsec
ToyLang-IDE.exe and put it somewhere in the path:$ cabal install
npm (if not already installed)$ npm i vscode-languageclient
.toy, otherwise nothing will happen!You should see something like this:

To permanently install the extension, copy the whole project into the extension folder (?):
%USERPROFILE%\.vscode\extensions~/.vscode/extensions23 commits
Haskell
98.5%
JavaScript
1.5%