From 838133d24fba3380577909094b2e4f27854d28c7 Mon Sep 17 00:00:00 2001 From: pullfrog Date: Fri, 19 Dec 2025 15:12:20 +0000 Subject: [PATCH] Add built-in syntax highlighting for arktype Adds tree-sitter injection rules for arktype function calls in TypeScript and JavaScript files. This enables syntax highlighting for string and template string arguments passed to arktype functions. Supported patterns: - arktype function calls: type(), generic(), scope(), define(), match(), fn(), module(), ark*() - Chained method calls: .and(), .or(), .case(), .in(), .extends(), .ifExtends(), .intersect(), .merge(), .exclude(), .extract(), .overlaps(), .subsumes(), .to(), .satisfies() - regex() function with regex language injection String and template string arguments are highlighted with TypeScript syntax, matching arktype's DSL which uses TypeScript-like syntax. --- .../languages/src/javascript/injections.scm | 33 +++++++++++++++++++ .../languages/src/typescript/injections.scm | 33 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/crates/languages/src/javascript/injections.scm b/crates/languages/src/javascript/injections.scm index 244e025a6f5d62..4d678fd28b12f7 100644 --- a/crates/languages/src/javascript/injections.scm +++ b/crates/languages/src/javascript/injections.scm @@ -126,3 +126,36 @@ (#match? @_ecma_comment "^\\/\\*\\s*(css)\\s*\\*\\/") (#set! injection.language "css") ) + +; ArkType function calls - highlight string/template arguments as TypeScript +(call_expression + function: (identifier) @_name + (#match? @_name "^(type|generic|scope|define|match|fn|module|[aA]rk[a-zA-Z]*)$") + arguments: (arguments [ + (string (string_fragment) @injection.content) + (template_string (string_fragment) @injection.content) + ]) + (#set! injection.language "typescript") +) + +; ArkType chained method calls +(call_expression + function: (member_expression + property: (property_identifier) @_method + (#match? @_method "^(and|or|case|in|extends|ifExtends|intersect|merge|exclude|extract|overlaps|subsumes|to|satisfies)$")) + arguments: (arguments [ + (string (string_fragment) @injection.content) + (template_string (string_fragment) @injection.content) + ]) + (#set! injection.language "typescript") +) + +; ArkType regex function - highlight as regex +(call_expression + function: (identifier) @_name (#eq? @_name "regex") + arguments: (arguments [ + (string (string_fragment) @injection.content) + (template_string (string_fragment) @injection.content) + ]) + (#set! injection.language "regex") +) diff --git a/crates/languages/src/typescript/injections.scm b/crates/languages/src/typescript/injections.scm index 91880407900e74..0c6e4382b3b1c7 100644 --- a/crates/languages/src/typescript/injections.scm +++ b/crates/languages/src/typescript/injections.scm @@ -167,3 +167,36 @@ (#match? @_ecma_comment "^\\/\\*\\s*(css)\\s*\\*\\/") (#set! injection.language "css") ) + +; ArkType function calls - highlight string/template arguments as TypeScript +(call_expression + function: (identifier) @_name + (#match? @_name "^(type|generic|scope|define|match|fn|module|[aA]rk[a-zA-Z]*)$") + arguments: (arguments [ + (string (string_fragment) @injection.content) + (template_string (string_fragment) @injection.content) + ]) + (#set! injection.language "typescript") +) + +; ArkType chained method calls +(call_expression + function: (member_expression + property: (property_identifier) @_method + (#match? @_method "^(and|or|case|in|extends|ifExtends|intersect|merge|exclude|extract|overlaps|subsumes|to|satisfies)$")) + arguments: (arguments [ + (string (string_fragment) @injection.content) + (template_string (string_fragment) @injection.content) + ]) + (#set! injection.language "typescript") +) + +; ArkType regex function - highlight as regex +(call_expression + function: (identifier) @_name (#eq? @_name "regex") + arguments: (arguments [ + (string (string_fragment) @injection.content) + (template_string (string_fragment) @injection.content) + ]) + (#set! injection.language "regex") +)