LSP Server: rust-analyzer
Glass uses rust-analyzer as the language server for Rust.Installation
- Automatic
- System Installation
Glass automatically downloads and installs rust-analyzer if not found:
- Detects your system architecture and libc type (GNU/musl on Linux)
- Downloads from the rust-lang/rust-analyzer GitHub releases
- Verifies SHA-256 checksums for security
- Manages multiple versions in
~/.local/share/zed/languages/rust-analyzer/
On Linux, Glass automatically detects whether you’re using GNU libc or musl and downloads the appropriate binary.
Features
Intelligent Completions
rust-analyzer provides context-aware completions with:- Full signatures: Function and method signatures with parameter types
- Snippets: Complete function bodies with placeholders
- Import suggestions: Automatic import path suggestions
- Trait completions: Methods from implemented traits
- Function Completion
- Struct Field Completion
- Snippet Completion
to_uppercase() -> StringSemantic Highlighting
Rust-analyzer provides semantic token information for precise syntax highlighting:crates/languages/src/rust/semantic_token_rules.json.
Diagnostics
Glass displays diagnostics from both rust-analyzer and cargo:- Compiler Errors
- Cargo Check
- Error message with help text
- Related information (like trait imports needed)
- Quick fixes (code actions)
Cargo Integration
Glass provides comprehensive Cargo task automation:Available Tasks
- Check & Build
- Testing
- Running
- Check (package):
cargo check -p $RUST_PACKAGE - Check all targets:
cargo check --workspace --all-targets - Build:
cargo build - Clean:
cargo clean
Task Variables
Glass extracts these variables from your Rust workspace:| Variable | Description | Source |
|---|---|---|
RUST_PACKAGE | Package name | cargo metadata |
RUST_BIN_NAME | Binary target name | Cargo.toml targets |
RUST_BIN_KIND | bin or example | Target kind |
RUST_BIN_REQUIRED_FEATURES_FLAG | --features or empty | From manifest |
RUST_BIN_REQUIRED_FEATURES | Comma-separated features | From manifest |
RUST_TEST_NAME | Test function name | From symbol |
RUST_TEST_FRAGMENT | Module test path | From file structure |
RUST_MANIFEST_DIRNAME | Directory with Cargo.toml | Workspace detection |
Custom Target Directory
Configure a custom target directory in language settings:--target-dir ./target/custom.
Configuration
Dynamic Schema
rust-analyzer’s configuration schema is dynamically loaded by running:Example Configuration
LSP Tasks (Experimental)
Enable rust-analyzer’s runnable tasks:Code Actions
rust-analyzer provides extensive code actions:- Import suggestions: Add missing imports
- Fill match arms: Complete match expressions
- Add derive: Add derive macros to structs
- Extract function: Extract code to a new function
- Inline: Inline variables or functions
- Generate implementations: Implement traits
Workspace Detection
Glass detects your Rust workspace by findingCargo.toml files:
Platform-Specific Notes
Linux
- Auto-detects GNU libc vs musl
- Tests with
ldd --versionor scans/libdirectory - Downloads appropriate binary automatically
macOS
- Uses
apple-darwinbuilds - Full support for Apple Silicon (aarch64)
Windows
- Downloads
.ziparchives with.exebinary - Uses
pc-windows-msvcbuilds
FreeBSD
- Uses
unknown-freebsdbuilds - May require manual compilation for some architectures
Troubleshooting
- Server Not Starting
- Slow Performance
- Workspace Issues
Check that rust-analyzer works:If installed via rustup:Glass logs server startup in the LSP logs (Cmd/Ctrl+Shift+P → “language server: Show logs”).
Next Steps
- Configure rust-analyzer settings
- Learn about task templates and testing
- Explore code actions and refactoring