Skip to content

Commit

Permalink
Update formatting by hand to match nvim where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Mar 11, 2024
1 parent 3073ccf commit 58ec38f
Show file tree
Hide file tree
Showing 31 changed files with 560 additions and 318 deletions.
23 changes: 14 additions & 9 deletions build-flavored-queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
(r"(@[\w.]+).inside", "\1.inner"),
(r"(@[\w.]+).around", "\1.outer"),
# nvim does not have `injection.include-children`
(r"\n?\s*\(\s*#set!\s*injection\.include-children\s*\)", "", re.MULTILINE),
(r"\s*\n?\s*\(\s*#set!\s*injection\.include-children\s*\)", "", re.MULTILINE),
# nvim uses `var` rather than `variable`
(r"(@[\w.]+)\.variable", r"\1.var"),
# nothing more specific than reference
Expand Down Expand Up @@ -523,7 +523,18 @@ def main():
allowed_settings,
basepath,
) in FLAVOR_MAPPINGS:
contents = base_contents
# Remove lines as indicated by directives
contents = "\n".join(
(
line
for line in base_contents.splitlines()
if f"SKIP-{tag}" not in line
)
)

# Delete other directives
contents = re.sub(r";?\s*SKIP-[\w-]+", "", contents)

for rep in replacements:
pat = rep[0]
sub = rep[1]
Expand All @@ -532,14 +543,8 @@ def main():
flags = rep[2]
contents = re.sub(pat, sub, contents, flags=flags)

contents = "\n".join(
(line for line in contents.splitlines() if f"SKIP-{tag}" not in line)
)

# Delete directives
contents = re.sub(r"SKIP-[\w-]+", "", contents)
# Remove trailing whitespace and duplicate newlines
contents = re.sub(r"\s*;?\s+$", "", contents)
contents = re.sub(r"[\s;]+$", "", contents)
contents = re.sub(r"((?:\r?\n){2,})(?:\r?\n)+", r"\1", contents)

if not contents.endswith("\n"):
Expand Down
63 changes: 35 additions & 28 deletions queries-flavored/helix/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,38 @@

; Variables

(value (identifier) @variable)
(value
(identifier) @variable)

(alias left: (identifier) @variable)
(alias
left: (identifier) @variable)

(assignment left: (identifier) @variable)
(assignment
left: (identifier) @variable)

; Functions

(recipe_header name: (identifier) @function)
(recipe_header
name: (identifier) @function)

(dependency name: (identifier) @function)
(dependency
name: (identifier) @function)

(dependency_expression name: (identifier) @function)
(dependency_expression
name: (identifier) @function)

(function_call name: (identifier) @function)
(function_call
name: (identifier) @function)

; Parameters

(parameter name: (identifier) @variable.parameter)
(parameter
name: (identifier) @variable.parameter)

; Namespaces

(module name: (identifier) @namespace)
(module
name: (identifier) @namespace)

; Operators

Expand Down Expand Up @@ -103,7 +112,7 @@

