Introduction
The Glass Extension API allows you to write extensions for Glass code editor in Rust. Extensions run in a secure WebAssembly (WASM) sandbox and can:- Integrate language servers for code intelligence
- Add custom slash commands to the AI assistant
- Provide context servers for AI features
- Configure debugging adapters (DAP)
- Index documentation for the
/docscommand
Extensions are compiled to WebAssembly and run in an isolated environment. This provides security while enabling rich functionality.
Core Concepts
Extension Trait
All extensions implement theExtension trait, which defines lifecycle methods and integration points:
Extension Registration
Register your extension using theregister_extension! macro at the end of your main module:
Extension Trait Methods
TheExtension trait provides many optional methods you can implement:
Language Server Integration
Returns the command to start a language server process.Parameters:
language_server_id: &LanguageServerId- ID of the language serverworktree: &Worktree- The project worktree
Result<Command> - Command to executeReturns initialization options passed to the language server on startup.Parameters:
language_server_id: &LanguageServerIdworktree: &Worktree
Result<Option<serde_json::Value>> - JSON initialization optionsReturns workspace configuration options for the language server.Parameters:
language_server_id: &LanguageServerIdworktree: &Worktree
Result<Option<serde_json::Value>> - JSON configurationCompletion and Symbol Labels
Customizes how code completions are displayed.Parameters:
language_server_id: &LanguageServerIdcompletion: Completion- The completion item
Option<CodeLabel> - Custom label or None for defaultCustomizes how symbols are displayed in symbol search.Parameters:
language_server_id: &LanguageServerIdsymbol: Symbol- The symbol
Option<CodeLabel> - Custom label or NoneSlash Commands
Provides completions for slash command arguments.Parameters:
command: SlashCommand- The slash command being completedargs: Vec<String>- Current arguments
Result<Vec<SlashCommandArgumentCompletion>>Executes a slash command.Parameters:
command: SlashCommandargs: Vec<String>- Command argumentsworktree: Option<&Worktree>
Result<SlashCommandOutput> - Command output for the AI assistantContext Servers
Returns command to start a Model Context Protocol (MCP) server.Parameters:
context_server_id: &ContextServerIdproject: &Project
Result<Command>Returns configuration for a context server.Parameters:
context_server_id: &ContextServerIdproject: &Project
Result<Option<ContextServerConfiguration>>Documentation Indexing
Suggests package names for
/docs command completions.Parameters:provider: String- Documentation provider name
Result<Vec<String>> - List of package namesIndexes documentation for a specific package.Parameters:
provider: Stringpackage: String- Package name to indexdatabase: &KeyValueStore- Storage for indexed data
Result<()>Debug Adapter Protocol (DAP)
Returns the debug adapter binary path.Parameters:
adapter_name: Stringconfig: DebugTaskDefinitionuser_provided_debug_adapter_path: Option<String>worktree: &Worktree
Result<DebugAdapterBinary>Determines if debug request is launch or attach.Parameters:
adapter_name: Stringconfig: serde_json::Value
Result<StartDebuggingRequestArgumentsRequest>Converts high-level debug config to adapter-specific scenario.Parameters:
config: DebugConfig
Result<DebugScenario>Resources
The Extension API provides several resource types representing editor state:Worktree
Represents a project worktree (folder):Returns the unique ID of this worktree
Returns the absolute path to the worktree root
Reads a text file from the worktree
Finds a binary in PATH, returns absolute path if found
Returns the current shell environment variables
Project
Represents the entire project:Returns IDs of all worktrees in the project
KeyValueStore
Simple key-value storage for extension data:Stores a key-value pair. Both key and value must be strings.
Helper Functions
Language Server Status
None- No statusDownloading- Downloading language serverCheckingForUpdate- Checking for updatesFailed(String)- Installation failed with reason
File Downloads
Node.js Integration
GitHub Releases
Platform Detection
Complete Example
Here’s a complete extension that integrates a Node.js-based language server:Next Steps
Language Server Integration
Learn how to integrate language servers with LSP
Commands API
Execute commands and manage processes
Configuration
Access and use extension settings
Language Extensions
See complete working examples