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

Add !shebang to injection queries to improve match precedence #150

Closed
Closed
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
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
Loading