Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/backtick-expand-only-in-styled.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": patch
---

Typing a backtick no longer offers to expand it into a multi-line template everywhere. The "expand template string" suggestion now appears only when the backtick opens a styled template (#386).
5 changes: 5 additions & 0 deletions .changeset/color-picker-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": patch
---

The color picker now writes the same values VS Code's picker writes in `.css` files. A semi-transparent hex color always gets a valid two-digit alpha (`#ff00000d` rather than `#ff0000c`), and `hsl()` values use whole numbers.
5 changes: 5 additions & 0 deletions .changeset/enter-after-nested-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": patch
---

Picking a CSS property from the suggestion list and pressing Enter fills in `: ;` again when the template holds a nested template string inside `${}` (#437). It also works when the styled tag is spread across several lines.
5 changes: 5 additions & 0 deletions .changeset/faster-highlighting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": patch
---

Syntax highlighting is about 8% faster on average, measured over about 5,800 lines of styled-components code in JavaScript and TSX, both the first time the editor highlights a file and after. Files with very long single lines gained the most, highlighting about 65% faster on average.
5 changes: 5 additions & 0 deletions .changeset/fix-highlighting-spill.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": patch
---

Syntax highlighting no longer breaks for the rest of the file after certain styled components. These now highlight correctly, along with the code below them: a template right after a call whose arrow function returns an object or JSX, like `foo(() => ({ ... }))` or MUI's `styled(({ className, ...props }) => (...))` pattern (#383); `.attrs()` that uses props, even across several lines (#292); a props type written over several lines, like `styled.div<{ color: string }>` broken onto new lines (#358); TypeScript type parameters after `styled.div` (#442); a styled component passed into a function such as `React.memo` (#196); and templates after `Comp.extend`, `keyframes`, and `.withComponent()`.
5 changes: 5 additions & 0 deletions .changeset/keyframe-percent-selectors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": patch
---

Keyframe selectors with decimals, like `33.3%`, now highlight as one selector inside an `@keyframes` block, the same as they already did in a `keyframes` template.
5 changes: 5 additions & 0 deletions .changeset/minimum-vscode-1-74.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": patch
---

The extension now needs VS Code 1.74 or later, so VS Code starts it for the Enter-key `: ;` command in any JavaScript or TypeScript file, not only after a JSX or TSX file opens.
5 changes: 5 additions & 0 deletions .changeset/modern-css-function-highlighting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": minor
---

Modern CSS functions such as `oklch()`, `color-mix()`, `clamp()`, and `light-dark()` now highlight as functions inside styled templates, and `light-dark()` no longer breaks apart at the hyphen.
5 changes: 5 additions & 0 deletions .changeset/more-styled-tag-shapes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": minor
---

CSS highlighting now works in more of the ways you write styled components: a tag chain, on one line or split across lines by Prettier (`styled.div` or `Button.extend`, then any number of `.attrs()` and `.withConfig()` calls), a comment between `styled.div` and its backtick, a tag reached through an object (`theme.styled.div`, `$styled.div`, `theme.css`) or through a call or index (`getTheme().styled.div`, `items[0].styled.div`), type arguments that span several lines, including on `theme.keyframes`, and an arrow function whose parameter starts with `$` or has no parentheses, like `styled.div(($props) => ...)` or `styled.div(p => ...)`.
5 changes: 5 additions & 0 deletions .changeset/space-separated-rgb-hsl-swatches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": patch
---

Space-separated `rgb()` and `hsl()` colors now show a color swatch and open the color picker, with or without a `/ alpha` value, like `hsl(220 30% 95%)` and `rgb(255 0 153 / 50%)` (#455).
5 changes: 5 additions & 0 deletions .changeset/wide-gamut-color-swatches.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vscode-styled-components": minor
---

`hwb()`, `lab()`, `lch()`, `oklab()`, and `oklch()` colors now show a color swatch, and the color picker can write any color in these five formats.
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ version: 2
updates:
- package-ecosystem: github-actions
directory: /
commit-message:
prefix: ci
cooldown:
default-days: 7
schedule:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ jobs:
- name: Check formatting
run: npm run lint

- name: Typecheck
run: npx tsc --noEmit -p .

- name: Unit tests
run: npm run test:unit

test:
name: Test (${{ matrix.os }})
strategy:
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/commit-messages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Commit Messages

# Separate from ci.yml so editing a PR title reruns only this check, not the OS matrix.
on:
pull_request:
branches:
- main
types: [opened, edited, synchronize, reopened]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

permissions:
contents: read

jobs:
commit-messages:
name: Commit messages
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

# A squash merge commits the PR title; a rebase merge commits each commit.
- name: Check the PR title and every commit
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
status=0
sh scripts/check-commit-message.sh -m "$PR_TITLE" || status=1
for sha in $(git rev-list "$BASE_SHA..$HEAD_SHA"); do
git log -1 --format=%B "$sha" > "$RUNNER_TEMP/message"
sh scripts/check-commit-message.sh "$RUNNER_TEMP/message" || status=1
done
exit $status
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ jobs:

- run: npm ci

# With pending changesets this opens or updates the "Version Packages" PR; once that PR merges,
# With pending changesets this opens or updates the "chore: version packages" PR; once that PR merges,
# `npm run release` publishes to the VS Code Marketplace via trusted publishing (OIDC) and tags vX.Y.Z.
# RELEASE_GITHUB_TOKEN (a PAT) lets CI run on the version PR; the job token works but triggers no checks.
- name: Version or publish
uses: changesets/action@ae32849d5ba541f9ae29e40e22a623bc13562f51 # v2.1.2
with:
commit-message: "chore: version packages"
github-token: ${{ secrets.RELEASE_GITHUB_TOKEN || github.token }}
pr-title: "chore: version packages"
publish-script: npm run release
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.DS_Store
node_modules
dist
.vscode-test
.integration-test/
syntaxes/*.json
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sh scripts/check-commit-message.sh --local "$1"
6 changes: 5 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ package-lock.json
.github
node_modules
.vscode-test
src/tests
.integration-test/
src/tests/suite/colorize-fixtures
src/tests/suite/colorize-results
dist
.claude/
syntaxes/src/css.tmLanguage.json
7 changes: 4 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/src/tests/suite/colorize-fixtures"
],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
Expand All @@ -24,9 +24,10 @@
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/src/tests/suite/index.js"
"--extensionTestsPath=${workspaceFolder}/.integration-test/index.js"
],
"internalConsoleOptions": "openOnSessionStart"
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "npm: pretest"
}
]
}
7 changes: 7 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
},
"label": "npm: watch",
"detail": "ESBuild watch mode"
},
{
"type": "npm",
"script": "pretest",
"problemMatcher": [],
"label": "npm: pretest",
"detail": "Build the extension and bundle the integration tests"
}
]
}
8 changes: 6 additions & 2 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
.changeset/**
.claude/**
.editorConfig
.github/**
.gitignore
.husky/**
.nvmrc
.prettierignore
.integration-test/**
.vscode-test/**
.vscode/**
**/*.map
build.mjs
AGENTS.md
build.mts
scripts/**
docs/**
src/**
test/
syntaxes/src/**
tsconfig.json
46 changes: 29 additions & 17 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,32 @@ This file is the index for agents working in this repo. It holds only one-line r

- `npm ci`: install (npm, `package-lock.json`)
- `npm test`: build, then run the integration suite in a downloaded VS Code (opens a VS Code window; on headless Linux run `xvfb-run -a npm test`)
- `npx tsc --noEmit -p .`: typecheck (`npm test` bundles with esbuild, which does not typecheck)
- `npm run test:unit`: unit tests (`src/**/*.test.ts` outside the integration suites, and `syntaxes/src/**/*.test.ts`) in Node, no window
- `npm run tokenize -- [--sentinel | --drift] [--grammars <dir>] <files>`: headless tokenizer, no window; modes in the spec, "Test strategy"
- `npm run bench:grammar -- [<baselineSyntaxesDir>...]`: grammar speed against the spec's "Performance" bar
- `npx tsc --noEmit -p .`: typecheck every TypeScript file (`npm test` bundles with esbuild, which does not typecheck)
- `npm run lint` / `npm run format`: Prettier check / write (the pre-commit hook and CI run the check)
- `npm run watch`: rebuild on change; press F5 in VS Code to launch the extension against the colorize fixtures
- `npx changeset`: describe a user-facing change
- Workflow audit: the "Workflow Security" CI job (`.github/workflows/zizmor.yml`) runs zizmor on every `.github/` change. To run it locally, [install zizmor](https://docs.zizmor.sh/installation/), then `zizmor .github/workflows`

## Map

- [docs/spec.md](docs/spec.md): authoritative behavior spec; edit it before the code
- `src/extension.ts`: activation; registers the providers below
- `src/colorProvider.ts`: color swatches and color picker presentations
- `src/insertColonCommand.ts`, `src/patterns.ts`: the Enter-key `: ;` command; decides "inside CSS" from the injection grammar's begin/end regexes
- `src/insertColonCommand.ts`: the Enter-key `: ;` command
- `src/completionItemProvider.ts`: the backtick-expansion snippet
- `syntaxes/styled-components.json`: injection grammar (scope `styled`) into JS/TS/JSX/TSX/Vue/Svelte
- `syntaxes/css.styled.json`: the embedded CSS grammar (scope `source.css.styled`)
- `src/templateScanner.ts`: `isInsideStyledTemplate`, the "inside a styled template" check `insertColonCommand.ts` and `completionItemProvider.ts` use
- `syntaxes/src/styled-components.mts`: injection grammar source (scope `styled`); hosts and tag shapes in the spec
- `syntaxes/src/css.styled.mts`, `syntaxes/src/ownCss.mts`: embedded CSS grammar source (scope `source.css.styled`); copies its CSS rules from `syntaxes/src/css.tmLanguage.json`, VS Code's CSS grammar, vendored
- `syntaxes/src/generate.mts`: writes `syntaxes/*.json` (build output, git-ignored)
- `ThirdPartyNotices.txt`: license notice for the vendored CSS grammar
- IntelliSense and diagnostics: the bundled `@styled/typescript-styled-plugin` (separate repo, styled-components/typescript-styled-plugin), registered as a TS server plugin in `package.json`
- `src/tests/runTests.js`: pins the VS Code version tests run against
- `src/tests/vscodeVersion.mts`: pins the VS Code version the tests, the tokenizer, and the grammar benchmark use
- `src/tests/suite/*.test.ts`: integration suites; `scripts/bundle-integration-tests.mts` bundles them into `.integration-test/` in `pretest`
- `src/tests/suite/colorize-fixtures/` and `colorize-results/`: grammar snapshot tests
- `scripts/`: the tokenizer, the grammar benchmark, the unit and integration bundlers, and `check-commit-message.sh` (the Conventional Commits check)
- `.vscodeignore`: what ships in the published package
- `.changeset/`, `.github/workflows/release.yml`: release pipeline
- [CONTRIBUTING.md](CONTRIBUTING.md): grammar authoring, plugin debugging, tests, releasing
Expand All @@ -35,35 +44,37 @@ This file is the index for agents working in this repo. It holds only one-line r
### Prose and communication

- American English, no em-dashes. Human-facing text (README, changesets, PR descriptions, issue replies) uses plain words and leads with user impact; agent-facing text uses the most precise term.
- A changeset is one short paragraph per user-noticeable change, leading with the visible effect; no mechanism, no internal-only changes, no unmeasured claims.
- A changeset is one short paragraph per user-noticeable change, leading with the visible effect; a speed claim gives the average percent change and the conditions measured, never absolute timings; no mechanism, no internal-only changes, no unmeasured claims.
- No "Generated by" or attribution footers or trailers in commits, PRs, or files.
- A user-facing message (`window.show*Message`) states the problem and the fix in plain language, with no internals.

### Correctness and types

- `tsconfig.json` is `strict`; types are law. No `as any`, non-null `!`, or `@ts-expect-error`, and no new type-assertion casts; remove existing ones in code you touch.
- Public contract, changed only with a major changeset: grammar scope names (themes and other extensions match them), the language id `source.css.styled`, the command id `extension.insertColonOrSemiColon`, and the extension id. Everything else is internal and may be rewritten freely.
- The public contract (spec, "Public contract") changes only with a major changeset; everything else is internal and may be rewritten freely.
- TextMate rules match one line at a time; a rule that needs a newline never matches. Write a rule per line shape (CONTRIBUTING.md, "A line break seems to break the syntax highlighting").
- Grammar regexes are Oniguruma, not JavaScript. `src/patterns.ts` converts POSIX classes for reuse in JS; a grammar change that adds other Oniguruma-only syntax breaks `insertColonCommand` silently.
- Grammar regexes are Oniguruma, not JavaScript; check one with `npm run tokenize`, never a JavaScript regex engine.
- The grammar and `src/templateScanner.ts` each decide which templates are styled; a tag-shape change updates both, and the scanner's differential test against `colorize-results/` fails on a new disagreement.
- A file Node runs directly (`build.mts`, `scripts/`, the generators, the test runner) is `.mts`, imports with explicit `.mts` or `.ts` extensions, and uses only erasable TypeScript syntax: Node strips its types with no build step.

### Testing and validation

- Every grammar change adds or updates a fixture in `src/tests/suite/colorize-fixtures/` and commits the regenerated `colorize-results/` file. Review every changed token: a first run on a new fixture writes its result and passes without comparing anything, so the committed JSON is the assertion.
- Every grammar change adds or updates a fixture in `src/tests/suite/colorize-fixtures/` and commits the regenerated `colorize-results/` file. Review every changed token: the committed JSON is the assertion (spec, "Test strategy").
- Treat colorize-results drift with suspicion; a token change outside the edited rule is a regression until proven otherwise.
- Bump the pinned VS Code version in `src/tests/runTests.js` deliberately, regenerating and reviewing all results in the same commit.
- Bump the pinned VS Code version in `src/tests/vscodeVersion.mts` deliberately: replace `syntaxes/src/css.tmLanguage.json` with the new build's CSS grammar, then regenerate and review all results in the same commit (CONTRIBUTING.md, "Tests").
- A bug fix starts with a red test (fixture or suite test), then goes green.
- Test names read as spec sentences ("activates without an error").

### Inputs and error handling

- Document text is untrusted (any opened workspace file). Regexes run over it must not backtrack catastrophically (no nested or overlapping quantifiers) and should scan a bounded range, not the whole document, per keystroke.
- Document text is untrusted (any opened workspace file). Regexes run over it must not backtrack catastrophically (no nested or overlapping quantifiers), and a scan that runs per keystroke runs in linear time within the spec's "Performance" budget.
- No empty or log-only `catch`; handle the failure or let it surface.

### Organization and naming

- One provider or command per file in `src/`; `extension.ts` only wires them.
- Grammar regexes live JSON-escaped in `syntaxes/*.json`; decode before editing, re-encode after (CONTRIBUTING.md, "Syntax").
- Never reorder grammar `patterns` arrays for tidiness: TextMate tries rules in order, so order is behavior.
- Edit the grammar generators in `syntaxes/src/`, never the generated `syntaxes/*.json` (CONTRIBUTING.md, "Syntax").
- Never reorder the generators' pattern arrays for tidiness: TextMate tries rules in order, so order is behavior.
- Split a file past ~4,000 lines.

### Comments and docs
Expand All @@ -75,7 +86,7 @@ This file is the index for agents working in this repo. It holds only one-line r
### Security and data

- The extension makes no network calls and collects no data; keep it that way.
- Releases publish through Marketplace trusted publishing (OIDC). Never add a long-lived publish token or secret.
- Never add a long-lived publish token or secret (spec, "Packaging and release").
- Workflow hardening is enforced by zizmor in CI: SHA-pinned actions with a version comment, least-privilege `permissions`, `persist-credentials: false`, no dependency cache in the release job. Depth: [docs/github-actions.md](docs/github-actions.md).
- Package install scripts stay off (npm's `allowScripts` gate); approve one only on demonstrated breakage, with a one-line reason.

Expand All @@ -85,13 +96,14 @@ This file is the index for agents working in this repo. It holds only one-line r

### Performance

- The color provider and the grammar run on every edit. Validate a change to either against the previous code with a microbenchmark on a large file; never trade behavior for speed without a measurement.
- The color provider and the grammar run on every edit. Validate a change to either against the previous code (`npm run bench:grammar` for the grammar, the linear-scaling test in `src/colorParsing.test.ts` for the color provider); never trade behavior for speed without a measurement.
- Keep measured figures (timings, sizes) out of docs; state the budget and the command that measures it.

### Git and process

- Every PR with a user-facing change adds a changeset (`npx changeset`); CI, docs, and test-only PRs add none.
- Merging to `main` opens or updates the "Version Packages" PR; merging that PR publishes. Never bump `version` or edit `CHANGELOG.md` by hand.
- Commit messages and PR titles follow Conventional Commits (`type(scope): subject`); the commit-msg hook and the "Commit messages" CI job enforce it (CONTRIBUTING.md, "Commit messages").
- Every PR with a user-facing change adds one changeset per change, written directly as `.changeset/<kebab-case-name>.md` (`npx changeset` is interactive), bumping patch for a fix or speedup, minor for new behavior, major for a public-contract change; template and traps in [docs/changesets.md](docs/changesets.md). CI, docs, and test-only PRs add none.
- Merging to `main` opens or updates the "chore: version packages" PR; merging that PR publishes. Never bump `version` or edit `CHANGELOG.md` by hand.
- A dependency change updates `package-lock.json` in the same commit and is verified with `npm test`.
- Never `git stash`; use a temporary commit. Never force-push `main`.

Expand Down
Loading
Loading