; highlight known settings (filtering does not always work)
(setting
left: ((identifier) @keyword
left: (identifier) @keyword
(#any-of? @keyword
"allow-duplicate-recipes"
"dotenv-filename"
Expand All @@ -116,27 +125,25 @@
"shell"
"tempdi"
"windows-powershell"
"windows-shell"
)))
"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"
)))
(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
4 changes: 2 additions & 2 deletions queries-flavored/helix/indents.scm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
; File autogenerated by build-queries-nvim.py; do not edit

; This query
; This query specifies how to auto-indent logical blocks.
;
; Better documentation is in https://docs.helix-editor.com/guides/indent.html
; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html

[
(recipe)
Expand Down
27 changes: 16 additions & 11 deletions queries-flavored/helix/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

; Specify nested languages that live within a `justfile`

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

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

((comment) @injection.content
(#set! injection.language "comment"))

(comment) @comment

; Highlight the RHS of `=~` as regex
((regex_literal (_) @injection.content)
(#set! injection.language "regex"))
Expand Down Expand Up @@ -54,23 +52,30 @@
(recipe_body (#set! injection.include-children)) @injection.content)

(assignment
(expression (value (external_command (command_body) @injection.content))))
(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)
(recipe_body
(#set! injection.include-children)) @injection.content)

(assignment
(expression (value (external_command (command_body) @injection.content))))
(expression
(value
(external_command
(command_body) @injection.content))))
])

; ================ Recipe language specified ================

; Set highlighting for recipes that specify a language
(recipe_body
(shebang (language) @injection.language)
; ================ Recipe language specified - Helix only ================
; Set highlighting for recipes that specify a language using builtin shebang matching
(recipe_body
(shebang) @injection.shebang
(#set! injection.include-children)) @injection.content
30 changes: 20 additions & 10 deletions queries-flavored/helix/locals.scm
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,34 @@

; Definitions

(alias left: (identifier) @local.definition.variable)
(alias
left: (identifier) @local.definition.variable)

(assignment left: (identifier) @local.definition.variable)
(assignment
left: (identifier) @local.definition.variable)

(module name: (identifier) @local.definition.namespace)
(module
name: (identifier) @local.definition.namespace)

(parameter name: (identifier) @local.definition.variable)
(parameter
name: (identifier) @local.definition.variable)

(recipe_header name: (identifier) @local.definition.function)
(recipe_header
name: (identifier) @local.definition.function)

; References

(alias right: (identifier) @local.reference)
(alias
right: (identifier) @local.reference)

(function_call name: (identifier) @local.reference)
(function_call
name: (identifier) @local.reference)

(dependency name: (identifier) @local.reference)
(dependency
name: (identifier) @local.reference)

(dependency_expression name: (identifier) @local.reference)
(dependency_expression
name: (identifier) @local.reference)

(value (identifier) @local.reference)
(value
(identifier) @local.reference)
3 changes: 2 additions & 1 deletion queries-flavored/helix/textobjects.scm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
(_) @parameter.inside) @parameter.around

(function_call
arguments: (sequence (expression) @parameter.inside) @parameter.around) @function.around
arguments: (sequence
(expression) @parameter.inside) @parameter.around) @function.around

(comment) @comment.around
63 changes: 35 additions & 28 deletions queries-flavored/lapce/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,38 @@

; Variables

(value (identifier) @variable)
(value
(identifier) @variable)

(alias left: (identifier) @variable)
(alias
left: (identifier) @variable)

(assignment left: (identifier) @variable)
(assignment
left: (identifier) @variable)

; Functions

(recipe_header name: (identifier) @function)
(recipe_header
name: (identifier) @function)

(dependency name: (identifier) @function)
(dependency
name: (identifier) @function)

(dependency_expression name: (identifier) @function)
(dependency_expression
name: (identifier) @function)

(function_call name: (identifier) @function)
(function_call
name: (identifier) @function)

; Parameters

(parameter name: (identifier) @variable.parameter)
(parameter
name: (identifier) @variable.parameter)

; Namespaces

(module name: (identifier) @namespace)
(module
name: (identifier) @namespace)

; Operators

Expand Down Expand Up @@ -103,7 +112,7 @@

; highlight known settings (filtering does not always work)
(setting
left: ((identifier) @keyword
left: (identifier) @keyword
(#any-of? @keyword
"allow-duplicate-recipes"
"dotenv-filename"
Expand All @@ -116,27 +125,25 @@
"shell"
"tempdi"
"windows-powershell"
"windows-shell"
)))
"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"
)))
(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
4 changes: 2 additions & 2 deletions queries-flavored/lapce/indents.scm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
; File autogenerated by build-queries-nvim.py; do not edit

; This query
; This query specifies how to auto-indent logical blocks.
;
; Better documentation is in https://docs.helix-editor.com/guides/indent.html
; Better documentation with diagrams is in https://docs.helix-editor.com/guides/indent.html

[
(recipe)
Expand Down
Loading

0 comments on commit 58ec38f

Please sign in to comment.