Skip to content

Commit

Permalink
Update the query generator to support more flavors
Browse files Browse the repository at this point in the history
Add new nvim queries, as well as support for Zed and Lapce.
  • Loading branch information
tgross35 committed Mar 10, 2024
1 parent 0ddbe48 commit 1b9b10f
Show file tree
Hide file tree
Showing 36 changed files with 1,717 additions and 125 deletions.
575 changes: 545 additions & 30 deletions build-flavored-queries.py

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions queries-flavored/helix/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; File autogenerated by build-queries-nvim.py; do not edit

; Define collapse points

[
(recipe)
(string)
(external_command)
] @fold
(#trim! @fold)
143 changes: 143 additions & 0 deletions queries-flavored/helix/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
; File autogenerated by build-queries-nvim.py; do not edit

; This file specifies how matched syntax patterns should be highlighted

[
"export"
"import"
] @keyword.control.import

"mod" @keyword.directive

[
"alias"
"set"
"shell"
] @keyword

[
"if"
"else"
] @keyword.control.conditional

; Variables

(value (identifier) @variable)

(alias left: (identifier) @variable)

(assignment left: (identifier) @variable)

; Functions

(recipe_header name: (identifier) @function)

(dependency name: (identifier) @function)

(dependency_expression name: (identifier) @function)

(function_call name: (identifier) @function)

; Parameters

(parameter name: (identifier) @variable.parameter)

; Namespaces

(module name: (identifier) @namespace)

; Operators

[
":="
"?"
"=="
"!="
"=~"
"@"
"="
"$"
"*"
"+"
"&&"
"@-"
"-@"
"-"
"/"
":"
] @operator

; Punctuation

[ "," ] @punctuation.delimiter

[
"{"
"}"
"["
"]"
"("
")"
"{{"
"}}"
] @punctuation.bracket

[ "`" "```" ] @punctuation.special

; Literals

(boolean) @constant.builtin.boolean

[
(string)
(external_command)
] @string

(escape_sequence) @constant.character.escape

; Comments

; FIXME: add once all editors support it
(comment) @comment.line

(shebang) @comment

; highlight known settings (filtering does not always work)
(setting
left: ((identifier) @keyword
(#any-of? @keyword
"allow-duplicate-recipes"
"dotenv-filename"
"dotenv-load"
"dotenv-path"
"export"
"fallback"
"ignore-comments"
"positional-arguments"
"shell"
"tempdi"
"windows-powershell"
"windows-shell"
)))

; highlight known attributes (filtering does not always work)
(attribute
((identifier) @attribute
(#any-of? @attribute
"private"
"allow-duplicate-recipes"
"dotenv-filename"
"dotenv-load"
"dotenv-path"
"export"
"fallback"
"ignore-comments"
"positional-arguments"
"shell"
"tempdi"
"windows-powershell"
"windows-shell"
)))

; Numbers are part of the syntax tree, even if disallowed
(numeric_error) @error
11 changes: 11 additions & 0 deletions queries-flavored/helix/indents.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; File autogenerated by build-queries-nvim.py; do not edit

; This query
;
; Better documentation is in https://docs.helix-editor.com/guides/indent.html

[
(recipe)
(string)
(external_command)
] @indent @extend
74 changes: 74 additions & 0 deletions queries-flavored/helix/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
; File autogenerated by build-queries-nvim.py; do not edit

; FIXME: these are not compatible with helix due to precedence

; ================ Always applicable ================

((comment) @injection.content
(#set! injection.language "comment"))

(comment) @comment

; Highlight the RHS of `=~` as regex
((regex_literal (_) @injection.content)
(#set! injection.language "regex"))

; ================ Global defaults ================

; Default everything to be bash
(recipe_body
(#set! injection.language "bash")
(#set! injection.include-children)) @injection.content

(external_command
(command_body) @injection.content
(#set! injection.language "bash"))

; ================ Global language specified ================
; Global language is set with something like one of the following:
;
; set shell := ["bash", "-c", ...]
; set shell := ["pwsh.exe"]
;
; We can extract the first item of the array, but we can't extract the language
; name from the string with something like regex. So instead we special case
; two things: powershell, which is likely to come with a `.exe` attachment that
; we need to strip, and everything else which hopefully has no extension. We
; separate this with a `#match?`.
;
; Unfortunately, there also isn't a way to allow arbitrary nesting or
; alternatively set "global" capture variables. So we can set this for item-
; level external commands, but not for e.g. external commands within an
; expression without getting _really_ annoying. Should at least look fine since
; they default to bash. Limitations...
; See https://github.com/tree-sitter/tree-sitter/issues/880 for more on that.

(source_file
(setting "shell" ":=" "[" (string) @_langstr
(#match? @_langstr ".*(powershell|pwsh|cmd).*")
(#set! injection.language "powershell"))
[
(recipe
(recipe_body (#set! injection.include-children)) @injection.content)

(assignment
(expression (value (external_command (command_body) @injection.content))))
])

(source_file
(setting "shell" ":=" "[" (string) @injection.language
(#not-match? @injection.language ".*(powershell|pwsh|cmd).*"))
[
(recipe
(recipe_body (#set! injection.include-children)) @injection.content)

(assignment
(expression (value (external_command (command_body) @injection.content))))
])

; ================ Recipe language specified ================

; Set highlighting for recipes that specify a language
(recipe_body
(shebang (language) @injection.language)
(#set! injection.include-children)) @injection.content
32 changes: 32 additions & 0 deletions queries-flavored/helix/locals.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; File autogenerated by build-queries-nvim.py; do not edit

; This file tells us about the scope of variables so e.g. local
; variables override global functions with the same name

; Scope

(recipe) @local.scope

; Definitions

(alias left: (identifier) @local.definition.variable)

(assignment left: (identifier) @local.definition.variable)

(module name: (identifier) @local.definition.namespace)

(parameter name: (identifier) @local.definition.variable)

(recipe_header name: (identifier) @local.definition.function)

; References

(alias right: (identifier) @local.reference)

(function_call name: (identifier) @local.reference)

(dependency name: (identifier) @local.reference)

(dependency_expression name: (identifier) @local.reference)

(value (identifier) @local.reference)
15 changes: 15 additions & 0 deletions queries-flavored/helix/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; File autogenerated by build-queries-nvim.py; do not edit

(recipe
(recipe_body) @function.inside) @function.around

(parameters
((_) @parameter.inside . ","? @parameter.around)) @parameter.around

(dependency_expression
(_) @parameter.inside) @parameter.around

(function_call
arguments: (sequence (expression) @parameter.inside) @parameter.around) @function.around

(comment) @comment.around
10 changes: 10 additions & 0 deletions queries-flavored/lapce/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; File autogenerated by build-queries-nvim.py; do not edit

; Define collapse points

[
(recipe)
(string)
(external_command)
] @fold
(#trim! @fold)
Loading

0 comments on commit 1b9b10f

Please sign in to comment.