add circom tree-sitter, syntax-highlighting, and lsp support (#11676)

* add circom tree-sitter and lsp support

* add circom syntax highlighting queries

* cargo xtask docgen

* updated highlights to reflect helix themes typing

* bugfix: ~= operator causing issues

* minor adjustment: add = and ; operator and delimiter
This commit is contained in:
Thor 🪁 2024-09-21 18:13:02 +01:00 committed by GitHub
parent 274c660a0e
commit c850b90f67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 169 additions and 0 deletions

View file

@ -19,6 +19,7 @@
| cairo | ✓ | ✓ | ✓ | `cairo-language-server` |
| capnp | ✓ | | ✓ | |
| cel | ✓ | | | |
| circom | ✓ | | | `circom-lsp` |
| clojure | ✓ | | | `clojure-lsp` |
| cmake | ✓ | ✓ | ✓ | `cmake-language-server` |
| comment | ✓ | | | |

View file

@ -16,6 +16,7 @@ bicep-langserver = { command = "bicep-langserver" }
bitbake-language-server = { command = "bitbake-language-server" }
bufls = { command = "bufls", args = ["serve"] }
cairo-language-server = { command = "cairo-language-server", args = [] }
circom-lsp = { command = "circom-lsp" }
cl-lsp = { command = "cl-lsp", args = [ "stdio" ] }
clangd = { command = "clangd" }
clojure-lsp = { command = "clojure-lsp" }
@ -3788,3 +3789,19 @@ indent = { tab-width = 2, unit = " " }
[[grammar]]
name = "thrift"
source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-thrift" , rev = "68fd0d80943a828d9e6f49c58a74be1e9ca142cf" }
[[language]]
name = "circom"
scope = "source.circom"
injection-regex = "circom"
file-types = ["circom"]
roots = ["package.json"]
comment-tokens = "//"
indent = { tab-width = 4, unit = " " }
auto-format = false
language-servers = ["circom-lsp"]
[[grammar]]
name = "circom"
source = { git = "https://github.com/Decurity/tree-sitter-circom", rev = "02150524228b1e6afef96949f2d6b7cc0aaf999e" }

View file

@ -0,0 +1,142 @@
; identifiers
; -----------
(identifier) @variable
; Pragma
; -----------
(pragma_directive) @keyword.directive
; Include
; -----------
(include_directive) @keyword.directive
; Literals
; --------
(string) @string
(int_literal) @constant.numeric.integer
(comment) @comment
; Definitions
; -----------
(function_definition
name: (identifier) @keyword.function)
(template_definition
name: (identifier) @keyword.function)
; Use contructor coloring for special functions
(main_component_definition) @constructor
; Invocations
(call_expression . (identifier) @function)
; Function parameters
(parameter name: (identifier) @variable.parameter)
; Members
(member_expression property: (property_identifier) @variable.other.member)
; Tokens
; -------
; Keywords
[
"signal"
"var"
"component"
] @keyword.storage.type
[ "include" ] @keyword.control.import
[
"public"
"input"
"output"
] @keyword.storage.modifier
[
"for"
"while"
] @keyword.control.repeat
[
"if"
"else"
] @keyword.control.conditional
[
"return"
] @keyword.control.return
[
"function"
"template"
] @keyword.function
; Punctuation
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
[
"."
","
";"
] @punctuation.delimiter
; Operators
; https://docs.circom.io/circom-language/basic-operators
[
"="
"?"
"&&"
"||"
"!"
"<"
">"
"<="
">="
"=="
"!="
"+"
"-"
"*"
"**"
"/"
"\\"
"%"
"+="
"-="
"*="
"**="
"/="
"\\="
"%="
"++"
"--"
"&"
"|"
"~"
"^"
">>"
"<<"
"&="
"|="
; "\~=" ; bug, uncomment and circom will not highlight
"^="
">>="
"<<="
] @operator
[
"<=="
"==>"
"<--"
"-->"
"==="
] @operator

View file

@ -0,0 +1,9 @@
(function_definition) @local.scope
(template_definition) @local.scope
(main_component_definition) @local.scope
(block_statement) @local.scope
(parameter name: (identifier) @local.definition) @local.definition
(identifier) @local.reference