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",