Skip to content

Commit

Permalink
add circom tree-sitter, syntax-highlighting, and lsp support (#11676)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
thor314 authored Sep 21, 2024
1 parent 274c660 commit c850b90
Show file tree
Hide file tree
Showing 4 changed files with 169 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 @@ -19,6 +19,7 @@
| cairo |||| `cairo-language-server` |
| capnp || || |
| cel || | | |
| circom || | | `circom-lsp` |
| clojure || | | `clojure-lsp` |
| cmake |||| `cmake-language-server` |
| comment || | | |
Expand Down
17 changes: 17 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }

142 changes: 142 additions & 0 deletions runtime/queries/circom/highlights.scm
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions runtime/queries/circom/locals.scm
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c850b90

Please sign in to comment.