⚠️ Work in progress — this extension is incomplete and not fully functional.Syntax highlighting is partial (brace-style Stylus works reasonably well; indentation-style Stylus does not parse correctly since there is no tree-sitter grammar for Stylus — the CSS grammar is used as a stand-in). The language server is a custom implementation that has not been thoroughly tested. Several features listed below may not work correctly or at all.
Forks and improvements are very welcome. If you want to build a more complete Stylus extension for Zed — especially one with a proper tree-sitter grammar — please feel free to use this as a starting point.
Stylus CSS language support for the Zed editor, powered by a custom Language Server Protocol (LSP) implementation.
| Feature | Status |
|---|---|
| Syntax highlighting | |
| Diagnostics / linting | |
| Completions | |
| Hover documentation | |
| Signature help | |
| Go-to definition | |
| Find references | |
| Document symbols | |
| Folding ranges | |
| Color picker | |
| Formatting |
- Open the Command Palette:
cmd+shift+p - Type
zed: extensions - Search for Stylus
- Click Install
# Clone the repo
git clone https://github.com/your-org/zed-stylus
cd zed-stylus
# Build the LSP server
cd stylus-language-server
npm install
npm run build
cd ..
# Install as a Zed dev extension
# In Zed: Extensions > Install Dev Extension > select this directoryzed-stylus/
├── extension.toml # Zed extension manifest
├── Cargo.toml # Rust extension crate
├── src/
│ └── lib.rs # Extension entry point (Rust/WASM)
│ # Installs & launches the LSP server
├── languages/
│ └── stylus/
│ ├── config.toml # Language config (file ext, comments, brackets)
│ ├── highlights.scm # Tree-sitter syntax highlighting queries
│ ├── indents.scm # Indentation queries
│ ├── brackets.scm # Bracket matching queries
│ └── outline.scm # Outline panel queries
└── stylus-language-server/ # The LSP server (TypeScript/Node.js)
├── package.json
├── tsconfig.json
└── src/
├── main.ts # LSP connection, request handlers
├── parser.ts # Stylus parser & validator
├── analyzer.ts # Variable/mixin extraction, color detection
├── formatter.ts # Code formatter
└── data.ts # CSS properties, Stylus builtins, named colors
The Rust extension (src/lib.rs) acts as a thin shim compiled to WebAssembly. When Zed activates a .styl file, it calls the extension to get a command to launch the language server. The extension:
- Checks for a workspace-local
stylus-language-serverbinary - Falls back to auto-installing via npm into Zed's extension storage
- Returns the command
stylus-language-server --stdioto Zed
The TypeScript LSP server (stylus-language-server/) handles all language intelligence over the Language Server Protocol using stdin/stdout in --stdio mode.
- CSS properties with syntax documentation and value suggestions
- CSS values contextually filtered to the current property
- Stylus variables (
$var) with their resolved values - User mixins with parameter signatures
- Built-in functions (
lighten,darken,mix,rgba, etc.) with snippet insertion - At-rules (
@import,@media,@keyframes, etc.) - Named colors with hex previews
- Pseudo-classes and pseudo-elements
- Undefined variable references
- Unbalanced parentheses
- Optional semicolon consistency warnings
- Optional brace usage warnings
The formatter normalizes Stylus to idiomatic brace-free, semicolon-free style:
- Removes redundant semicolons
- Removes redundant braces
- Normalizes
calc()operator spacing - Removes unnecessary units from
0values - Normalizes variable declaration spacing (
$var = value)
// Variables
$primary = #3498db
$font-stack = 'Helvetica Neue', sans-serif
// Mixin
border-radius(r = 5px)
-webkit-border-radius r
-moz-border-radius r
border-radius r
// Selector nesting
.card
background white
border-radius(8px)
&:hover
box-shadow 0 4px 20px rgba(0,0,0,0.1)
.title
font-size 1.5rem
color $primary
// Conditionals
.alert
if $theme == dark
background #222
else
background white
// Loops
for i in (1..5)
.col-{i}
width (i * 20)%
// Interpolation
vendor(prop, val)
for prefix in webkit moz ms
-{prefix}-{prop} val
{prop} valAdd to your Zed settings.json to customize:
{
"languages": {
"Stylus": {
"tab_size": 2,
"format_on_save": "on",
"formatter": "language_server"
}
}
}PRs welcome! The LSP server is standard TypeScript — no special toolchain needed beyond Node.js 18+.
cd stylus-language-server
npm install
npm run watch # incremental TypeScript compilation
node dist/main.js --stdio # manual testPrimarily written by Claude (Anthropic), with @sinejoe.
MIT