Go Analyzer - LSP Server
A high-performance Language Server Protocol (LSP) implementation for Go code analysis, written in Rust. Provides real-time variable lifecycle tracking, data race detection, and advanced static analysis capabilities.
Features
🚀 High Performance
- Built in Rust for maximum speed and memory safety
- Asynchronous processing with Tokio runtime
- Incremental parsing with tree-sitter
- Smart caching with automatic cleanup
🔍 Advanced Analysis
- Variable Lifecycle Tracking: Complete variable scope and usage analysis
- Data Race Detection: Intelligent goroutine and concurrency analysis
- Context-Aware Analysis: Support for all Go constructs (structs, interfaces, methods)
- Severity Classification: High/Medium/Low priority race condition detection
🛡️ Production Ready
- Comprehensive error handling with panic recovery
- Graceful degradation when analysis fails
- Memory-safe operations with proper resource cleanup
- Extensively tested with 32+ unit tests
Installation
Install the LSP server using Cargo:
This will install the go-analyzer binary to your ~/.cargo/bin directory.
Usage
The go-analyzer binary implements the Language Server Protocol and can be used with any LSP-compatible editor.
Basic Usage
Start the LSP server:
The server communicates via stdin/stdout using the LSP protocol.
Editor Integration
VS Code
Install the Go Analyzer extension from the marketplace.
Neovim
Configure with your LSP client:
require. =
Emacs (lsp-mode)
(lsp-register-client
(make-lsp-client :new-connection (lsp-stdio-connection "go-analyzer")
:major-modes '(go-mode)
:server-id 'go-analyzer))
Vim (vim-lsp)
if executable('go-analyzer')
au User lsp_setup call lsp#register_server({
\ 'name': 'go-analyzer',
\ 'cmd': {server_info->['go-analyzer']},
\ 'allowlist': ['go'],
\ })
endif
LSP Capabilities
The server implements the following LSP features:
- Hover: Detailed variable information with lifecycle data
- Execute Command: Custom analysis commands
goanalyzer/cursor: Analyze variable at cursor positiongoanalyzer/graph: Generate code relationship graph
- Text Document Sync: Full document synchronization
- Custom Notifications: Progress updates and indexing status
Analysis Features
Variable Lifecycle Analysis
func example()
Data Race Detection
func concurrent()
Synchronization Awareness
func synchronized()
Configuration
The server accepts the following environment variables:
GO_ANALYZER_LOG_LEVEL: Set logging level (debug,info,warn,error)GO_ANALYZER_CACHE_SIZE: Maximum number of cached AST trees (default: 20)GO_ANALYZER_CACHE_TTL: Cache time-to-live in seconds (default: 300)
Architecture
Core Components
- LSP Server: Tower-LSP based server implementation
- Go Parser: Tree-sitter Go grammar for accurate parsing
- Analysis Engine: Variable tracking and race detection algorithms
- Cache System: Intelligent AST caching with TTL and size limits
Analysis Pipeline
- File Parsing: Go source code → AST via tree-sitter
- Variable Extraction: Identify declarations, usages, and scopes
- Race Detection: Analyze goroutine patterns and synchronization
- Result Generation: Create LSP-compatible analysis results
Performance
- Startup Time: < 100ms typical startup
- Analysis Speed: < 50ms for files up to 2000 lines
- Memory Usage: < 50MB with caching enabled
- CPU Usage: < 5% during active analysis, 0% when idle
Development
Building from Source
Running Tests
Contributing
Contributions are welcome! Please see our GitHub repository for development guidelines.
License
Licensed under the MIT License. See LICENSE for details.
Related Projects
- VS Code Extension - VS Code integration
- tree-sitter-go - Go grammar for tree-sitter
For more information, visit the project repository.