From 04d878eef8cabf320c7b860a8092f17eb2c38719 Mon Sep 17 00:00:00 2001 From: Delyan Haralanov Date: Thu, 29 Jan 2026 19:52:26 +0200 Subject: [PATCH] typescript: Fix type import highlighting when alias is not present (#47190) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem The existing tree-sitter queries for type imports required both name and alias fields to match. This caused `import type { Foo }` and `import { type Foo }` to fall back to the generic identifier/variable highlighting instead of being colored as types. - `import type { Foo }` → **NOT matched** (no alias) - `import { type Foo }` → **NOT matched** (no alias) - `import type { Foo as Bar }` → Matched ✓ - `import { type Foo as Bar }` → Matched ✓ ## Solution Split the patterns to handle name and alias captures independently. ~## Disclaimer~ ~DEBUGGING AND IMPLEMENTATION WAS DONE WITH **AI ASSISTANCE**.~ ~**THE FIX HAS NOT BEEN TESTED** - I HAVE NOT COMPILED FROM SOURCE~ - @KyleBarton built from source and verified Release Notes: - Fixed typescript type import highlighting --- crates/languages/src/typescript/highlights.scm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/languages/src/typescript/highlights.scm b/crates/languages/src/typescript/highlights.scm index e38467626fe475aa21bd7a62e8735dbd55320bfe..8ec3ec26cca805c65d68d9df08037102a32494dc 100644 --- a/crates/languages/src/typescript/highlights.scm +++ b/crates/languages/src/typescript/highlights.scm @@ -98,18 +98,34 @@ (statement_block) @nested ]))) +; Inline type imports: import { type Foo } or import { type Foo as Bar } (import_specifier "type" name: (identifier) @type +) + +(import_specifier + "type" alias: (identifier) @type ) +; Full type imports: import type { Foo } or import type { Foo as Bar } (import_statement "type" (import_clause (named_imports (import_specifier name: (identifier) @type + ) + ) + ) +) + +(import_statement + "type" + (import_clause + (named_imports + (import_specifier alias: (identifier) @type ) )