Skip to content

Commit

Permalink
Add language support for rego (OpenPolicyAgent) (helix-editor#6415)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmuller authored and Schuyler Mortimer committed Jul 10, 2024
1 parent ddc30f0 commit 1ca6bc8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
| r || | | `R` |
| racket || | | `racket` |
| regex || | | |
| rego || | | `regols` |
| rescript ||| | `rescript-language-server` |
| rmarkdown || || `R` |
| ron || || |
Expand Down
15 changes: 15 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2383,3 +2383,18 @@ injection-regex = "vhdl"
[[grammar]]
name = "vhdl"
source = { git = "https://github.com/teburd/tree-sitter-vhdl", rev = "c57313adee2231100db0a7880033f6865deeadb2" }

[[language]]
name = "rego"
roots = []
scope = "source.rego"
injection-regex = "rego"
file-types = ["rego"]
auto-format = true
comment-token = "#"
language-server = { command = "regols" }
grammar = "rego"

[[grammar]]
name = "rego"
source = { git = "https://github.com/FallenAngel97/tree-sitter-rego", rev = "b2667c975f07b33be3ceb83bea5cfbad88095866" }
68 changes: 68 additions & 0 deletions runtime/queries/rego/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[
(import)
] @keyword.control.import

[
(package)
] @namespace

[
(with)
(as)
(every)
(some)
(in)
(default)
"null"
] @keyword.control

[
(not)
(if)
(contains)
(else)
] @keyword.control.conditional

[
(boolean)
] @constant.builtin.boolean

[
(assignment_operator)
(bool_operator)
(arith_operator)
(bin_operator)
] @operator

[
(string)
(raw_string)
] @string

(term (ref (var))) @variable

(comment) @comment.line

(number) @constant.numeric.integer

(expr_call func_name: (fn_name (var) @function .))

(expr_call func_arguments: (fn_args (expr) @variable.parameter))

(rule_args (term) @variable.parameter)

[
(open_paren)
(close_paren)
(open_bracket)
(close_bracket)
(open_curly)
(close_curly)
] @punctuation.bracket

(rule (rule_head (var) @function.method))

(rule
(rule_head (term (ref (var) @namespace)))
(rule_body (query (literal (expr (expr_infix (expr (term (ref (var)) @_output)))))) (#eq? @_output @namespace))
)
2 changes: 2 additions & 0 deletions runtime/queries/rego/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))

0 comments on commit 1ca6bc8

Please sign in to comment.