Architecture
The language system in Glass is built on several core components:Tree-sitter Integration
Glass uses Tree-sitter for syntax highlighting, code outlining, and structural analysis:- Grammar-based parsing: Each language has a Tree-sitter grammar that provides precise syntax trees
- Incremental parsing: Only changed portions of files are re-parsed for performance
- Syntax highlighting: Tree-sitter queries map code ranges to highlight groups
- Code structure: Enables buffer outlines (symbol lists) and code navigation
Glass doesn’t assign a single language to a file. Real-world files often contain multiple languages (like HTML with embedded JavaScript), and the language system reflects this reality.
Language Server Protocol (LSP)
Glass integrates with LSP servers to provide:- Completions with semantic information
- Go-to-definition and find-references
- Hover documentation
- Code actions and refactoring
- Diagnostics (errors and warnings)
- Inlay hints for types and parameters
Language Registry
TheLanguageRegistry manages all loaded languages and their LSP adapters:
- Configuration (brackets, comments, etc.)
- Tree-sitter grammar
- File matchers (extensions, patterns)
- LSP adapters
- Context providers for tasks
LSP Adapter System
Each language implements anLspAdapter trait that handles:
- Installation
- Configuration
- Processing
- Download and install language servers automatically
- Detect user-installed servers in PATH
- Manage multiple versions
Built-in Language Support
Glass includes built-in support for these languages (fromcrates/languages/src/lib.rs):
| Language | LSP Server | Features |
|---|---|---|
| Rust | rust-analyzer | Full IDE support, semantic tokens |
| TypeScript/JavaScript | typescript-language-server, vtsls | Multiple servers, auto-completion |
| Python | Pyright, Basedpyright, Ruff | Type checking, linting, formatting |
| Go | gopls | Comprehensive Go support |
| C/C++ | clangd | Cross-language support |
| JSON | vscode-json-languageserver | Schema validation |
| CSS | vscode-css-languageserver | Tailwind support |
| YAML | yaml-language-server | Schema validation |
| Bash | - | Syntax highlighting |
Language Settings
Each language can be configured in your settings:Available Settings
tab_size: Number of spaces for indentationhard_tabs: Use tabs instead of spacessoft_wrap: Text wrapping behaviorlanguage_servers: List of LSP servers to useformat_on_save: Auto-format behaviorcode_actions_on_format: Run code actions during formatting
LSP Lifecycle
Language servers follow this lifecycle:- Detection: Adapter checks for user-installed or downloads server
- Initialization: Server starts with workspace folders and capabilities
- Configuration: Workspace configuration sent to server
- Operation: Server provides features (completion, diagnostics, etc.)
- Shutdown: Graceful shutdown on file close or editor exit
Multi-Language Files
Glass handles files with multiple languages:- Correct syntax highlighting
- Language-specific features in each section
- Proper indentation and formatting
Task Integration
Each language can provide task templates throughContextProvider:
- Running tests
- Building projects
- Executing files
- Custom toolchain commands
Next Steps
Rust Support
rust-analyzer integration and Cargo tasks
TypeScript Support
TypeScript, JavaScript, and JSX/TSX support
Python Support
Multiple LSP servers and virtual environments
Go Support
gopls integration and testing features