From 17b5be766aaa87f80ee1e25794467e3c38f3ee33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R4T=20=E1=B5=88=E1=B5=89=E1=B5=9B?= <153876514+RATR2@users.noreply.github.com> Date: Sat, 11 Jul 2026 08:35:01 -0500 Subject: [PATCH 1/3] Recognize <##rrggbb> alongside <#rrggbb> for hex color tags Some addons write hex color tags with a doubled "#" prefix. Extended all three places that recognize <#rrggbb> to also accept <##rrggbb>: the live decoration engine (scanColorRuns), the color picker (DocumentColorProvider), and the static grammar fallback. The color picker also now preserves whichever of "#"/"##" the original tag used when a new color is picked, instead of always collapsing back to a single "#". Version bump: 1.0.4 -> 1.0.5. --- README.md | 6 +++--- package-lock.json | 4 ++-- package.json | 2 +- src/providers/colorProvider.ts | 20 ++++++++++++++------ src/utils/colorCodes.ts | 2 +- syntaxes/skript.tmLanguage.json | 2 +- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 3465088..54c68f3 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ Skript language support for VS Code / VSCodium. - **Syntax highlighting** for `.sk` files (functions, commands, events, variables, types, effects). - **Minecraft/Bukkit chat color codes** inside strings are rendered live using their real in-game color/style, following actual chat rendering rules (a color code resets formatting, format codes stack, `&r` resets both): - Legacy codes `&0`-`&f` (color) and `&l/&m/&n/&o` (bold/strikethrough/underline/italic), e.g. `"&cRed &lbold text"`. - - Hex tags `<#rrggbb>`, using the *exact* color parsed out of the tag itself, e.g. `"<#f18d8d>this text is actually that pink"`. + - Hex tags `<#rrggbb>` (and the double-hash `<##rrggbb>` variant some addons use), using the *exact* color parsed out of the tag itself, e.g. `"<#f18d8d>this text is actually that pink"`. - This part is implemented as live editor decorations (not just static theme colors), since an arbitrary hex value can't be baked into a fixed color theme. -- **Color picker support for `<#rrggbb>` tags** — VS Code's built-in color swatch/picker only recognizes a bare `#rrggbb` with nothing around it by default, so it never matched Skript's `<...>`-wrapped hex tags. A `DocumentColorProvider` is registered for `.sk` files so the swatch shows up next to `<#rrggbb>` tags and picking a new color rewrites the tag correctly (including the brackets). +- **Color picker support for `<#rrggbb>`/`<##rrggbb>` tags** — VS Code's built-in color swatch/picker only recognizes a bare `#rrggbb` with nothing around it by default, so it never matched Skript's `<...>`-wrapped hex tags. A `DocumentColorProvider` is registered for `.sk` files so the swatch shows up next to either tag form and picking a new color rewrites it correctly (including the brackets, and preserving whichever of `#`/`##` the original tag used). - **R4TSK Dark theme** — same UI color palette as VS Code's built-in "Dark 2026" theme, with hand-authored syntax colors for Skript instead of the default ones. - **Hover call-signature preview** — hover over a function call site, e.g. `functionname("123", true, {object})`, and see the function it resolves to: ``` @@ -103,7 +103,7 @@ npm run package # produce a .vsix via vsce ``` To try it locally: open this folder in VS Code / VSCodium and press F5, or install the -built `r4tsk-1.0.4.vsix` via the "Install from VSIX" command. +built `r4tsk-1.0.5.vsix` via the "Install from VSIX" command. Open [`examples/example.sk`](examples/example.sk) for a single script touching every feature above (doc comments, annotations, hover, `local function` scoping, color codes, diagnostics, and more). diff --git a/package-lock.json b/package-lock.json index cff631a..4afa150 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "r4tsk", - "version": "1.0.4", + "version": "1.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "r4tsk", - "version": "1.0.4", + "version": "1.0.5", "license": "UNLICENSED", "devDependencies": { "@types/node": "^20.14.0", diff --git a/package.json b/package.json index 899b2cc..cc96dd8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "r4tsk", "displayName": "r4tsk - Skript Language Support", "description": "Skript language support: syntax highlighting, hover call-signature preview, autocomplete, diagnostics, go-to-definition and a bundled dark theme.", - "version": "1.0.4", + "version": "1.0.5", "publisher": "r4tsk", "license": "UNLICENSED", "repository": { diff --git a/src/providers/colorProvider.ts b/src/providers/colorProvider.ts index d71fca1..8a1fa5f 100644 --- a/src/providers/colorProvider.ts +++ b/src/providers/colorProvider.ts @@ -1,13 +1,14 @@ import * as vscode from "vscode"; import { findStringContentRanges } from "../utils/textScanning"; -const HEX_TAG = /<#([0-9a-fA-F]{6})>/g; +const HEX_TAG = /<#{1,2}([0-9a-fA-F]{6})>/g; /** * Lets VS Code's built-in color swatch/picker work on Skript's `<#rrggbb>` - * hex color tags. The default color detection VS Code falls back to when a - * language has no DocumentColorProvider only recognizes a bare `#rrggbb` - * with nothing around it, so it never matches Skript's `<...>` wrapper. + * (and `<##rrggbb>`) hex color tags. The default color detection VS Code + * falls back to when a language has no DocumentColorProvider only recognizes + * a bare `#rrggbb` with nothing around it, so it never matches Skript's + * `<...>` wrapper. */ export class SkriptColorProvider implements vscode.DocumentColorProvider { provideDocumentColors(document: vscode.TextDocument): vscode.ColorInformation[] { @@ -32,8 +33,15 @@ export class SkriptColorProvider implements vscode.DocumentColorProvider { return results; } - provideColorPresentations(color: vscode.Color): vscode.ColorPresentation[] { - return [new vscode.ColorPresentation(`<#${colorToHex(color)}>`)]; + provideColorPresentations( + color: vscode.Color, + context: { document: vscode.TextDocument; range: vscode.Range } + ): vscode.ColorPresentation[] { + // Preserve the original tag's "#" count (<#rrggbb> vs <##rrggbb>) rather + // than always collapsing back to a single "#" when a color is picked. + const original = context.document.getText(context.range); + const hashes = /^<(#{1,2})/.exec(original)?.[1] ?? "#"; + return [new vscode.ColorPresentation(`<${hashes}${colorToHex(color)}>`)]; } } diff --git a/src/utils/colorCodes.ts b/src/utils/colorCodes.ts index 8550794..85698e8 100644 --- a/src/utils/colorCodes.ts +++ b/src/utils/colorCodes.ts @@ -34,7 +34,7 @@ const LEGACY_COLORS: Record = { f: "#FFFFFF", }; -const TAG_PATTERN = /&([0-9a-fklmnor])|<#([0-9a-fA-F]{6})>/gi; +const TAG_PATTERN = /&([0-9a-fklmnor])|<#{1,2}([0-9a-fA-F]{6})>/gi; export function scanColorRuns(text: string): ColorRun[] { const runs: ColorRun[] = []; diff --git a/syntaxes/skript.tmLanguage.json b/syntaxes/skript.tmLanguage.json index f0bba52..eb9750b 100644 --- a/syntaxes/skript.tmLanguage.json +++ b/syntaxes/skript.tmLanguage.json @@ -93,7 +93,7 @@ { "include": "#bukkit-color-codes" }, { "name": "constant.other.color.hextag.skript", - "match": "<#[0-9a-fA-F]{6}>" + "match": "<#{1,2}[0-9a-fA-F]{6}>" }, { "name": "meta.embedded.expression.skript", From 01ae7eba5ea193780832366911d0380ed0160b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R4T=20=E1=B5=88=E1=B5=89=E1=B5=9B?= <153876514+RATR2@users.noreply.github.com> Date: Sat, 11 Jul 2026 08:49:35 -0500 Subject: [PATCH 2/3] Don't color the color-tag markup itself, only the text it affects scanColorRuns started each colored run at the tag's own position (match.index), so the literal tag characters (&c, <#5f0202>, etc.) got colored the same as the text that followed them - not just the text the tag is meant to style. This is invisible for a subtle legacy code, but very noticeable for hex tags with an extreme color: <#5f0202> (near-black dark red) made the 9-character tag markup itself nearly illegible against a dark theme, and <#fffb00> (near-white bright yellow) made it look like a glaring highlighted block - both reported as "colors are weird" from a real file. Real chat rendering never shows the tag as literal text either way (it's a control sequence consumed by the client), so only coloring what comes after it is both more correct and avoids this. Fixed by starting the run after the matched tag instead of at it. --- README.md | 2 +- src/utils/colorCodes.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 54c68f3..26d8b53 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Skript language support for VS Code / VSCodium. - **Syntax highlighting** for `.sk` files (functions, commands, events, variables, types, effects). - **Minecraft/Bukkit chat color codes** inside strings are rendered live using their real in-game color/style, following actual chat rendering rules (a color code resets formatting, format codes stack, `&r` resets both): - Legacy codes `&0`-`&f` (color) and `&l/&m/&n/&o` (bold/strikethrough/underline/italic), e.g. `"&cRed &lbold text"`. - - Hex tags `<#rrggbb>` (and the double-hash `<##rrggbb>` variant some addons use), using the *exact* color parsed out of the tag itself, e.g. `"<#f18d8d>this text is actually that pink"`. + - Hex tags `<#rrggbb>` (and the double-hash `<##rrggbb>` variant some addons use), using the *exact* color parsed out of the tag itself, e.g. `"<#f18d8d>this text is actually that pink"`. Only the text *after* the tag is colored - the tag's own literal characters aren't, matching how it's an invisible control sequence in real chat rendering (coloring the tag markup itself with an extreme color, e.g. a very dark or very bright hex value, made the tag syntax look broken/illegible rather than just styling the text it affects). - This part is implemented as live editor decorations (not just static theme colors), since an arbitrary hex value can't be baked into a fixed color theme. - **Color picker support for `<#rrggbb>`/`<##rrggbb>` tags** — VS Code's built-in color swatch/picker only recognizes a bare `#rrggbb` with nothing around it by default, so it never matched Skript's `<...>`-wrapped hex tags. A `DocumentColorProvider` is registered for `.sk` files so the swatch shows up next to either tag form and picking a new color rewrites it correctly (including the brackets, and preserving whichever of `#`/`##` the original tag used). - **R4TSK Dark theme** — same UI color palette as VS Code's built-in "Dark 2026" theme, with hand-authored syntax colors for Skript instead of the default ones. diff --git a/src/utils/colorCodes.ts b/src/utils/colorCodes.ts index 85698e8..06fc45d 100644 --- a/src/utils/colorCodes.ts +++ b/src/utils/colorCodes.ts @@ -74,7 +74,13 @@ export function scanColorRuns(text: string): ColorRun[] { else if (legacy === "o") italic = true; // "k" (obfuscated) has no static color/style equivalent - ignored. - runStart = match.index; + // The tag itself (e.g. "&c", "<#5f0202>") is a control sequence - in + // real chat rendering it's never actually shown, only the text after it + // is. Starting the run after the tag (not at it) keeps that consistent: + // coloring the tag's own literal characters with an extreme color (very + // dark or very bright) made the tag syntax itself look broken/illegible, + // rather than just styling the text it actually affects. + runStart = match.index + match[0].length; } flush(text.length); From d161693a07a71ea93711c1d06f32887b08de7cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R4T=20=E1=B5=88=E1=B5=89=E1=B5=9B?= <153876514+RATR2@users.noreply.github.com> Date: Sat, 11 Jul 2026 09:11:44 -0500 Subject: [PATCH 3/3] Revert "Don't color the color-tag markup itself, only the text it affects" This reverts commit 01ae7eba5ea193780832366911d0380ed0160b8a. --- README.md | 2 +- src/utils/colorCodes.ts | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 26d8b53..54c68f3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Skript language support for VS Code / VSCodium. - **Syntax highlighting** for `.sk` files (functions, commands, events, variables, types, effects). - **Minecraft/Bukkit chat color codes** inside strings are rendered live using their real in-game color/style, following actual chat rendering rules (a color code resets formatting, format codes stack, `&r` resets both): - Legacy codes `&0`-`&f` (color) and `&l/&m/&n/&o` (bold/strikethrough/underline/italic), e.g. `"&cRed &lbold text"`. - - Hex tags `<#rrggbb>` (and the double-hash `<##rrggbb>` variant some addons use), using the *exact* color parsed out of the tag itself, e.g. `"<#f18d8d>this text is actually that pink"`. Only the text *after* the tag is colored - the tag's own literal characters aren't, matching how it's an invisible control sequence in real chat rendering (coloring the tag markup itself with an extreme color, e.g. a very dark or very bright hex value, made the tag syntax look broken/illegible rather than just styling the text it affects). + - Hex tags `<#rrggbb>` (and the double-hash `<##rrggbb>` variant some addons use), using the *exact* color parsed out of the tag itself, e.g. `"<#f18d8d>this text is actually that pink"`. - This part is implemented as live editor decorations (not just static theme colors), since an arbitrary hex value can't be baked into a fixed color theme. - **Color picker support for `<#rrggbb>`/`<##rrggbb>` tags** — VS Code's built-in color swatch/picker only recognizes a bare `#rrggbb` with nothing around it by default, so it never matched Skript's `<...>`-wrapped hex tags. A `DocumentColorProvider` is registered for `.sk` files so the swatch shows up next to either tag form and picking a new color rewrites it correctly (including the brackets, and preserving whichever of `#`/`##` the original tag used). - **R4TSK Dark theme** — same UI color palette as VS Code's built-in "Dark 2026" theme, with hand-authored syntax colors for Skript instead of the default ones. diff --git a/src/utils/colorCodes.ts b/src/utils/colorCodes.ts index 06fc45d..85698e8 100644 --- a/src/utils/colorCodes.ts +++ b/src/utils/colorCodes.ts @@ -74,13 +74,7 @@ export function scanColorRuns(text: string): ColorRun[] { else if (legacy === "o") italic = true; // "k" (obfuscated) has no static color/style equivalent - ignored. - // The tag itself (e.g. "&c", "<#5f0202>") is a control sequence - in - // real chat rendering it's never actually shown, only the text after it - // is. Starting the run after the tag (not at it) keeps that consistent: - // coloring the tag's own literal characters with an extreme color (very - // dark or very bright) made the tag syntax itself look broken/illegible, - // rather than just styling the text it actually affects. - runStart = match.index + match[0].length; + runStart = match.index; } flush(text.length);