Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Swift Color PreviewNew to Visual Studio Code? Get it now.
Swift Color Preview

Swift Color Preview

Christoffer R

|
2 installs
| (0) | Free
Inline swatches and a color picker for SwiftUI Color literals in .swift files
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Swift Color Preview

Inline color swatches and a color picker for SwiftUI Color literals in .swift files.

Every supported Color(...) literal gets a swatch in the gutter of the line it sits on. Clicking the swatch opens VS Code's built-in color picker; picking a color rewrites the literal in place.

Supported initializers

Form Example
RGB Color(red: 0.046, green: 0.020, blue: 0.855)
HSB Color(hue: 0.6, saturation: 0.8, brightness: 0.9)
Grayscale Color(white: 0.37)

Each form also works with a leading color space and a trailing opacity:

Color(.sRGB, red: 1, green: 0.5765, blue: 0, opacity: 0.22)
Color(.displayP3, white: 0.2)

Behavior

  • The literal's own form is kept. Picking a color in an HSB literal writes HSB back. The picker also lists the other forms if you want to switch.
  • The color space is kept. .sRGB and .displayP3 survive a rewrite untouched.
  • Precision follows the file. A rewrite uses at least three fraction digits, or more if the literal already had more, and drops trailing zeros so 1 stays 1.
  • opacity: is kept once it is written, and added when you pick a translucent color.
  • white: is only offered for a grey color, since it cannot express anything else. Picking a non-grey color in a Color(white:) literal rewrites it as RGB.
  • Computed arguments are left alone. Color(.sRGB, red: 0x99 / 255, …) gets no swatch, because rewriting it would replace the expression with a plain number.
  • Literals inside comments and string literals are ignored.

Development

npm install
npm run compile   # build into out/
npm run watch     # rebuild on change
npm test          # unit tests for the parsing and rendering logic

Press F5 in VS Code to launch an Extension Development Host with the extension loaded (see .vscode/launch.json).

Packaging

npx @vscode/vsce package

Install the resulting .vsix with Extensions: Install from VSIX… in the command palette.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft