Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Jan 9, 2024
1 parent a6d75f8 commit 79a649a
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 82 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "test-submodules/tree-sitter-bash"]
path = test-submodules/tree-sitter-bash
url = https://github.com/tree-sitter/tree-sitter-bash.git
shallow = true
4 changes: 2 additions & 2 deletions build-flavored-queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
]

REPLACEMENTS_RE = [
(r";\s*NVIM-DISABLE-START.*;\s*NVIM-DISABLE-END", "", re.MULTILINE | re.DOTALL),
("^.*NVIM-ENABLE(?P<content>.*)$", r"\g<content>", re.MULTILINE),
(r"^[^;] ?(.*;\s*NVIM-DISABLE)$", "", re.MULTILINE),
(r"^; ?(.*;\s*NVIM-ENABLE)$", r"\1", re.MULTILINE),
]


Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"injection-regex": "^(?i)just(file)?$",
"first-line-regex": "#!\\S*bin\\S*[/ ]just",
"highlights": ["queries-src/highlights.scm"],
"locals": ["queries-src/locals.scm"]
"locals": ["queries-src/locals.scm"],
"injections": ["queries-src/injections.scm"]
}
]
}
18 changes: 1 addition & 17 deletions queries-src/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,8 @@
(function_call
name: (identifier) @function)

; highlight known attributes (filtering does not always work)
(attribute
attr_item: ((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"
)))
attr_item: ((identifier) @attribute))

(recipe_header
recipe_name: (identifier) @function)
Expand Down
82 changes: 52 additions & 30 deletions queries-src/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,57 @@
(source_file
(item
(setting
left: "shell")))
right: (array
)

; TODO reenable
; ; NVIM-DISABLE-START
; (recipe_body
; (shebang) @injection.shebang
; (recipe_line
; (text) @injection.content))
; ; NVIM-DISABLE-END

; (recipe_line
; (text) @injection.content
; (#set! injection.language "bash"))

; ; NVIM-ENABLE (recipe_body
; ; NVIM-ENABLE (shebang) @injection.language
; ; NVIM-ENABLE (recipe_line
; ; NVIM-ENABLE (text) @injection.content)
; ; NVIM-ENABLE (#gsub! injection.language "/#!%*[\/ ](%S+)/" "%1"))

; (external_command
; (command_body) @injection.content
; (#set! injection.language "bash"))
left: (identifier) @setting
(#match? @setting "^shell$")
right: (array
(string_literal) @executable
(#match? @executable ".*(powershell|pwsh|cmd).*")
(#set! injection.language "powershell")
)))
(item
(recipe
(recipe_body
(recipe_line
(text) @injection.content)))))


(source_file
(item
(setting
left: (identifier) @setting
(#match? @setting "^shell$")
right: (array
(string_literal) @injection.language
(#not-match? @executable ".*(powershell|pwsh|cmd).*")
)))
(item
(recipe
(recipe_body
(recipe_line
(text) @injection.content)))))

(recipe_body ; NVIM-DISABLE
(shebang) @injection.shebang ; NVIM-DISABLE
(recipe_line ; NVIM-DISABLE
(text) @injection.content)) ; NVIM-DISABLE

(recipe_line
(text) @injection.content
(#set! injection.language "bash"))

; (recipe_body ; NVIM-ENABLE
; (shebang) @injection.language ; NVIM-ENABLE
; (recipe_line ; NVIM-ENABLE
; (text) @injection.content) ; NVIM-ENABLE
; (#gsub! injection.language "/#!%*[\/ ](%S+)/" "%1")) ; NVIM-ENABLE

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

((regex_literal
[
(string_literal)
(raw_string_literal)
] @injection.content)
(#set! injection.language "regex"))
[
(string_literal)
(raw_string_literal)
] @injection.content)
(#set! injection.language "regex"))
18 changes: 1 addition & 17 deletions queries/just/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,8 @@
(function_call
name: (identifier) @function)

; highlight known attributes (filtering does not always work)
(attribute
attr_item: ((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"
)))
attr_item: ((identifier) @attribute))

(recipe_header
recipe_name: (identifier) @function)
Expand Down
59 changes: 45 additions & 14 deletions queries/just/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,60 @@
(source_file
(item
(setting
left: "shell")))
right: (array
)
left: (identifier) @setting
(#match? @setting "^shell$")
right: (array
(string_literal) @executable
(#match? @executable ".*(powershell|pwsh|cmd).*")
(#set! injection.language "powershell")
)))
(item
(recipe
(recipe_body
(recipe_line
(text) @injection.content)))))


(source_file
(item
(setting
left: (identifier) @setting
(#match? @setting "^shell$")
right: (array
(string_literal) @injection.language
(#not-match? @executable ".*(powershell|pwsh|cmd).*")
)))
(item
(recipe
(recipe_body
(recipe_line
(text) @injection.content)))))

;
; TODO reenable
; ; NVIM-DISABLE-START
; (recipe_body
; (shebang) @injection.shebang
; (recipe_line
; (text) @injection.content))
; ; NVIM-DISABLE-END

; (recipe_line
; (text) @injection.content
; (#set! injection.language "bash"))

(recipe_body
(shebang) @injection.language
(recipe_line
(text) @injection.content)
(#gsub! injection.language "/#!%*[\/ ](%S+)/" "%1"))
; ; NVIM-ENABLE (recipe_body
; ; NVIM-ENABLE (shebang) @injection.language
; ; NVIM-ENABLE (recipe_line
; ; NVIM-ENABLE (text) @injection.content)
; ; NVIM-ENABLE (#gsub! injection.language "/#!%*[\/ ](%S+)/" "%1"))

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

((regex_literal
[
(string_literal)
(raw_string_literal)
] @injection.content)
(#set! injection.language "regex"))
[
(string_literal)
(raw_string_literal)
] @injection.content)
(#set! injection.language "regex"))
1 change: 1 addition & 0 deletions test-submodules/tree-sitter-bash
Submodule tree-sitter-bash added at 733199
8 changes: 8 additions & 0 deletions test/highlight/injections-global-pwsh.just
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
set shell := ["pwsh", "-c"]
set dotenv-filename := ".env-local"
set banana := "oiij"
set dotenv-load

recipe:
Write-Host "Hello, world!"
Get-ChildItem -Path C:\
10 changes: 9 additions & 1 deletion test/highlight/injections-global-py.just
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
set shell := ["python3", "-c"]
set shell := ["python", "-c"]
set dotenv-filename := ".env-local"
set banana := "oiij"
set dotenv-load

recipe:
print("foo")
if bar:
a += b
if (baz) {
abcd()
}

0 comments on commit 79a649a

Please sign in to comment.