Overview
Walrus includes a full-featured Language Server Protocol (LSP) implementation and VS Code extension that provides rich IDE support for.walrus files.
Features
The Walrus LSP provides:- Parse diagnostics - Real-time syntax error detection
- Hover information - Rich hover docs for symbols, keywords, and built-ins
- Code completion - Scoped completion for locals, functions, structs, modules, built-ins, and keywords
- Signature help - Function and built-in call parameter hints
- Document symbols - Nested outline view of file structure
- Go to definition - Jump to symbol declarations
- Find references - Locate all uses of a symbol
- Rename symbol - Refactor symbol names across references
- Document highlights - Highlight read/write occurrences of symbols
- Syntax highlighting - Rich syntax coloring
Installation
Build the language server
From the repository root:The language server binary will be at
target/release/walrus-lsp.Launch Extension Development Host
Open the Then press
vscode/walrus directory in VS Code:F5 to launch an Extension Development Host.Configuration
Extension settings
The extension provides two configuration options:| Setting | Description | Default |
|---|---|---|
walrus.languageServer.path | Path to the language server executable | walrus-lsp |
walrus.languageServer.args | Additional command-line arguments | [] |
Custom language server path
Ifwalrus-lsp is not in your PATH, configure the absolute path:
.vscode/settings.json or user settings).
Language server architecture
Server implementation
The language server is implemented insrc/bin/walrus-lsp.rs using:
- tower-lsp - LSP server framework
- tokio - Async runtime
- walrus::lsp_support - Analysis and semantic information
Analysis module
Thesrc/lsp_support.rs module provides semantic analysis:
- Parses the source code
- Builds a scope tree
- Tracks definitions and references
- Resolves symbols across scopes
- Collects diagnostics
Built-in documentation
The LSP includes hover documentation for:Keywords
All language keywords (let, fn, struct, if, for, while, etc.) include contextual descriptions.
Built-in functions
| Function | Signature | Description |
|---|---|---|
len | len(value) | Returns length of a string, list, or dictionary |
str | str(value) | Converts a value to string |
type | type(value) | Returns the runtime type name for a value |
input | input(prompt) | Reads user input from stdin |
__gc__ | __gc__() | Manually triggers garbage collection |
__heap_stats__ | __heap_stats__() | Returns heap statistics as a dictionary |
__gc_threshold__ | __gc_threshold__(threshold) | Sets GC allocation threshold |
User-defined symbols
The LSP extracts and displays:- Function signatures with parameters
- Struct definitions
- Variable declarations
- Module information
Completion features
Scope-aware completion
The LSP provides completions based on the current scope:- Local variables - Variables defined in current function
- Function parameters - Available within function body
- Global functions - Top-level function definitions
- Struct methods - Static methods on struct types
- Modules - Imported module names and their exports
- Built-ins - All built-in functions
- Keywords - Language keywords appropriate for context
Snippet completion
Function completions include snippet placeholders:Signature help
When typing function calls, the LSP shows parameter information:fn quicksort : arr
As you type arguments, the active parameter is highlighted.
Document symbols
The LSP builds a hierarchical symbol tree showing:- Top-level functions
- Struct definitions with nested methods
- Global variables
- Module imports
Function- Named functionsMethod- Struct static methodsStruct- Struct typesVariable- Let bindingsModule- Import bindings
Reference tracking
Find references
Locates all uses of a symbol, sorted by position.Document highlights
Highlights all occurrences in the current file with kind:- Read - Variable/function reads
- Write - Variable assignments
Rename refactoring
Renames a symbol and all its references. Validates that the new name is a valid Walrus identifier.Extension files
The VS Code extension includes:Language configuration
Defines comment tokens, brackets, auto-closing pairs:Troubleshooting
LSP not starting
-
Verify the language server is built:
- Check the path configuration in VS Code settings
- View the Output panel (Walrus Language Server) for errors
Completions not working
- Ensure the file is saved (LSP analyzes on save)
- Check for parse errors in the Problems panel
- Restart the Extension Development Host (
F5)
Performance issues
For large files:- The LSP re-analyzes on every change
- Consider breaking code into smaller modules
- Parse errors are expensive - fix syntax issues first
Contributing to LSP
To improve the language server:- Modify
src/bin/walrus-lsp.rsfor server features - Enhance
src/lsp_support.rsfor semantic analysis - Update
vscode/walrus/for extension changes - Test in Extension Development Host
- Submit a pull request