# SQL LSP
<div align="center">
A **high-performance**, **multi-dialect** SQL Language Server Protocol (LSP) implementation in Rust.
[](https://www.rust-lang.org/)
[](LICENSE)
[](https://github.com/your-org/lsp_sqls/actions)
[Features](#-features) โข [Quick Start](#-quick-start) โข [Documentation](#-documentation) โข [Contributing](#-contributing)
</div>
---
## โจ Features
### Core Capabilities
- ๐ฏ **Multi-Dialect Support** - MySQL, PostgreSQL, Hive, ClickHouse, Elasticsearch (EQL/DSL), Redis
- ๐ **Intelligent Completion** - Context-aware suggestions for keywords, tables, columns, and functions
- ๐ **Code Navigation** - Go-to-definition with source location tracking
- ๐ **Find References** - Locate all usages of tables and columns
- โก **Real-Time Diagnostics** - Instant syntax error detection as you type
- ๐จ **SQL Formatting** - Professional formatting with customizable options
- ๐ **Rich Hover Information** - Detailed schema information in Markdown format
### Advanced Features
- ๏ฟฝ **Runtime Configuration** - Update schemas without restarting the server
- ๐ **Incremental Sync** - Efficient text synchronization for large files
- ๐ณ **AST-Based Analysis** - Tree-sitter powered parsing for accuracy
- ๐งต **Thread-Safe** - Concurrent request handling
- ๐ฆ **Schema Management** - Auto-inference with priority-based matching
- ๐ **Structured Logging** - Observable with `tracing` framework
## ๐ Quick Start
### Installation
#### Option 1: Build from Source
```bash
git clone https://github.com/your-org/lsp_sqls.git
cd lsp_sqls
cargo build --release
# Binary location: target/release/sql-lsp
```
#### Option 2: Install via Cargo
```bash
cargo install --path .
```
### Basic Usage
```bash
# Start the LSP server
./target/release/sql-lsp
# With debug logging
RUST_LOG=debug ./target/release/sql-lsp
```
### Editor Integration
Choose your editor for detailed setup instructions:
- **[VS Code](docs/editor-integration.md#vs-code)** - Extension or manual setup
- **[Neovim](docs/editor-integration.md#neovim)** - nvim-lspconfig integration
- **[Vim](docs/editor-integration.md#vim-vim-lsp)** - vim-lsp configuration
- **[Emacs](docs/editor-integration.md#emacs-lsp-mode)** - lsp-mode setup
- **[Sublime Text](docs/editor-integration.md#sublime-text-lsp-package)** - LSP package
## ๐ Documentation
### User Guides
- **[Configuration Guide](docs/configuration.md)** - Schema and dialect configuration
- **[Editor Integration](docs/editor-integration.md)** - Step-by-step editor setup
- **[Troubleshooting](docs/configuration.md#troubleshooting)** - Common issues and solutions
### Developer Resources
- **[Architecture](ARCHITECTURE.md)** - System design and components
- **[Contributing Guide](CONTRIBUTING.md)** - How to contribute
- **[Error Handling](docs/error-handling.md)** - Error handling strategies
## ๐ฏ Example
### Configure a Database Schema
```json
{
"schemas": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"database": "my_app",
"source_uri": "file:///path/to/schema.sql",
"tables": [
{
"name": "users",
"source_location": ["file:///path/to/schema.sql", 42],
"columns": [
{
"name": "id",
"data_type": "INT",
"nullable": false,
"comment": "Primary key"
},
{
"name": "email",
"data_type": "VARCHAR(255)",
"nullable": false,
"comment": "User email"
}
],
"comment": "User accounts"
}
]
}
]
}
```
### Features in Action
**Hover Information:**
```markdown
**Table**: `users`
User accounts
**Columns** (10)
- `id`: INT NOT NULL
- `email`: VARCHAR(255) NOT NULL
- `name`: VARCHAR(255) NOT NULL
...
```
**Intelligent Completion:**
- Keywords based on context (SELECT, FROM, WHERE, etc.)
- Tables from your schema
- Columns context-aware (knows which table you're querying)
- Functions with parameter hints
## ๐ Development
### Prerequisites
- Rust 1.70 or later
- Cargo
### Build
```bash
# Development build
cargo build
# Release build with optimizations
cargo build --release
# Run tests
cargo test
# Run linter
cargo clippy
```
### Project Structure
```
lsp_sqls/
โโโ src/
โ โโโ main.rs # Entry point
โ โโโ server.rs # LSP server
โ โโโ dialect.rs # Dialect trait
โ โโโ dialects/ # SQL dialect implementations
โ โโโ parser/ # SQL parsers (tree-sitter)
โ โโโ schema.rs # Schema management
โ โโโ token.rs # Token definitions
โโโ docs/ # Documentation
โโโ tests/ # Integration tests
โโโ scripts/ # Helper scripts
```
## ๐ค Contributing
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
### Quick Contribution Guide
1. Fork the repository
2. Create a feature branch: `git checkout -b feature/amazing-feature`
3. Make your changes
4. Run tests: `cargo test`
5. Commit: `git commit -m 'feat: add amazing feature'`
6. Push: `git push origin feature/amazing-feature`
7. Open a Pull Request
## ๏ฟฝ Supported SQL Dialects
| MySQL | โ
Full support | MySQL 5.7+ syntax |
| PostgreSQL | โ
Full support | PostgreSQL 12+ syntax |
| Hive | โ
Full support | HiveQL syntax |
| ClickHouse | โ
Full support | ClickHouse SQL |
| Elasticsearch EQL | โ
Full support | Event Query Language |
| Elasticsearch DSL | โ
Full support | Query DSL (JSON) |
| Redis | โ
Basic support | Redis commands |
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Acknowledgments
- Built with [tower-lsp](https://github.com/ebkalderon/tower-lsp) - LSP framework
- Powered by [tree-sitter](https://tree-sitter.github.io/) - Parser generator
- Formatted with [sqlformat](https://github.com/shssoichiro/sqlformat-rs) - SQL formatter
## ๐ฌ Contact
- **Issues**: [GitHub Issues](https://github.com/your-org/lsp_sqls/issues)
- **Discussions**: [GitHub Discussions](https://github.com/your-org/lsp_sqls/discussions)
---
<div align="center">
Made with โค๏ธ by the SQL LSP community
</div>