From d8c6d0d046c01666c77a1a133abe99237ebbdc1a Mon Sep 17 00:00:00 2001 From: Thor Kampefner Date: Wed, 11 Sep 2024 17:43:08 -0700 Subject: [PATCH 1/6] add circom tree-sitter and lsp support --- languages.toml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index cc437f78c1db..105029625fc7 100644 --- a/languages.toml +++ b/languages.toml @@ -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" } @@ -3785,4 +3786,20 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "thrift" -source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-thrift" , rev = "68fd0d80943a828d9e6f49c58a74be1e9ca142cf" } \ No newline at end of file +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" } + From 0ab8b7622777a1921f57ca7de0e0a0706106cf92 Mon Sep 17 00:00:00 2001 From: Thor Kampefner Date: Wed, 11 Sep 2024 17:46:40 -0700 Subject: [PATCH 2/6] add circom syntax highlighting queries --- runtime/queries/circom/highlights.scm | 134 ++++++++++++++++++++++++++ runtime/queries/circom/locals.scm | 9 ++ 2 files changed, 143 insertions(+) create mode 100644 runtime/queries/circom/highlights.scm create mode 100644 runtime/queries/circom/locals.scm diff --git a/runtime/queries/circom/highlights.scm b/runtime/queries/circom/highlights.scm new file mode 100644 index 000000000000..4eb1972e33c6 --- /dev/null +++ b/runtime/queries/circom/highlights.scm @@ -0,0 +1,134 @@ +; identifiers +; ----------- +(identifier) @variable + +; Pragma +; ----------- +(pragma_directive) @tag + +; Include +; ----------- +(include_directive) @include + +; Literals +; -------- + +(string) @string +(int_literal) @number +(comment) @comment + +; Definitions +; ----------- + +(function_definition + name: (identifier) @function) + +(template_definition + name: (identifier) @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) @property) + + +; Tokens +; ------- + +; Keywords + +[ + "public" + "signal" + "var" + "include" + "input" + "output" + "public" + "component" +] @keyword + +[ + "for" + "while" +] @repeat + +[ + "if" + "else" +] @conditional + +[ + "return" +] @keyword.return + +[ + "function" + "template" +] @keyword.function + + +; Punctuation + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + + +[ + "." + "," +] @punctuation.delimiter + + +; Operators + +[ + "&&" + "||" + ">>" + "<<" + "&" + "^" + "|" + "+" + "-" + "*" + "/" + "%" + "**" + "<" + "<=" + "==" + "!=" + ">=" + ">" + "!" + "~" + "-" + "+" + "++" + "--" +] @operator + +[ + "<==" + "==>" + "<--" + "-->" + "===" +] @assignment \ No newline at end of file diff --git a/runtime/queries/circom/locals.scm b/runtime/queries/circom/locals.scm new file mode 100644 index 000000000000..e0ea12de0800 --- /dev/null +++ b/runtime/queries/circom/locals.scm @@ -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 \ No newline at end of file From ad7c408d4329490dbcc7776f514f0f7872e92817 Mon Sep 17 00:00:00 2001 From: Thor Kampefner Date: Mon, 16 Sep 2024 17:33:03 -0700 Subject: [PATCH 3/6] cargo xtask docgen --- book/src/generated/lang-support.md | 1 + 1 file changed, 1 insertion(+) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index cb1c815f2150..8a2f04148918 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -19,6 +19,7 @@ | cairo | ✓ | ✓ | ✓ | `cairo-language-server` | | capnp | ✓ | | ✓ | | | cel | ✓ | | | | +| circom | ✓ | | | `circom-lsp` | | clojure | ✓ | | | `clojure-lsp` | | cmake | ✓ | ✓ | ✓ | `cmake-language-server` | | comment | ✓ | | | | From e1b343c6de122fd39aaf267d6698bde09c714103 Mon Sep 17 00:00:00 2001 From: Thor Kampefner Date: Tue, 17 Sep 2024 21:50:11 -0700 Subject: [PATCH 4/6] updated highlights to reflect helix themes typing --- runtime/queries/circom/highlights.scm | 90 ++++++++++++++------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/runtime/queries/circom/highlights.scm b/runtime/queries/circom/highlights.scm index 4eb1972e33c6..c61d3336101d 100644 --- a/runtime/queries/circom/highlights.scm +++ b/runtime/queries/circom/highlights.scm @@ -4,81 +4,76 @@ ; Pragma ; ----------- -(pragma_directive) @tag +(pragma_directive) @keyword.directive ; Include ; ----------- -(include_directive) @include +(include_directive) @keyword.directive ; Literals ; -------- - (string) @string -(int_literal) @number +(int_literal) @constant.numeric.integer (comment) @comment ; Definitions ; ----------- - (function_definition - name: (identifier) @function) + name: (identifier) @keyword.function) (template_definition - name: (identifier) @function) + 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) @property) - +(member_expression property: (property_identifier) @variable.other.member) ; Tokens ; ------- ; Keywords - [ - "public" "signal" "var" - "include" + "component" +] @keyword.storage.type + +[ "include" ] @keyword.control.import + +[ + "public" "input" "output" - "public" - "component" -] @keyword + ] @keyword.storage.modifier [ "for" "while" -] @repeat +] @keyword.control.repeat [ "if" "else" -] @conditional +] @keyword.control.conditional [ "return" -] @keyword.return +] @keyword.control.return [ "function" "template" ] @keyword.function - ; Punctuation - [ "(" ")" @@ -88,41 +83,52 @@ "}" ] @punctuation.bracket - [ "." "," ] @punctuation.delimiter - ; Operators - +; https://docs.circom.io/circom-language/basic-operators [ + "?" "&&" "||" - ">>" - "<<" - "&" - "^" - "|" + "!" + "<" + ">" + "<=" + ">=" + "==" + "!=" "+" "-" "*" + "**" "/" + "\\" "%" - "**" - "<" - "<=" - "==" - "!=" - ">=" - ">" - "!" - "~" - "-" - "+" + "+=" + "-=" + "*=" + "**=" + "/=" + "\\=" + "%=" "++" "--" + "&" + "|" + "~" + "^" + ">>" + "<<" + "&=" + "|=" + "~=" + "^=" + ">>=" + "<<=" ] @operator [ @@ -131,4 +137,4 @@ "<--" "-->" "===" -] @assignment \ No newline at end of file +] @operator From 21ebcbd175f8b08ee18737d7f3d838ad89573a95 Mon Sep 17 00:00:00 2001 From: Thor Kampefner Date: Wed, 18 Sep 2024 12:05:37 -0700 Subject: [PATCH 5/6] bugfix: ~= operator causing issues --- runtime/queries/circom/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/circom/highlights.scm b/runtime/queries/circom/highlights.scm index c61d3336101d..81e9ad8948bc 100644 --- a/runtime/queries/circom/highlights.scm +++ b/runtime/queries/circom/highlights.scm @@ -125,7 +125,7 @@ "<<" "&=" "|=" - "~=" + ; "\~=" ; bug, uncomment and circom will not highlight "^=" ">>=" "<<=" From 896f13666f7387586af8d1d0a36df08d14ff3c68 Mon Sep 17 00:00:00 2001 From: Thor Kampefner Date: Wed, 18 Sep 2024 12:08:18 -0700 Subject: [PATCH 6/6] minor adjustment: add = and ; operator and delimiter --- runtime/queries/circom/highlights.scm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/queries/circom/highlights.scm b/runtime/queries/circom/highlights.scm index 81e9ad8948bc..1d310bd8e087 100644 --- a/runtime/queries/circom/highlights.scm +++ b/runtime/queries/circom/highlights.scm @@ -86,11 +86,13 @@ [ "." "," + ";" ] @punctuation.delimiter ; Operators ; https://docs.circom.io/circom-language/basic-operators [ + "=" "?" "&&" "||"