From 223f8dd2e475ab790d9fede23681cd3c016fab79 Mon Sep 17 00:00:00 2001 From: Liam Woodleigh-Hardinge Date: Sun, 28 Apr 2024 18:13:51 +0200 Subject: [PATCH] fix(wit): update parser and queries (#6528) --- lockfile.json | 2 +- queries/wit/highlights.scm | 181 +++++++++++++++++++++++++------------ queries/wit/injections.scm | 5 +- 3 files changed, 127 insertions(+), 61 deletions(-) diff --git a/lockfile.json b/lockfile.json index 74266b4c5..7970934ce 100644 --- a/lockfile.json +++ b/lockfile.json @@ -801,7 +801,7 @@ "revision": "bd1d35cf3e013dc7e189b46a593bdc2b281b0dd7" }, "wit": { - "revision": "ed13e0a3ee77833900a095d57d2685a1f7f91237" + "revision": "16e263143e230b79a00f6cc353f6fd860c4e5de5" }, "xcompose": { "revision": "2383cc69a2c42cfade41c7cb971fb3862bec6df1" diff --git a/queries/wit/highlights.scm b/queries/wit/highlights.scm index 237858ba2..983987b90 100644 --- a/queries/wit/highlights.scm +++ b/queries/wit/highlights.scm @@ -1,81 +1,150 @@ -; Comments -(line_comment) @comment +(comment) @comment @spell -(block_comment) @comment +(ty + (id)) @type + +(package_decl + (id)) @module + +(valid_semver) @string.special + +(world_item + name: (id) @module) + +(interface_item + name: (id) @module) + +(import_item + name: (id) @module + (extern_type + (interface_body))) + +(import_item + name: (id) @function + (extern_type + (func_type))) + +(export_item + name: (id) @module + (extern_type + (interface_body))) + +(export_item + name: (id) @function + (extern_type + (func_type))) + +(type_item + alias: (id) @type.definition) + +(func_item + name: (id) @function) + +(handle + (id) @type) + +(named_type + name: (id) @variable.parameter) + +(record_item + name: (id) @type) + +(record_field + name: (id) @variable.member) + +(flags_items + name: (id) @type) + +(flags_body + (id) @variable.member) + +(variant_items + name: (id) @type) + +(variant_case + name: (id) @type) + +(enum_items + name: (id) @type) + +(enum_body + enum_cases: (id) @constant) + +(resource_item + name: (id) @type) + +(resource_method + "constructor" @constructor) + +(toplevel_use_item + "use" @keyword.import) + +(use_item + "use" @keyword.import) + +(use_path + (id) @module) + +"func" @keyword.function + +[ + "type" + "interface" + "world" + "package" + "resource" + "record" + "enum" + "flags" + "variant" +] @keyword.type + +"static" @keyword.modifier + +[ + "include" + "import" + "export" +] @keyword.import -; Primitive Types [ - "bool" - "s8" - "s16" - "s32" - "s64" "u8" "u16" "u32" "u64" - "float32" - "float64" + "s8" + "s16" + "s32" + "s64" + "f32" + "f64" "char" + "bool" "string" - ; Container Types - "list" "tuple" + "list" "option" "result" + "borrow" ] @type.builtin -"func" @keyword.function - -; Keywords for file structure and components [ - "record" - "enum" - "variant" - "flags" - "resource" -] @keyword.type - -; Keywords for importing and exporting -[ - "package" - "world" - "use" - "import" -] @keyword.import - -; Resource Keywords -"static" @keyword.modifier - -; Named Types (Capitalized identifiers) -((identifier) @type - (#match? @type "^[A-Z]")) - -((identifier) @variable - (#match? @variable "^[a-z_][a-zA-Z0-9_]*$")) - -; Constants (UPPER_CASE names and Enums) -((identifier) @constant - (#match? @constant "^[A-Z][A-Z0-9_]+$")) - -; Functions and Methods (lowercase names followed by parentheses) -((identifier) @function - (#match? @function "^[a-z_][a-zA-Z0-9_]*%(")) - -; Punctuation -[ - ";" - ":" + "@" "->" ] @punctuation.special -; Delimiters -"," @punctuation.delimiter +[ + "/" + ";" + ":" + "," +] @punctuation.delimiter -; Brackets [ "{" "}" "(" ")" ] @punctuation.bracket + +"=" @operator diff --git a/queries/wit/injections.scm b/queries/wit/injections.scm index 50b9b8fa9..2f0e58eb6 100644 --- a/queries/wit/injections.scm +++ b/queries/wit/injections.scm @@ -1,5 +1,2 @@ -((line_comment) @comment - (#set! injection.language "comment")) - -((block_comment) @comment +((comment) @injection.content (#set! injection.language "comment"))