Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lang): Update Nix grammar & improve queries #2472

Merged
merged 1 commit into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ indent = { tab-width = 2, unit = " " }

[[grammar]]
name = "nix"
source = { git = "https://github.com/cstrahan/tree-sitter-nix", rev = "50f38ceab667f9d482640edfee803d74f4edeba5" }
source = { git = "https://github.com/cstrahan/tree-sitter-nix", rev = "6b71a810c0acd49b980c50fc79092561f7cee307" }

[[language]]
name = "ruby"
Expand Down
54 changes: 31 additions & 23 deletions runtime/queries/nix/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
(comment) @comment

[
"if"
"if"
"then"
"else"
"let"
"inherit"
"in"
"rec"
"with"
"with"
"assert"
"or"
] @keyword

((identifier) @variable.builtin
Expand All @@ -21,61 +22,70 @@
(#is-not? local))

[
(string)
(indented_string)
(string_expression)
(indented_string_expression)
] @string

[
(path)
(hpath)
(spath)
(path_expression)
(hpath_expression)
(spath_expression)
] @string.special.path

(uri) @string.special.uri
(uri_expression) @string.special.uri

; boolean
((identifier) @constant.builtin.boolean (#match? @constant.builtin.boolean "^(true|false)$")) @constant.builtin.boolean
; null
((identifier) @constant.builtin (#eq? @constant.builtin "null")) @constant.builtin

(integer) @constant.numeric.integer
(float) @constant.numeric.float
(integer_expression) @constant.numeric.integer
(float_expression) @constant.numeric.float

(interpolation
"${" @punctuation.special
"}" @punctuation.special) @embedded

(escape_sequence) @constant.character.escape

(function
(function_expression
universal: (identifier) @variable.parameter
)

(formal
name: (identifier) @variable.parameter
"?"? @punctuation.delimiter)

(app
(select_expression
attrpath: (attrpath (identifier)) @variable.other.member)

(apply_expression
function: [
(identifier) @function
(select
(variable_expression (identifier)) @function
(select_expression
attrpath: (attrpath
attr: (attr_identifier) @function .))])

attr: (identifier) @function .))])

(unary
(unary_expression
operator: _ @operator)

(binary
(binary_expression
operator: _ @operator)

(attr_identifier) @variable.other.member
(inherit attrs: (attrs_inherited (identifier) @variable.other.member) )
(variable_expression (identifier) @variable)

(binding
attrpath: (attrpath (identifier)) @variable.other.member)

(identifier) @variable.other.member
nrdxp marked this conversation as resolved.
Show resolved Hide resolved

(inherit_from attrs: (inherited_attrs attr: (identifier) @variable.other.member) )

[
";"
"."
","
"="
] @punctuation.delimiter

[
Expand All @@ -85,6 +95,4 @@
"]"
"{"
"}"
] @punctuation.bracket

(identifier) @variable
] @punctuation.bracket
33 changes: 20 additions & 13 deletions runtime/queries/nix/indents.scm
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@

the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
[
; "function",
(bind)
(assert)
(with)
; Bracket like
(let)
(if)

(attrset)
(list)
(indented_string)
(rec_attrset)
(let_attrset)
(parenthesized)
] @indent
(list)

[
"}"
"]"
] @outdent
Comment on lines -15 to -18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably keep these unless the injects work better without them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure exactly why tbh, but I was getting extra indents with the previous definitions. These ones seem to work more accurately

; Binding
(bind)
(inherit)
(inherit_from)
(formal)

; Binary operations
(binary)
(has_attr)
(select)
(app)

; Conditional
(if)
] @indent