Skip to main content
Glass provides first-class Rust support through rust-analyzer integration, offering advanced IDE features, Cargo task automation, and semantic token highlighting.

LSP Server: rust-analyzer

Glass uses rust-analyzer as the language server for Rust.

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/
The adapter will automatically use the latest compatible version.
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
fn example(value: String) {
    value.to_| // Completes to to_uppercase() with full signature
}
Glass displays: to_uppercase() -> String

Semantic Highlighting

Rust-analyzer provides semantic token information for precise syntax highlighting:
// Distinguishes between:
struct Type;        // Type (blue)
let variable = 1;   // Variable (white)
const CONSTANT: i32 = 42;  // Constant (purple)

fn function() {     // Function (yellow)
    macro_name!();  // Macro (cyan)
}
Semantic rules are defined in crates/languages/src/rust/semantic_token_rules.json.

Diagnostics

Glass displays diagnostics from both rust-analyzer and cargo:
fn example() {
    let x = "hello";
    x.push('!');  // Error: no method named `push` found
}
Diagnostics include:
  • Error message with help text
  • Related information (like trait imports needed)
  • Quick fixes (code actions)
Glass processes diagnostics to clean up rust-analyzer’s markdown formatting (removing trailing newlines in code blocks).

Cargo Integration

Glass provides comprehensive Cargo task automation:

Available Tasks

  • Check (package): cargo check -p $RUST_PACKAGE
  • Check all targets: cargo check --workspace --all-targets
  • Build: cargo build
  • Clean: cargo clean
Tasks use the package containing the current file.

Task Variables

Glass extracts these variables from your Rust workspace:
VariableDescriptionSource
RUST_PACKAGEPackage namecargo metadata
RUST_BIN_NAMEBinary target nameCargo.toml targets
RUST_BIN_KINDbin or exampleTarget kind
RUST_BIN_REQUIRED_FEATURES_FLAG--features or emptyFrom manifest
RUST_BIN_REQUIRED_FEATURESComma-separated featuresFrom manifest
RUST_TEST_NAMETest function nameFrom symbol
RUST_TEST_FRAGMENTModule test pathFrom file structure
RUST_MANIFEST_DIRNAMEDirectory with Cargo.tomlWorkspace detection

Custom Target Directory

Configure a custom target directory in language settings:
{
  "languages": {
    "Rust": {
      "tasks": {
        "variables": {
          "RUST_TARGET_DIR": "./target/custom"
        }
      }
    }
  }
}
All cargo commands will use --target-dir ./target/custom.

Configuration

Dynamic Schema

rust-analyzer’s configuration schema is dynamically loaded by running:
rust-analyzer --print-config-schema
Glass converts the schema to a nested JSON format for settings validation.

Example Configuration

{
  "lsp": {
    "rust-analyzer": {
      "initialization_options": {
        "check": {
          "command": "clippy",
          "extraArgs": ["--all-targets"]
        },
        "cargo": {
          "features": "all",
          "targetDir": true
        },
        "procMacro": {
          "enable": true
        }
      }
    }
  }
}

LSP Tasks (Experimental)

Enable rust-analyzer’s runnable tasks:
{
  "lsp": {
    "rust-analyzer": {
      "enable_lsp_tasks": true
    }
  }
}
This allows rust-analyzer to provide its own test/run tasks with:
"experimental": {
  "runnables": {
    "kinds": ["cargo", "shell"]
  }
}

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 finding Cargo.toml files:
// From crates/languages/src/rust.rs:CargoManifestProvider
fn search(&self, query: ManifestQuery) -> Option<Arc<RelPath>> {
    // Walks up directory tree finding Cargo.toml
    // Returns outermost manifest (workspace root)
}
For multi-package workspaces, Glass uses the outermost Cargo.toml as the workspace root.

Platform-Specific Notes

Linux

  • Auto-detects GNU libc vs musl
  • Tests with ldd --version or scans /lib directory
  • Downloads appropriate binary automatically

macOS

  • Uses apple-darwin builds
  • Full support for Apple Silicon (aarch64)

Windows

  • Downloads .zip archives with .exe binary
  • Uses pc-windows-msvc builds

FreeBSD

  • Uses unknown-freebsd builds
  • May require manual compilation for some architectures

Troubleshooting

Check that rust-analyzer works:
rust-analyzer --version
If installed via rustup:
rustup component add rust-analyzer
Glass logs server startup in the LSP logs (Cmd/Ctrl+Shift+P → “language server: Show logs”).

Next Steps

Build docs developers (and LLMs) love