diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cb2ea23 --- /dev/null +++ b/.gitmodules @@ -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 diff --git a/build-flavored-queries.py b/build-flavored-queries.py index 883615f..1abd285 100755 --- a/build-flavored-queries.py +++ b/build-flavored-queries.py @@ -28,8 +28,8 @@ ] REPLACEMENTS_RE = [ - (r";\s*NVIM-DISABLE-START.*;\s*NVIM-DISABLE-END", "", re.MULTILINE | re.DOTALL), - ("^.*NVIM-ENABLE(?P.*)$", r"\g", re.MULTILINE), + (r"^[^;] ?(.*;\s*NVIM-DISABLE)$", "", re.MULTILINE), + (r"^; ?(.*;\s*NVIM-ENABLE)$", r"\1", re.MULTILINE), ] diff --git a/package.json b/package.json index 49d89c3..3b20ec5 100644 --- a/package.json +++ b/package.json @@ -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"] } ] } diff --git a/queries-src/highlights.scm b/queries-src/highlights.scm index d1bb16a..a10c543 100644 --- a/queries-src/highlights.scm +++ b/queries-src/highlights.scm @@ -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) diff --git a/queries-src/injections.scm b/queries-src/injections.scm index 9bb2bcf..f9e7026 100644 --- a/queries-src/injections.scm +++ b/queries-src/injections.scm @@ -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")) diff --git a/queries/just/highlights.scm b/queries/just/highlights.scm index af0b594..a72c336 100644 --- a/queries/just/highlights.scm +++ b/queries/just/highlights.scm @@ -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) diff --git a/queries/just/injections.scm b/queries/just/injections.scm index 6673434..84d9d21 100644 --- a/queries/just/injections.scm +++ b/queries/just/injections.scm @@ -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")) diff --git a/test-submodules/tree-sitter-bash b/test-submodules/tree-sitter-bash new file mode 160000 index 0000000..7331995 --- /dev/null +++ b/test-submodules/tree-sitter-bash @@ -0,0 +1 @@ +Subproject commit 7331995b19b8f8aba2d5e26deb51d2195c18bc94 diff --git a/test/highlight/injections-global-pwsh.just b/test/highlight/injections-global-pwsh.just new file mode 100644 index 0000000..1e6ff4f --- /dev/null +++ b/test/highlight/injections-global-pwsh.just @@ -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:\ diff --git a/test/highlight/injections-global-py.just b/test/highlight/injections-global-py.just index 1958826..aee1fa5 100644 --- a/test/highlight/injections-global-py.just +++ b/test/highlight/injections-global-py.just @@ -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() + }