CSS Variable LSP (Rust Implementation)
A Language Server Protocol implementation for CSS Variables, written in Rust.
Status: Complete
This is a ground-up Rust rewrite of the TypeScript/Node-based css-variable-lsp, eliminating the Node/npm dependency for the Zed extension.
Features
- CSS parsing for variable definitions and
var()usage tracking - HTML parsing for
<style>blocks and inline styles (custom DOM scanner) - Cascade sorting and specificity calculation
- LSP features: completion, hover, definition, references, rename, diagnostics, document/workspace symbols
- Workspace scanning and color provider (hex/rgb/hsl + named colors)
Autocomplete Contexts
TypeScript LSP (css-variable-lsp):
- Triggers on
-,(, and:. - Returns items only in CSS value contexts (after a
:and before the next;). - CSS-like files: inside rules/declarations (requires
{}context). - HTML-like files: inside
style="..."attributes or<style>...</style>blocks. - JS/TS/JSX/TSX: only inside string literals or template literal text (not inside
${...}). - Insert text:
--nameif already insidevar(, otherwisevar(--name).
Rust LSP (this repo):
- Matches the TypeScript LSP behavior above.
- Document kind detection uses language ID when available, otherwise extensions derived from
lookupFiles.
Building
Release Assets (Local)
Build and package release assets into dist/ (tar.gz on Unix, zip on Windows):
To build a subset of targets:
Running
The LSP server communicates via stdin/stdout using the Language Server Protocol.
Architecture
main.rs- Entry point, sets up async runtime and LSP serverlsp_server.rs- LSP protocol handlers (implementstower_lsp::LanguageServer)manager.rs- CSS variable manager (stores definitions/usages, DOM trees)types.rs- Core data types (CssVariable, CssVariableUsage, Config, etc.)parsers/- CSS and HTML parsing (definitions + var() usages)dom_tree.rs- Lightweight HTML scanner for selector matchingspecificity.rs- Specificity calculation and cascade orderingworkspace.rs- Workspace scanning and file discoveryruntime_config.rs- CLI/env configuration parsingpath_display.rs- Path formatting for hover/completioncolor.rs- Color parsing and color provider helpers
Dependencies
tower-lsp- LSP server frameworktokio- Async runtimeglobset/walkdir- Workspace scanningcsscolorparser- Color value parsingregex/pathdiff- Parsing helpers and path formatting
License
GPL-3.0