Slim parser for tree-sitter.
warning, this code is at it's alpha stage.
When this project began, no Slim parser was available. While an alternative now exists, I chose to continue because my approach differs.
This project aims to:
- Support all slim features except custom syntax configurations.
- Follow tree-sitter guidelines.
- Enable static analysis, Ruby linting, and support for other embedded languages through injections.
Performance will improve once the syntax tree stabilizes. That said, the plugin is functional and lag-free on modern computers.
neovim with Lazy and nvim-treesitter.
Running the following command to build an install the parser:
tree-sitter generate && \
tree-sitter build -o slim.so && \
cp slim.so ~/.local/share/nvim/lazy/nvim-treesitter/parser/ && \
mkdir -p ~/.local/share/nvim/lazy/nvim-treesitter/queries/slim && \
cp queries/* ~/.local/share/nvim/lazy/nvim-treesitter/queries/slim/
Add the following sections to ~/.config/helix/languages.toml
[[language]]
name = "slim"
scope = "source.slim"
file-types = [ "slim" ]
comment-tokens = [ "/", "/!" ]
[[grammar]]
name = "slim"
source = { git = "https://gitlab.com/theoreichel/tree-sitter-slim", rev = "REV" }
Update REV
with the last commit hash SHA.
Copy queries found in the queries
folder of this repo to ~/.config/helix/runtime/queries/
.
The run helix --gramar fetch
and you should be good to go. Use helix --health
to check the languages capabilities.
The syntax tree may evolve until the library stabilizes. Share your needs or feedback regarding a stable syntax tree.
All queries are provided: folds, highlights, indent, injections and locals.
Tests are based on the slim documentation, not its parse code. Test files match documentation chapters, with additional files for extensive custom tests and unsupported syntax.
Syntax highlighting follows tree-sitter's recommendations. Since Slim isn't a traditional language with variables or functions, some liberties were taken.
The unsupported.txt
test file lists unsupported features:
Won't be fixed:
The custom scanner is based on the tree-sitter python scanner, modified for slim. Future refactoring will improve performance and align with tree-sitter recommendations.
Example: Parsing 12k lines under 35ms on a Ryzen 7040
> wc -cl views/**/*.slim
...
12262 531233 total
> time tree-sitter parse --timeout 1000 views/**/*.slim -sq
Total parses: 301; successful parses: 301; failed parses: 0; success percentage: 100.00%; average speed: 20701 bytes/ms
________________________________________________________
Executed in 32.25 millis fish external
usr time 28.60 millis 393.00 micros 28.21 millis
sys time 3.46 millis 369.00 micros 3.09 millis
The main repository is on GitLab. Issues and PRs on GitHub will be ignored.
Feedback and merge requests are welcome! To test the parser with a slim codebase, clone this repo and run:
tree-sitter generate
Then example, test all slim file in a rails project:
tree-sitter parse --timeout 1000 views/**/*.slim -sq
While developing with neovim, use this handy command:
nvim your_file.slim +"InspectTree"