Skip to content

feat: stop highlighting leaks, fix the Enter command and snippet, and add modern color swatches - #465

Merged
quantizor merged 15 commits into
mainfrom
spec-and-issue-fixes
Nov 19, 2026
Merged

quantizor merged 15 commits into
mainfrom
spec-and-issue-fixes

Conversation

@quantizor

@quantizor quantizor commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes the highlighting, Enter-key, snippet, and color-swatch bugs from the open issue triage, and adds what styled-components v7 users need: swatches for wide-gamut colors and highlighting for modern CSS functions.

What changes for you

Highlighting stays inside the template. CSS highlighting no longer spills into the code after a template's closing backtick (#383, #292, #358, #442, #196).

More ways of writing styled components highlight. Examples:

  • Prettier-split tag chains (styled.div or Button.extend, then any number of .attrs() and .withConfig() calls)
  • A comment between styled.div and its backtick
  • Tags reached through an object, a call, or an index (theme.styled.div, $styled.div, getTheme().styled.div)
  • Type arguments that span several lines
  • Arrow functions like styled.div(($props) => ...) and styled.div(p => ...)

Modern CSS highlights. Functions such as oklch(), color-mix(), clamp(), and light-dark() highlight as functions. Keyframe selectors with decimals, like 33.3%, highlight as one selector inside an @keyframes block.

Highlighting is faster. Highlighting is about 8% faster on average. This was measured over about 5,800 lines of styled-components code in JavaScript and TSX, both on the first highlight of a file and after. Very long single lines gained the most, about 65% faster on average.

