# Language service for Master CSS

Set up VS Code, confirm project-aware token completion, inspect generated CSS, and configure class sources and workspaces.

<a id="overview"></a>

## Overview

Use the Master CSS Language Service to discover the classes your project actually supports and inspect their CSS while you edit. Its suggestions read the project's tokens and definitions, including your own utilities, mixins, selectors and conditions.

Start with a project that has [Master CSS installed](/guide/installation). The extension helps author source; your framework integration still delivers the stylesheet to the browser.

---

<a id="set-up-vs-code"></a>

## Set up VS Code

Install the official [Master CSS extension](https://marketplace.visualstudio.com/items?itemName=masterco.master-css-vscode), open the project folder in VS Code, and enable completion inside strings:

```json name=.vscode/settings.json
{
  "editor.quickSuggestions": {
    "strings": true
  }
}
```

The extension discovers project context from a CSS entry importing `@master/css` or a `package.json` declaring a Master CSS package. In a repository with several apps, open a source file in the app whose theme you want to use.

<a id="check-a-project-token"></a>

## Check a project token

Add a spacing token after the existing import in your app's CSS entry:

```css name=app.css
@import '@master/css';

@theme {
  --spacing-card: 1.5rem;
}
```

In an HTML file, type `p-ca` inside a class attribute. Choose `p-card` from the suggestions, then hover the completed class:

```html
<article class="p-card">Field notes</article>
```

**Project definitions become editor vocabulary**

- **Define.** The app stylesheet imports @master/css and declares --spacing-card: 1.5rem in @theme.
- **Complete.** Inside an HTML class attribute, p-ca receives the project-aware completion p-card.
- **Inspect.** Hovering p-card shows its generated padding: var(--spacing-card) declaration. The framework integration still supplies CSS to the page; verify the rendered result separately.

One project token, two editor checks: complete its class name, then inspect the declaration. The editor preview does not establish what wins in the browser.

The hover's generated rule should contain `padding: var(--spacing-card)`. The class name comes from your project token; the declaration keeps a variable reference. Check the page in your browser to see the resulting padding. If `p-card` is missing, resolve the [workspace context](#workspace-aware-manifests) before adding more editor settings.

---

**An editor preview does not deliver a stylesheet**

One source class has two branches: the language service shows generated CSS to the author, while the integration delivers CSS to the browser.

Completion and hover verify authoring context. Verify the actual page through its build and browser as well.

<a id="add-class-sorting-on-save"></a>

## Add class sorting on save

For class policy diagnostics and sort-on-save, first set up [Code linting](/guide/code-linting) and install the [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint). Add these options alongside `editor.quickSuggestions`:

```json name=.vscode/settings.json
{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit"
  },
  "eslint.codeActionsOnSave.rules": [
    "@master/css/sort-classes"
  ]
}
```

Now an explicit save can sort classes using the project's ESLint configuration. The rule list alone does not enable the save action. Keep `eslint.codeActionsOnSave.mode` at its default `all`: the extension's `problems` mode ignores this rule filter. See the [ESLint extension settings](https://github.com/microsoft/vscode-eslint#settings-options).

---

<a id="inspect-styles-as-you-edit"></a>

## Inspect styles as you edit

<a id="complete-classes-and-conditions"></a>

### Complete classes and conditions

Completion works inside configured class sources: markup attributes, bound framework attributes, JavaScript helper calls, tagged templates and project-specific class declarations. Suggestions include utilities, property values, color tokens, selectors, queries and directive syntax, and project tokens appear once the workspace manifest loads.

<a id="read-the-generated-rule"></a>

### Read the generated rule

Hover a class such as `fg-blue-60:hover@sm` to inspect its declaration, selector state and query. This example applies the preset blue token only for the hover state at `sm` and above:

```html
<a class="fg-text-body fg-blue-60:hover@sm" href="/notes">
  Field notes
</a>
```

<a id="syntax-highlighting"></a>

### Syntax highlighting

The extension highlights directive syntax in CSS-family documents and uses semantic tokens for class-list spans: declaration, value, selector, query, unit, important marker, quoted segment and component boundaries. By default it highlights only the class string under the cursor, keeping long markup calm. If semantic colors do not appear, enable semantic highlighting in the active VS Code theme.

Shiki code examples use the same quiet default for markup class attributes, with pointer hover in place of the cursor. Import the public stylesheet alongside `transformerMasterCSS`:

```ts
import '@master/css-language-service/shiki.css'
import { transformerMasterCSS } from '@master/css-language-service/shiki'
```

<a id="color-tools"></a>

### Color tools

Master CSS color utilities and manifest colors use VS Code color decorators and the color picker. Keep both `masterCSS.renderSyntaxColors` and VS Code's [`editor.colorDecorators`](https://code.visualstudio.com/docs/languages/css) enabled.

<a id="directive-formatting"></a>

### Directive formatting

Document and range formatting repairs directive source in CSS, SCSS and LESS documents and in CSS-family `<style>` blocks in Vue, Svelte and Astro, without changing generated CSS. For class-list directives it keeps important markers attached to their class: `@safelist "(background-color:transparent) !";` becomes `@safelist "(background-color:transparent)!";`.

<a id="diagnostics"></a>

### Diagnostics

The language server reports directive errors in the same documents and project manifest loading errors. Class-string syntax, policy and sorting diagnostics belong to [Code linting](/guide/code-linting) and are not duplicated. Language-server clients can also opt into token-reference checks for open managed CSS files with the `designSystem` setting, which takes the same [design-system options](/reference/tools/cli#design-system-options) as `master-css inspect`.

---

<a id="supported-class-sources"></a>

## Recognize your class sources

Built-in sources include `class` and `className`, framework bindings, common helper calls and tagged templates. When your project uses another helper or attribute, add its name:

```json name=.vscode/settings.json
{
  "masterCSS.classAttributes": ["ui"],
  "masterCSS.classDeclarations": ["classes", "styles"],
  "masterCSS.classFunctions": ["cx"]
}
```

For example, `cx("p-card")` now receives class completion. Language-service arrays **extend** the built-in class sources, so `clsx` still works. ESLint source settings **replace** their defaults instead; configure both tools when introducing a project convention.

**Available VS Code settings**

Set options in `.vscode/settings.json` or VS Code user settings. The defaults cover HTML, PHP, JavaScript, TypeScript, JSX, TSX, CSS, SCSS, LESS, Vue, Svelte, Rust, Astro, Markdown and MDX.

**`masterCSS.includedLanguages`**

Default: Common web and template language IDs.

Languages that receive language-service features.

**`masterCSS.classAttributes`**

Default: `class`, `className`.

Markup attributes whose values contain class strings.

**`masterCSS.classAttributeBindings`**

Default: Framework binding defaults.

Bound attributes such as `:class`, `v-bind:class`, `[ngClass]` and `class:list`.

**`masterCSS.classFunctions`**

Default: `clsx`, `cn`, `cva`, `ctl`, `cv`, `class`, `classnames`, `classVariant`, `styled`, `classList.add/remove/toggle/replace`.

Callees whose string arguments contain class strings; `styled` also accepts member forms such as `styled.button`.

**`masterCSS.classDeclarations`**

Default: `[]`.

Variables or object properties whose strings are class declarations.

**`masterCSS.exclude`**

Default: `.git`, `node_modules`, `.hg`.

Files excluded from all features.

**`masterCSS.suggestSyntax`**

Default: `true`.

Completion items.

**`masterCSS.inspectSyntax`**

Default: `true`.

Hover inspection and generated CSS previews.

**`masterCSS.renderSyntaxColors`**

Default: `true`.

Color decorators for Master CSS color syntax.

**`masterCSS.formatDirectives`**

Default: `true`.

Directive formatting.

**`masterCSS.embeddedSyntaxHighlighting`**

Default: `active`.

`active` highlights the class under the cursor, `always` every embedded class, `off` none; directive syntax stays highlighted.

**`masterCSS.workspaces`**

Default: `auto`.

Workspace detection for project manifests.

---

<a id="workspace-aware-manifests"></a>

## Workspace-aware manifests

In `auto` mode the language server detects a workspace for each CSS file importing `@master/css` and each `package.json` declaring a Master CSS package, and gives each its own manifest. In a monorepo, completions, hover previews, colors and diagnostics follow the nearest Master CSS project. List workspace directories when detection does not match the repository layout, and see [Monorepo](/guide/monorepo) for project boundaries:

```json name=.vscode/settings.json
{
  "masterCSS.workspaces": ["apps/admin", "apps/shop", "packages/design-system"]
}
```

Run `Master CSS: Restart Language Server` after dependency changes, workspace-layout changes or manifest edits that VS Code has not picked up.

<a id="troubleshooting"></a>

## Troubleshooting

| Symptom | Fix |
| --- | --- |
| Completions do not show inside strings. | Enable `editor.quickSuggestions.strings`. |
| Project tokens or utilities are missing. | Confirm the token is in the detected CSS entry or one of its imports, fix manifest errors, then restart the language server if needed. |
| The wrong monorepo package is used. | Set `masterCSS.workspaces` to explicit workspace directories. |
| Color decorators do not appear. | Enable `masterCSS.renderSyntaxColors` and `editor.colorDecorators`; check language-specific overrides. |
