Skip to content

Commit

Permalink
Add queries for the just language
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Mar 12, 2024
1 parent 21c714d commit 233b22a
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [#3026](https://github.com/lapce/lapce/pull/3026): Add missing file explorer context menu entries
- [#3047](https://github.com/lapce/lapce/pull/3047): Add support for different CrLf/Lf line endings per-file
- [#3053](https://github.com/lapce/lapce/pull/3053): Add tooltips to various places
- [#3065](https://github.com/lapce/lapce/pull/3065): Add the `just` language

### Bug Fixes
- [#2779](https://github.com/lapce/lapce/pull/2779): Fix files detection on fresh git/VCS repository
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions lapce-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tree-sitter-python = { version = "0.20.4", optional = true }
tree-sitter-rust = { version = "0.20.4", optional = true }
tree-sitter-toml = { version = "0.20.0", optional = true }
tree-sitter-yaml = { git = "https://github.com/panekj/tree-sitter-yaml", rev = "80c8d76847f03e772c5c524cf29bafb56858a8d1", optional = true }
tree-sitter-just = "0.0.1"

[features]
default = []
Expand Down
10 changes: 10 additions & 0 deletions lapce-core/queries/just/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)
149 changes: 149 additions & 0 deletions lapce-core/queries/just/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
; 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

(comment) @comment.line

(shebang) @keyword.directive

; 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 lapce-core/queries/just/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 specifies how to auto-indent logical blocks.
;
; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html

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

; Specify nested languages that live within a `justfile`

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

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

((comment) @injection.content
(#set! injection.language "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, using the exact name by default
(recipe_body ;
(shebang ;
(language) @injection.language) ;
(#not-any-of? @injection.language "python3" "nodejs" "node")
(#set! injection.include-children)) @injection.content

; Transform some known executables

; python3 -> python
(recipe_body
(shebang
(language) @_lang)
(#eq? @_lang "python3")
(#set! injection.language "python")
(#set! injection.include-children)) @injection.content

; node/nodejs -> javascript
(recipe_body
(shebang
(language) @_lang)
(#any-of? @_lang "node" "nodejs")
(#set! injection.language "javascript")
(#set! injection.include-children)) @injection.content
42 changes: 42 additions & 0 deletions lapce-core/queries/just/locals.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
; 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)
18 changes: 18 additions & 0 deletions lapce-core/queries/just/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; File autogenerated by build-queries-nvim.py; do not edit

; Specify how to navigate around logical blocks in code

(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

0 comments on commit 233b22a

Please sign in to comment.