Skip to content

Commit

Permalink
Remove queries for the old nvim-treesitter
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Mar 14, 2024
1 parent 58a60a4 commit 733d744
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 582 deletions.
56 changes: 19 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# tree-sitter-just

WIP: Tree-sitter grammar for Justfiles ([casey/just](https://github.com/casey/just))
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.
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:

Expand All @@ -19,12 +22,16 @@ 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
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 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({})`)
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 = {
Expand All @@ -38,13 +45,11 @@ require("nvim-treesitter.parsers").get_parser_configs().just = {
}
```

Don't forget to `:TSInstall` after adding this. With this method you do not have to add this repo as a plugin.
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"}
```
Please note that the nightly version of `nvim-treesitter`, at least since
`5b90ea2abaa4303b9205b5c9002a8cdd0acd11a5` (2024-01-19).

## Contributing

Expand Down Expand Up @@ -76,7 +81,9 @@ 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.
command to explore the resulting parse tree, and
[`:Inspect`](https://neovim.io/doc/user/lua.html#%3AInspect) to view highlight
groups.

## Quirks of Just

Expand All @@ -103,28 +110,3 @@ 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)
221 changes: 29 additions & 192 deletions build-flavored-queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from glob import glob
from pathlib import Path


REPLACEMENTS_HELIX = []
REPLACEMENTS_ZED = []
REPLACEMENTS_LAPCE = []
Expand All @@ -26,187 +25,6 @@
"#match?",
]

ALLOWED_CAPS_NVIM_OLD = {
"highlights.scm": [
"@comment",
"@comment.documentation",
"@error",
"@none",
"@preproc",
"@define",
"@operator",
"@punctuation.delimiter",
"@punctuation.bracket",
"@punctuation.special",
"@string",
"@string.documentation",
"@string.regex",
"@string.escape",
"@string.special",
"@character",
"@character.special",
"@boolean",
"@number",
"@float",
"@function",
"@function.builtin",
"@function.call",
"@function.macro",
"@method",
"@method.call",
"@constructor",
"@parameter",
"@keyword",
"@keyword.coroutine",
"@keyword.function",
"@keyword.operator",
"@keyword.return",
"@conditional",
"@conditional.ternary",
"@repeat",
"@debug",
"@label",
"@include",
"@exception",
"@type",
"@type.builtin",
"@type.definition",
"@type.qualifier",
"@storageclass",
"@attribute",
"@field",
"@property",
"@variable",
"@variable.builtin",
"@constant",
"@constant.builtin",
"@constant.macro",
"@namespace",
"@symbol",
"@text",
"@text.strong",
"@text.emphasis",
"@text.underline",
"@text.strike",
"@text.title",
"@text.quote",
"@text.uri",
"@text.math",
"@text.environment",
"@text.environment.name",
"@text.reference",
"@text.literal",
"@text.literal.block",
"@text.todo",
"@text.note",
"@text.warning",
"@text.danger",
"@text.diff.add",
"@text.diff.delete",
"@tag",
"@tag.attribute",
"@tag.delimiter",
"@conceal",
"@spell",
"@nospell",
],
"injections.scm": [
"@injection.language",
"@injection.content",
"@comment",
],
"locals.scm": [
"@definition",
"@definition.constant",
"@definition.function",
"@definition.method",
"@definition.var",
"@definition.parameter",
"@definition.macro",
"@definition.type",
"@definition.field",
"@definition.enum",
"@definition.namespace",
"@definition.import",
"@definition.associated",
"@scope",
"@reference",
],
"folds.scm": [
"@fold",
],
"indents.scm": [
"@indent.begin",
"@indent.end",
"@indent.align",
"@indent.dedent",
"@indent.branch",
"@indent.ignore",
"@indent.auto",
"@indent.zero",
],
"textobjects.scm": [
"@attribute.inner",
"@attribute.outer",
"@function.inner",
"@function.outer",
"@class.inner",
"@class.outer",
"@conditional.inner",
"@conditional.outer",
"@loop.inner",
"@loop.outer",
"@call.inner",
"@call.outer",
"@block.inner",
"@block.outer",
"@parameter.inner",
"@parameter.outer",
"@regex.inner",
"@regex.outer",
"@comment.inner",
"@comment.outer",
"@assignment.inner",
"@assignment.outer",
"@return.inner",
"@return.outer",
"@frame.inner",
"@frame.outer",
],
}

ALLOWED_SETTINGS_NVIM_OLD = {
"injections.scm": [
"injection.combined",
"injection.language",
"injection.include-children",
]
}

# Old nvim-treesitter before updates
REPLACEMENTS_NVIM_OLD = [
# Changes to local captures
(r"@local.definition", r"@definition"),
(r"@local.reference[\w.]*", r"@reference"),
(r"@local.scope", r"@scope"),
# Changes to highlight queries
(r"@comment.line", r"@comment"),
(r"@constant.builtin.boolean", r"@boolean"),
(r"@constant.character.escape", "@string.escape"),
(r"@keyword.control.conditional", r"@conditional"),
(r"@keyword.control.import", r"@keyword"),
(r"@keyword.module", r"@keyword"),
(r"@keyword.directive", r"@comment"),
(r"@variable.parameter", r"@parameter"),
# Changes to indent queries
(r"@indent\s+@extend", r"@indent.begin"),
# Changes to textobject queries
(r"(@[\w.]+\.)inside", r"\1inner"),
(r"(@[\w.]+\.)around", r"\1outer"),
# nvim uses `var` rather than `variable`
(r"(@[\w.]+)\.variable", r"\1.var"),
]

ALLOWED_CAPS_NVIM = {
"highlights.scm": [
"@variable",
Expand Down Expand Up @@ -312,7 +130,34 @@
"@indent.auto",
"@indent.zero",
],
"textobjects.scm": ALLOWED_CAPS_NVIM_OLD["textobjects.scm"],
"textobjects.scm": [
"@attribute.inner",
"@attribute.outer",
"@function.inner",
"@function.outer",
"@class.inner",
"@class.outer",
"@conditional.inner",
"@conditional.outer",
"@loop.inner",
"@loop.outer",
"@call.inner",
"@call.outer",
"@block.inner",
"@block.outer",
"@parameter.inner",
"@parameter.outer",
"@regex.inner",
"@regex.outer",
"@comment.inner",
"@comment.outer",
"@assignment.inner",
"@assignment.outer",
"@return.inner",
"@return.outer",
"@frame.inner",
"@frame.outer",
],
}

ALLOWED_SETTINGS_NVIM = {
Expand Down Expand Up @@ -460,21 +305,13 @@

# (rname, eplacements, allowed caps, base path) mappings to create a flavor
FLAVOR_MAPPINGS = [
(
"old NeoVim",
"NVIM-OLD",
REPLACEMENTS_NVIM_OLD,
ALLOWED_CAPS_NVIM_OLD,
ALLOWED_SETTINGS_NVIM_OLD,
Path("queries") / "just",
),
(
"new NeoVim",
"NVIM",
REPLACEMENTS_NVIM,
ALLOWED_CAPS_NVIM,
ALLOWED_SETTINGS_NVIM,
Path("queries-flavored") / "nvim-next",
Path("queries") / "just",
),
(
"Helix",
Expand Down
10 changes: 0 additions & 10 deletions queries-flavored/nvim-next/folds.scm

This file was deleted.

Loading

0 comments on commit 733d744

Please sign in to comment.