Skip to content

Commit

Permalink
Add !shebang to injection queries to improve match precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Mar 14, 2024
1 parent 613b3fd commit d0a73f0
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 94 deletions.
3 changes: 2 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ module.exports = grammar({
recipe_body: ($) =>
seq(
$._indent,
optional(seq($.shebang, $._newline)),
optional(seq(field("shebang", $.shebang), $._newline)),
repeat(choice(seq($.recipe_line, $._newline), $._newline)),
$._dedent,
),
Expand All @@ -293,6 +293,7 @@ module.exports = grammar({

recipe_line_prefix: (_) => choice("@-", "-@", "@", "-"),

// Any shebang. Needs a named field to apply injection queries correctly.
shebang: ($) => seq("#!", choice($._shebang_with_lang, $._opaque_shebang)),

// Shebang with a nested `language` token that we can extract
Expand Down
8 changes: 6 additions & 2 deletions queries-flavored/helix/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

Expand Down Expand Up @@ -50,7 +51,9 @@
(#set! injection.language "powershell"))
[
(recipe
(recipe_body (#set! injection.include-children)) @injection.content)
(recipe_body
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -65,7 +68,8 @@
[
(recipe
(recipe_body
(#set! injection.include-children)) @injection.content)
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand Down
10 changes: 7 additions & 3 deletions queries-flavored/lapce/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

Expand Down Expand Up @@ -50,7 +51,9 @@
(#set! injection.language "powershell"))
[
(recipe
(recipe_body (#set! injection.include-children)) @injection.content)
(recipe_body
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -65,7 +68,8 @@
[
(recipe
(recipe_body
(#set! injection.include-children)) @injection.content)
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -79,7 +83,7 @@
; Set highlighting for recipes that specify a language, using the exact name by default
(recipe_body ;
(shebang ;
(language) @injection.language) ;
(language) @injection.language)
(#not-any-of? @injection.language "python3" "nodejs" "node")
(#set! injection.include-children)) @injection.content

Expand Down
10 changes: 7 additions & 3 deletions queries-flavored/nvim-next/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

Expand Down Expand Up @@ -48,7 +49,9 @@
(#set! injection.language "powershell"))
[
(recipe
(recipe_body (#set! injection.include-children)) @injection.content)
(recipe_body
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -63,7 +66,8 @@
[
(recipe
(recipe_body
(#set! injection.include-children)) @injection.content)
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -77,7 +81,7 @@
; Set highlighting for recipes that specify a language, using the exact name by default
(recipe_body ;
(shebang ;
(language) @injection.language) ;
(language) @injection.language)
(#not-any-of? @injection.language "python3" "nodejs" "node")
(#set! injection.include-children)) @injection.content

Expand Down
10 changes: 7 additions & 3 deletions queries-flavored/zed/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

Expand Down Expand Up @@ -50,7 +51,9 @@
(#set! injection.language "powershell"))
[
(recipe
(recipe_body (#set! injection.include-children)) @injection.content)
(recipe_body
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -65,7 +68,8 @@
[
(recipe
(recipe_body
(#set! injection.include-children)) @injection.content)
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -79,7 +83,7 @@
; Set highlighting for recipes that specify a language, using the exact name by default
(recipe_body ;
(shebang ;
(language) @injection.language) ;
(language) @injection.language)
(#not-any-of? @injection.language "python3" "nodejs" "node")
(#set! injection.include-children)) @injection.content

Expand Down
10 changes: 7 additions & 3 deletions queries-src/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

Expand Down Expand Up @@ -48,7 +49,9 @@
(#set! injection.language "powershell"))
[
(recipe
(recipe_body (#set! injection.include-children)) @injection.content)
(recipe_body
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -63,7 +66,8 @@
[
(recipe
(recipe_body
(#set! injection.include-children)) @injection.content)
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -77,7 +81,7 @@
; Set highlighting for recipes that specify a language, using the exact name by default ; SKIP-HELIX
(recipe_body ; ; SKIP-HELIX
(shebang ; ; SKIP-HELIX
(language) @injection.language) ; ; SKIP-HELIX
(language) @injection.language) ; SKIP-HELIX
(#not-any-of? @injection.language "python3" "nodejs" "node") ; SKIP-HELIX
(#set! injection.include-children)) @injection.content ; SKIP-HELIX
; SKIP-HELIX
Expand Down
10 changes: 7 additions & 3 deletions queries/just/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

Expand Down Expand Up @@ -48,7 +49,9 @@
(#set! injection.language "powershell"))
[
(recipe
(recipe_body (#set! injection.include-children)) @injection.content)
(recipe_body
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -63,7 +66,8 @@
[
(recipe
(recipe_body
(#set! injection.include-children)) @injection.content)
!shebang
(#set! injection.include-children)) @injection.content)

(assignment
(expression
Expand All @@ -77,7 +81,7 @@
; Set highlighting for recipes that specify a language, using the exact name by default
(recipe_body ;
(shebang ;
(language) @injection.language) ;
(language) @injection.language)
(#not-any-of? @injection.language "python3" "nodejs" "node")
(#set! injection.include-children)) @injection.content

Expand Down
8 changes: 6 additions & 2 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d0a73f0

Please sign in to comment.