Skip to content

Commit

Permalink
Improve highlighting for attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 4, 2024
1 parent a5e0069 commit 2677381
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 18 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ tree-sitter parse test/test.just

You can use the `nvim-treesitter/playground` plugin [from here](https://github.com/nvim-treesitter/playground), to explore the resulting parse tree. Use `TSPlaygroundToggle` to view the parse tree, and use `TSHighlightCapturesUnderCursor` 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"
}
```

## TODO

- [x] Implement a basic parser that is able to understand all features of Justfiles
Expand Down
2 changes: 1 addition & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ module.exports = grammar({
attribute: ($) =>
seq(
"[",
field("contents", comma_sep1(field("attribute", $.identifier))),
field("contents", comma_sep1(field("attr_item", $.identifier))),
"]",
$.eol,
),
Expand Down
6 changes: 3 additions & 3 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@


(attribute
attribute: ((identifier) @keyword
(#any-of? @keyword
attr_item: ((identifier) @attribute
(#any-of? @attribute
"private"
"allow-duplicate-recipes"
"dotenv-filename"
Expand All @@ -60,7 +60,7 @@
)))

(attribute
attribute: (identifier) @variable)
attr_item: (identifier) @variable)

(recipe_header
recipe_name: (identifier) @function)
Expand Down
4 changes: 2 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@
"members": [
{
"type": "FIELD",
"name": "attribute",
"name": "attr_item",
"content": {
"type": "SYMBOL",
"name": "identifier"
Expand All @@ -860,7 +860,7 @@
},
{
"type": "FIELD",
"name": "attribute",
"name": "attr_item",
"content": {
"type": "SYMBOL",
"name": "identifier"
Expand Down
2 changes: 1 addition & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"type": "attribute",
"named": true,
"fields": {
"attribute": {
"attr_item": {
"multiple": true,
"required": true,
"types": [
Expand Down
14 changes: 7 additions & 7 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ enum {
field_arguments = 1,
field_array = 2,
field_array_item = 3,
field_attribute = 4,
field_attr_item = 4,
field_braced_body = 5,
field_contents = 6,
field_default = 7,
Expand All @@ -779,7 +779,7 @@ static const char * const ts_field_names[] = {
[field_arguments] = "arguments",
[field_array] = "array",
[field_array_item] = "array_item",
[field_attribute] = "attribute",
[field_attr_item] = "attr_item",
[field_braced_body] = "braced_body",
[field_contents] = "contents",
[field_default] = "default",
Expand Down Expand Up @@ -864,10 +864,10 @@ static const TSFieldMapEntry ts_field_map_entries[] = {
{field_left, 1},
{field_right, 3},
[11] =
{field_attribute, 1},
{field_attr_item, 1},
[12] =
{field_attribute, 0, .inherited = true},
{field_attribute, 1, .inherited = true},
{field_attr_item, 0, .inherited = true},
{field_attr_item, 1, .inherited = true},
[14] =
{field_left, 0},
{field_right, 2},
Expand All @@ -879,8 +879,8 @@ static const TSFieldMapEntry ts_field_map_entries[] = {
{field_right, 2},
{field_right, 3},
[21] =
{field_attribute, 1},
{field_attribute, 2, .inherited = true},
{field_attr_item, 1},
{field_attr_item, 2, .inherited = true},
{field_contents, 2},
[24] =
{field_braced_body, 2, .inherited = true},
Expand Down
2 changes: 0 additions & 2 deletions test/corpus/recipes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ corge: foo (quux corge + banana)
(value
(identifier))))))
(recipe_body
(recipe_line
(text))
(recipe_line
(text)))))
(item
Expand Down
6 changes: 4 additions & 2 deletions test/highlight/recipes.just
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ grault abc="def":
# ^^^^ string
# ^ operator

[arguments]
a:
# FIXME: can't test these because we can't place comments between
[private]
[confirm, no-cd]
attributes:

0 comments on commit 2677381

Please sign in to comment.