diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 49cfd246..23ba6f5f 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -27,7 +27,7 @@ | cel | ✓ | | | | | | | chuck | ✓ | | | | | | | circom | ✓ | | | | | `circom-lsp` | -| clarity | ✓ | | | | | `clarinet` | +| clarity | ✓ | ✓ | ✓ | ✓ | ✓ | `clarinet` | | clojure | ✓ | ✓ | ✓ | ✓ | ✓ | `clojure-lsp` | | cmake | ✓ | ✓ | ✓ | | ✓ | `neocmakelsp`, `cmake-language-server` | | codeql | ✓ | ✓ | | | | `codeql` | diff --git a/runtime/queries/clarity/highlights.scm b/runtime/queries/clarity/highlights.scm index 112f0df6..02e3e99e 100644 --- a/runtime/queries/clarity/highlights.scm +++ b/runtime/queries/clarity/highlights.scm @@ -33,14 +33,20 @@ ")" "{" "}" - "<" - ">" ] @punctuation.bracket +(trait_type "<" @punctuation.bracket) +(trait_type ">" @punctuation.bracket) + [ "," ] @punctuation.delimiter +(tuple_lit ":" @punctuation.delimiter) +(tuple_type ":" @punctuation.delimiter) +(trait_implementation "." @punctuation.delimiter) +(trait_usage "." @punctuation.delimiter) + ; Keywords (list_lit_token) @keyword (some_lit ("some") @keyword) @@ -49,21 +55,7 @@ "err" ] @keyword) -[ - "+" - "-" - "*" - "/" - "mod" - "pow" - "<" - "<=" - ">" - ">=" - "and" - "or" - "xor" -] @keyword.operator +(int_lit "-" @constant.numeric.integer) ; Functions (function_signature (identifier) @function) @@ -71,6 +63,14 @@ (contract_function_call operator: (identifier) @function) (basic_native_form operator: (native_identifier) @function.builtin) +(basic_native_form operator: (native_identifier) @keyword.operator + (#match? @keyword.operator "^([+\\-*/<>]|<=|>=|mod|pow|and|or|xor|not)$")) +(basic_native_form operator: (native_identifier) @keyword.control.conditional + (#match? @keyword.control.conditional "^(if|match)$")) +(basic_native_form operator: (native_identifier) @keyword.control + (#match? @keyword.control "^begin$")) +(basic_native_form operator: (native_identifier) @keyword.control.exception + (#match? @keyword.control.exception "^(try!|unwrap!|unwrap-err!|unwrap-panic|unwrap-err-panic|asserts!)$")) [ "let" ] @function.builtin @@ -78,24 +78,29 @@ [ "impl-trait" "use-trait" - "define-trait" +] @keyword.control.import + +[ "define-read-only" "define-private" "define-public" +] @keyword.function + +[ + "define-trait" + "define-constant" "define-data-var" + "define-map" "define-fungible-token" "define-non-fungible-token" - "define-constant" - "define-map" -] @function.special +] @keyword.storage.type ; Variables and parameters (function_parameter) @variable.parameter (trait_usage trait_alias: (identifier) @type.parameter) -(tuple_lit key: (identifier) @variable) -(tuple_type key: (identifier) @variable) -(tuple_type_for_trait key: (identifier) @variable) +(tuple_lit key: (identifier) @variable.other.member) +(tuple_type key: (identifier) @variable.other.member) +(tuple_type_for_trait key: (identifier) @variable.other.member) (global) @variable.builtin - diff --git a/runtime/queries/clarity/indents.scm b/runtime/queries/clarity/indents.scm new file mode 100644 index 00000000..b26a05c7 --- /dev/null +++ b/runtime/queries/clarity/indents.scm @@ -0,0 +1,52 @@ +; Definitions +[ + (trait_definition) + (trait_implementation) + (trait_usage) + (fungible_token_definition) + (non_fungible_token_definition) + (constant_definition) + (variable_definition) + (mapping_definition) + (private_function) + (read_only_function) + (public_function) +] @indent + +; Function calls +[ + (basic_native_form) + (contract_function_call) + (let_expression) +] @indent + +; Bindings and signatures +[ + (local_binding) + (function_signature) + (function_parameter) + (function_signature_for_trait) +] @indent + +; Literals +[ + (list_lit) + (some_lit) + (response_lit) + (tuple_lit) +] @indent + +; Types +[ + (buffer_type) + (ascii_string_type) + (utf8_string_type) + (list_type) + (optional_type) + (tuple_type) + (tuple_type_for_trait) + (response_type) +] @indent + +; Closing delimiters +[")" "}"] @outdent diff --git a/runtime/queries/clarity/rainbows.scm b/runtime/queries/clarity/rainbows.scm new file mode 100644 index 00000000..8bbcb17a --- /dev/null +++ b/runtime/queries/clarity/rainbows.scm @@ -0,0 +1,52 @@ +; Definitions +[ + (trait_definition) + (trait_implementation) + (trait_usage) + (fungible_token_definition) + (non_fungible_token_definition) + (constant_definition) + (variable_definition) + (mapping_definition) + (private_function) + (read_only_function) + (public_function) +] @rainbow.scope + +; Function calls +[ + (basic_native_form) + (contract_function_call) + (let_expression) +] @rainbow.scope + +; Bindings and signatures +[ + (local_binding) + (function_signature) + (function_parameter) + (function_signature_for_trait) +] @rainbow.scope + +; Literals +[ + (list_lit) + (some_lit) + (response_lit) + (tuple_lit) +] @rainbow.scope + +; Types +[ + (buffer_type) + (ascii_string_type) + (utf8_string_type) + (list_type) + (optional_type) + (tuple_type) + (tuple_type_for_trait) + (response_type) +] @rainbow.scope + +; Bracket characters +["(" ")" "{" "}"] @rainbow.bracket diff --git a/runtime/queries/clarity/tags.scm b/runtime/queries/clarity/tags.scm new file mode 100644 index 00000000..709b8cff --- /dev/null +++ b/runtime/queries/clarity/tags.scm @@ -0,0 +1,35 @@ +; Functions +(private_function + (function_signature + (identifier) @definition.function)) + +(read_only_function + (function_signature + (identifier) @definition.function)) + +(public_function + (function_signature + (identifier) @definition.function)) + +; Traits +(trait_definition + "define-trait" . (identifier) @definition.interface) + +; Constants +(constant_definition + "define-constant" . (identifier) @definition.constant) + +; Data variables +(variable_definition + "define-data-var" . (identifier) @definition.constant) + +; Maps +(mapping_definition + "define-map" . (identifier) @definition.struct) + +; Tokens +(fungible_token_definition + "define-fungible-token" . (identifier) @definition.type) + +(non_fungible_token_definition + "define-non-fungible-token" . (identifier) @definition.type) diff --git a/runtime/queries/clarity/textobjects.scm b/runtime/queries/clarity/textobjects.scm new file mode 100644 index 00000000..feba5f2d --- /dev/null +++ b/runtime/queries/clarity/textobjects.scm @@ -0,0 +1,26 @@ +; Functions +(private_function + (function_signature) + (_) @function.inside) @function.around + +(read_only_function + (function_signature) + (_) @function.inside) @function.around + +(public_function + (function_signature) + (_) @function.inside) @function.around + +; FIXME: trait_definition not matching — may be a grammar issue +; (trait_definition) @class.around + +; Parameters +(function_signature + (function_parameter) @parameter.inside @parameter.around) + +; Comments +(comment) @comment.inside +(comment)+ @comment.around + +; Entries +(local_binding) @entry.inside @entry.around