# tree-sitter-just WIP: Tree-sitter grammar for Justfiles ([casey/just](https://github.com/casey/just)) To use treesitter based highlighting, folds etc. the queries need to be added to the runtimepath, until I get a PR into `nvim-treesitter/nvim-treesitter` you can install this repo as a plugin using Plug/packer/manual clone etc. This plugin also adds a simple `ftdetect` plugin for detecting justfiles. Packer: ```lua use "IndianBoy42/tree-sitter-just" ``` Plug ```vimscript Plug 'IndianBoy42/tree-sitter-just' ``` Manual ``` git clone https://github.com/IndianBoy42/tree-sitter-just ~/.local/share/nvim/site/pack/tree-sitter-queries/start/tree-sitter-just ``` You can then do `require('tree-sitter-just').setup({})` to register the parser with tree-sitter. You can then do `TSInstall`/`TSUpdate` as usual to install the parser You can also add the parser manually using (This is similar to what is done in `require"tree-sitter-just".setup({})`) ```lua require("nvim-treesitter.parsers").get_parser_configs().just = { install_info = { url = "https://github.com/IndianBoy42/tree-sitter-just", -- local path or git repo files = { "src/parser.c", "src/scanner.c" }, branch = "main", -- use_makefile = true -- this may be necessary on MacOS (try if you see compiler errors) }, maintainers = { "@IndianBoy42" }, } ``` Don't forget to `:TSInstall` after adding this. With this method you do not have to add this repo as a plugin. If you run into problems relating to C++ 11 features, try including this in your setup (you may have to `brew install gcc@11`): ```lua require"nvim-treesitter.install".compilers = {"gcc-11"} ``` ## Contributing The easiest way to get started is, fittingly, with [`just`](https://github.com/casey/just). ```sh # Make sure dependencies are available just setup # Create autogenerated files and run tests just test # Create autogenerated files without testing just gen # Check linting rules just lint # Apply formatting just fmt ``` Note that `just lint` and `just fmt` must pass for all changes. You can verify these automatically before committing by running `just pre-commit-install`. All our queries are in `queries-src`. This directory is what gets tested by tree-sitter, and should be usable by helix. To generate queries for NeoVim, run `./build-flavored-queries.py` (this is run as part of `npm run gen`). You can use the [`:InspectTree`](https://neovim.io/doc/user/treesitter.html#%3AInspectTree) command to explore the resulting parse tree, and [`:Inspect`](https://neovim.io/doc/user/lua.html#%3AInspect) to view highlight groups. ## Quirks of Just Just currently doesn't seem to support comments between attributes or within if statements, so we do not either. ```just [private] # hello! [no-cd] foo: ``` ```just foo := if true { # nope! "abcd" } ``` ## Test Information The tests directory contains "corpus" tests that are checked for syntax, as well as "highlight" tests that check the result. The "highlight" test directory includes some test files generated by the fuzzer that aren't always human readable. ## TODO - [x] Implement a basic parser that is able to understand all features of Justfiles - [x] Implement support for highlighting using `nvim-treesitter` ([reference](https://tree-sitter.github.io/tree-sitter/syntax-highlighting), `highlights.scm`) - [x] Write the queries - [x] Implement locals queries - [x] Implement queries for textobjects compatible with [`nvim-treesitter/nvim-treesitter-textobjects`](https://github.com/nvim-treesitter/nvim-treesitter-textobjects) - [x] Write the queries - [x] @block.inner|outer (recipe) - [x] @function.inner|outer (recipe) - [x] @call.inner|outer (dependencies) - [x] @comment.outer - [x] @parameter.inner|outer - [x] @conditional.inner|outer - [x] @statement.outer (recipe line or one variable) - [x] Definitions and references - [ ] Scopenames - [ ] Implement support for indentation using `nvim-treesitter` - [ ] Write the queries - [x] Implement support for code folding using `nvim-treesitter` (`folds.scm`) - [x] Write the queries - [ ] Write Tests - [x] Highlight the fish/bash/etc inside recipes (use tree-sitter injections) - [ ] Fix weirdness around trailing whitespace (don't leave trailing whitespace after the recipe header)