The Enter key works after a nested template. Pressing Enter on a suggested property inserts : ; even when the template holds another template, like ${css...} (#437).

The backtick snippet appears only where it belongs. "expand template string" is offered only right after a backtick that opens a styled template (#386).

Color swatches cover modern formats. These now show swatches and open the color picker:

The picker writes the same values VS Code writes in .css files. A semi-transparent hex color always gets a valid two-digit alpha.

VS Code 1.74 or later is required. VS Code then starts the extension for the Enter command in any JavaScript or TypeScript file, not only after a JSX or TSX file opens. Anyone on an older VS Code keeps the version they have.

For contributors

  • docs/spec.md is the behavior spec. It covers recognized tags, the Enter command, the snippet, color formats, performance budgets, and the public contract. A behavior change edits it first.
  • The grammars are generated from TypeScript in syntaxes/src/. VS Code's CSS grammar is vendored and its rules are copied in, so highlighting is the same whichever VS Code version you run.
  • Every highlighting fixture ends with const sentinel = 1;. A leak changes that line's scopes, and the test fails.
  • npm run test:unit, npm run tokenize, and npm run bench:grammar run without opening a VS Code window.
  • ThirdPartyNotices.txt now also credits atom/language-sass, the source of the grammar's SCSS-derived rules.
  • Commit messages and PR titles follow Conventional Commits, checked by a commit-msg hook and a CI job.

Public contract

This is a minor release; nothing a theme or another extension relies on changes. The spec now lists, as stable, the extension id, the grammar scopes, the command id, and the extension's own CSS scope names (the .scss names that VS Code's default themes color). Names that come from VS Code's own grammars follow those grammars.

@changeset-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a6a6e35

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
vscode-styled-components Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@socket-security

socket-security Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedvscode-oniguruma@​2.0.11001008385100
Addedvscode-textmate@​9.3.210010010087100

View full report

Node runs the .mts build and test scripts directly (Node 22.18 or later), and tsc typechecks every TypeScript file. The integration suites are bundled with esbuild before the test run, and unit tests run in Node without a VS Code window. glob and d3-color are no longer dependencies.
A commit-msg hook and a "Commit messages" CI job check each message and the PR title. The release PR and Dependabot PRs use conventional titles, and CI runs the unit tests and typecheck in the Lint job.
The tokenizer prints tokens with the pinned VS Code's grammars without opening a window, checks sentinel lines, and compares fixtures with their committed results. The benchmark compares grammar speed against other grammar folders. Every fixture ends with a sentinel line that fails the colorization suite when highlighting leaks.
…eaks, and highlight modern CSS

The grammars are generated from TypeScript sources, with VS Code's CSS grammar vendored and its rules copied in. Highlighting no longer spills past a template's closing backtick, more tag shapes are recognized, modern CSS functions highlight as functions, and CSS tokenizes faster.

Fixes #383, #292, #358, #442, #196
…hat agrees with the grammar

The Enter command and the backtick snippet share one scanner over the text before the cursor. It handles nested templates and matches the grammar's tag shapes, a differential test checks it against every colorize result, and the snippet is offered only after a backtick that opens a styled template.

Fixes #437, #386
Space-separated rgb() and hsl(), hwb(), lab(), lch(), oklab(), and oklch() get swatches, hex alpha pads correctly, and the color picker writes readable hsl.

Fixes #455
@quantizor
quantizor force-pushed the spec-and-issue-fixes branch 2 times, most recently from 5357498 to 4bb117a Compare November 19, 2026 20:19
@quantizor
quantizor force-pushed the spec-and-issue-fixes branch from 4bb117a to 314a82b Compare November 19, 2026 20:20
@quantizor quantizor changed the title Behavior spec, leak-catching tests, and fixes for highlighting, Enter, snippet, and colors feat: stop highlighting leaks, fix the Enter command and snippet, and add modern color swatches Nov 19, 2026
@quantizor
quantizor marked this pull request as ready for review November 19, 2026 20:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The integration suite stalls on an unsaved-fixture dialog, and escaped backticks inside existing styled templates incorrectly trigger the expansion completion.

1 open issue
What changed in this PR

This PR improves styled-components editing in VS Code by addressing highlighting leaks, correcting Enter-key and snippet behavior, and adding modern CSS color support. It also expands regression coverage and updates contributor tooling.

Changes:

  • Broaden styled-template recognition and add fixtures that detect highlighting leaking into surrounding code.
  • Fix nested-template Enter handling, restrict backtick expansion, and support modern color swatches and picker output.
  • Introduce TypeScript-based grammar and test tooling, strengthen CI checks, and document release changes.
File Description
tsconfig.json Extends strict typechecking to tooling and tests.
ThirdPartyNotices.txt Adds notices for inherited CSS and SCSS grammar rules.
syntaxes/​src/​grammarTypes.ts Defines shared grammar types.
syntaxes/​src/​generate.mts Generates the packaged grammar JSON files.
src/​tests/​vscodeVersion.mts Centralizes the existing VS Code test pin.
src/​tests/​suite/​index.ts Adds the TypeScript integration-suite loader.
src/​tests/​suite/​index.js Removes the old JavaScript suite loader.
src/​tests/​suite/​extension.test.ts Converts test imports to TypeScript module syntax.
src/​tests/​suite/​commands.test.ts Tests Enter behavior and snippet eligibility.
src/​tests/​suite/​colorize-results/​typescript-tag_ts.json Records sentinel scopes after typed tags.
src/​tests/​suite/​colorize-results/​typescript-emotion_ts.json Records sentinel scopes after Emotion templates.
src/​tests/​suite/​colorize-results/​typescript-css_ts.json Records sentinel scopes after typed CSS helpers.
src/​tests/​suite/​colorize-results/​typescript_ts.json Records sentinel scopes after generic styled calls.
src/​tests/​suite/​colorize-results/​theme-function_js.json Records sentinel scopes after theme callbacks.
src/​tests/​suite/​colorize-results/​stylesheet_js.json Records sentinel scopes after stylesheet templates.
src/​tests/​suite/​colorize-results/​string-tagname_js.json Records sentinel scopes after string-tag calls.
src/​tests/​suite/​colorize-results/​mixin_js.json Records sentinel scopes after mixins.
src/​tests/​suite/​colorize-results/​inside-method_js.json Records sentinel scopes after method-contained templates.
src/​tests/​suite/​colorize-results/​inside-function_js.json Records sentinel scopes after function-contained templates.
src/​tests/​suite/​colorize-results/​injectGlobal_js.json Records sentinel scopes after global styles.
src/​tests/​suite/​colorize-results/​function-call-space_js.json Records sentinel scopes after spaced styled calls.
src/​tests/​suite/​colorize-results/​function-call_js.json Records sentinel scopes after nested calls.
src/​tests/​suite/​colorize-results/​export-default_js.json Records sentinel scopes after default exports.
src/​tests/​suite/​colorize-results/​dot-tag_js.json Records sentinel scopes after member tags.
src/​tests/​suite/​colorize-results/​css-prop_js.json Records sentinel scopes after CSS props.
src/​tests/​suite/​colorize-results/​createGlobalStyle_js.json Records sentinel scopes after global-style templates.
src/​tests/​suite/​colorize-results/​component_js.json Records sentinel scopes after component wrappers.
src/​tests/​suite/​colorize-results/​comment_js.json Records sentinel scopes after commented templates.
src/​tests/​suite/​colorize-results/​arrow-function_js.json Records sentinel scopes after arrow-function templates.
src/​tests/​suite/​colorize-fixtures/​withConfig.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​withComponent.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​white-space-property.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​variable-assignment.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​typescript.ts Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​typescript-tag.ts Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​typescript-multiline.ts Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​typescript-emotion.ts Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​typescript-css.ts Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​typescript-attr.ts Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​theme-function.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​tag-shapes.ts Covers TypeScript tag shapes and surrounding code.
src/​tests/​suite/​colorize-fixtures/​tag-shapes.js Covers JavaScript tag shapes and surrounding code.
src/​tests/​suite/​colorize-fixtures/​tag-shape-agreement.js Covers tag-recognition agreement cases.
src/​tests/​suite/​colorize-fixtures/​stylesheet.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​string-tagname.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​segmented-component.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​plain-typescript.ts Covers TypeScript expressions that must stay plain.
src/​tests/​suite/​colorize-fixtures/​plain-jsx.tsx Covers TSX expressions that must stay plain.
src/​tests/​suite/​colorize-fixtures/​plain-jsx.js Covers JSX expressions that must stay plain.
src/​tests/​suite/​colorize-fixtures/​plain-comparisons.js Covers comparisons and calls that are not styled templates.
src/​tests/​suite/​colorize-fixtures/​object-literal.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​nextStyle.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​nested-template-strings-with-helper.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​modern-css-functions.js Covers modern and nested CSS functions.
src/​tests/​suite/​colorize-fixtures/​mixin.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​last-declaration.js Covers declarations without trailing semicolons.
src/​tests/​suite/​colorize-fixtures/​keyframes.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​keyframes-selectors.js Covers decimal keyframe selectors.
src/​tests/​suite/​colorize-fixtures/​keyframes-prefixed-generics.ts Covers prefixed keyframes with multiline types.
src/​tests/​suite/​colorize-fixtures/​jsx-in-head.tsx Covers JSX inside styled-call arguments in TSX.
src/​tests/​suite/​colorize-fixtures/​jsx-in-head.js Covers JSX inside styled-call arguments in JavaScript.
src/​tests/​suite/​colorize-fixtures/​interpolation-in-function.js Covers interpolation inside CSS functions and strings.
src/​tests/​suite/​colorize-fixtures/​inside-method.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​inside-function.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​injectGlobal.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​head-multiline.ts Covers multiline TypeScript tag expressions.
src/​tests/​suite/​colorize-fixtures/​head-multiline.js Covers multiline JavaScript tag expressions.
src/​tests/​suite/​colorize-fixtures/​head-comment.js Covers comments between tags and templates.
src/​tests/​suite/​colorize-fixtures/​head-chain-newline.js Covers tag chains split across lines.
src/​tests/​suite/​colorize-fixtures/​generics.tsx Covers complex and multiline generics in TSX.
src/​tests/​suite/​colorize-fixtures/​generics.ts Covers complex and multiline generics in TypeScript.
src/​tests/​suite/​colorize-fixtures/​function-media-queries.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​function-call.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​function-call-with-css-helper.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​function-call-space.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​extend.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​extend-chain.js Covers chained calls after .extend.
src/​tests/​suite/​colorize-fixtures/​export-default.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​dot-tag.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​custom-at-rule.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​css-prop.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​createGlobalStyle.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​component.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​comment.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​closers.js Covers tags following closing delimiters.
src/​tests/​suite/​colorize-fixtures/​call-prefix-root.js Covers styled tags reached through calls.
src/​tests/​suite/​colorize-fixtures/​body-edges.tsx Covers TSX template boundaries and concatenation.
src/​tests/​suite/​colorize-fixtures/​body-edges.js Covers empty templates, nesting, and CSS edge cases.
src/​tests/​suite/​colorize-fixtures/​await-member.js Covers tags reached through imports and indexes.
src/​tests/​suite/​colorize-fixtures/​attrs.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​attrs-arrow-template.tsx Distinguishes configuration templates from styled bodies in TSX.
src/​tests/​suite/​colorize-fixtures/​attrs-arrow-template.js Distinguishes configuration templates from styled bodies in JavaScript.
src/​tests/​suite/​colorize-fixtures/​arrow-function.js Adds a highlighting-leak sentinel.
src/​tests/​suite/​colorize-fixtures/​arrow-call-same-line.ts Covers typed arrow callbacks returning templates.
src/​tests/​suite/​colorize-fixtures/​arrow-call-same-line.js Covers arrow callbacks returning templates.
src/​tests/​suite/​colorization.test.js Removes the legacy JavaScript snapshot suite.
src/​tests/​runTests.mts Launches bundled tests and cleans temporary user data.
src/​tests/​runTests.js Removes the old JavaScript test launcher.
src/​tests/​colorizeToken.mts Adds shared snapshot validation and sentinel helpers.
src/​patterns.ts Removes grammar-to-JavaScript regex conversion.
src/​insertColonCommand.ts Uses template scanning and editor-specific cursor movement.
src/​extension.ts Registers the Enter command during activation.
src/​cssLanguageServiceColors.d.ts Declares CSS language-service color converter types.
src/​completionItemProvider.ts Restricts expansion to backtick-triggered styled contexts.
src/​colorProvider.ts Delegates color parsing and presentation formatting.
scripts/​webAssembly.d.ts Supplies types needed by Oniguruma tooling.
scripts/​unit-tests.mts Bundles and runs unit tests without VS Code.
scripts/​grammarRegistry.mts Loads repository and pinned VS Code grammars.
scripts/​check-commit-message.sh Validates Conventional Commit subjects.
scripts/​bundle-integration-tests.mts Bundles integration suites for the extension host.
README.md Clarifies highlighting and provider scope.
package.json Updates runtime requirements, scripts, and dependencies.
package-lock.json Updates dependency resolutions and root metadata.
docs/​github-actions.md Adjusts version-PR terminology.
docs/​changesets.md Documents changeset authoring and version-PR naming.
build.mts Adds grammar generation and TypeScript build orchestration.
build.mjs Removes the previous JavaScript build script.
.vscodeignore Excludes source tooling and test artifacts from packaging.
.vscode/​tasks.json Adds an integration-test preparation task.
.vscode/​launch.json Launches bundled tests after preparation.
.prettierignore Narrows test exclusions and excludes generated artifacts.
.husky/​commit-msg Runs local commit-message validation.
.gitignore Ignores generated grammars and integration bundles.
.github/​workflows/​release.yml Sets Conventional Commit titles for version PRs and commits.
.github/​workflows/​commit-messages.yml Checks PR titles and commit subjects.
.github/​workflows/​ci.yml Adds typechecking and unit-test steps.
.github/​dependabot.yml Gives dependency-update commits a ci prefix.
.changeset/​wide-gamut-color-swatches.md Announces additional color formats.
.changeset/​space-separated-rgb-hsl-swatches.md Announces modern RGB and HSL swatches.
.changeset/​more-styled-tag-shapes.md Announces broader styled-tag recognition.
.changeset/​modern-css-function-highlighting.md Announces modern CSS function highlighting.
.changeset/​minimum-vscode-1-74.md Announces the minimum VS Code requirement.
.changeset/​keyframe-percent-selectors.md Announces decimal keyframe-selector highlighting.
.changeset/​fix-highlighting-spill.md Describes highlighting-leak fixes.
.changeset/​faster-highlighting.md Reports highlighting performance improvements.
.changeset/​enter-after-nested-template.md Describes restored Enter behavior after nested templates.
.changeset/​color-picker-output.md Describes picker formatting and hex-alpha fixes.
.changeset/​backtick-expand-only-in-styled.md Describes restricted backtick expansion.

Review effort: Balanced

Comment thread src/completionItemProvider.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Accepting a CSS property or function completion discards secondary cursors because the command assigns a single editor.selection instead of preserving all selections.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve secondary cursors when accepting completions

src/​insertColonCommand.ts:55

Assigning editor.selection replaces all selections with the primary one, so accepting a CSS property with multiple cursors now discards every secondary cursor. The function-completion branch at lines 60–61 has the same regression. Use editor.selections to retain all cursors and coordinate their positions with the edits instead of assigning a single selection.

1 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human judgment is needed to assess whether the revised highlighting guidance is misleading given the extension’s language-scope restrictions.

No open issues 🎉

Review effort: Balanced

@quantizor
quantizor merged commit 004e515 into main Nov 19, 2026
8 checks passed
@quantizor
quantizor deleted the spec-and-issue-fixes branch November 19, 2026 21:09
@github-actions github-actions Bot mentioned this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants