| Crates.io | dbml-language-server |
| lib.rs | dbml-language-server |
| version | 0.1.2 |
| created_at | 2025-10-11 22:54:49.077643+00 |
| updated_at | 2025-10-13 04:47:07.451216+00 |
| description | A lightweight Language Server Protocol (LSP) implementation for DBML (Database Markup Language) files. |
| homepage | |
| repository | https://github.com/kamal-hamza/dbml-language-server |
| max_upload_size | |
| id | 1878630 |
| size | 202,306 |
A high-performance, standalone Language Server Protocol (LSP) implementation for DBML (Database Markup Language), written in Rust.
cargo install dbml-lsp
git clone https://github.com/your-username/dbml-lsp.git
cd dbml-lsp
cargo install --path .
Download pre-built binaries from the releases page.
cargo install dbml-lsp
Install a generic LSP extension or create a minimal one:
Using settings.json:
{
"dbml.lsp.path": "dbml-lsp"
}
Or use the VS Code extension (coming soon).
Add to your init.lua:
vim.api.nvim_create_autocmd('FileType', {
pattern = 'dbml',
callback = function()
vim.lsp.start({
name = 'dbml-lsp',
cmd = {'dbml-lsp'},
root_dir = vim.fs.dirname(vim.fs.find({'.git'}, { upward = true })[1]),
})
end,
})
-- Set filetype for .dbml files
vim.filetype.add({
extension = { dbml = 'dbml' },
})
Add to your .vimrc:
if executable('dbml-lsp')
au User lsp_setup call lsp#register_server({
\ 'name': 'dbml-lsp',
\ 'cmd': {server_info->['dbml-lsp']},
\ 'allowlist': ['dbml'],
\ })
endif
autocmd BufNewFile,BufRead *.dbml set filetype=dbml
Add to your Emacs config:
(require 'lsp-mode)
(add-to-list 'lsp-language-id-configuration '(dbml-mode . "dbml"))
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection "dbml-lsp")
:major-modes '(dbml-mode)
:server-id 'dbml-lsp))
(add-to-list 'auto-mode-alist '("\\.dbml\\'" . dbml-mode))
(add-hook 'dbml-mode-hook #'lsp)
Install the LSP package, then add to LSP settings:
{
"clients": {
"dbml-lsp": {
"enabled": true,
"command": ["dbml-lsp"],
"selector": "source.dbml"
}
}
}
Create a file example.dbml:
Table users {
id int [pk, increment]
username varchar(255) [unique, not null]
email varchar(255) [unique, not null]
created_at timestamp [default: `now()`]
Indexes {
(email) [unique]
(created_at)
}
}
Table posts {
id int [pk, increment]
user_id int [not null, ref: > users.id]
title varchar(500) [not null]
content text
status post_status [default: 'draft']
created_at timestamp [default: `now()`]
}
Enum post_status {
draft
published
archived
}
Ref: posts.user_id > users.id
You should now see:
| Feature | Supported | Notes |
|---|---|---|
| Tables | ✅ | With columns, aliases, and settings |
| Columns | ✅ | All data types and settings |
| Relationships | ✅ | All types: ->, <, >, <> |
| Inline Refs | ✅ | [ref: > table.column] |
| Composite Keys | ✅ | Multi-column foreign keys |
| Enums | ✅ | With members and notes |
| Indexes | ✅ | Single, composite, and expression-based |
| Projects | ✅ | Project metadata |
| Comments | ✅ | Single-line // and multi-line /* */ |
| Notes | ✅ | Table and column notes |
DBML Source Code
↓
Lexer (Tokenization)
↓
Parser (AST Construction)
↓
Semantic Analyzer (Symbol Resolution)
↓
LSP Features (Diagnostics, Navigation, etc.)
The language server uses a multi-stage analysis pipeline:
This architecture ensures robust error handling and allows features to work even when the document contains syntax errors.
# Debug build
cargo build
# Release build (optimized)
cargo build --release
# The binary will be at:
# target/release/dbml-lsp
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test
cargo test test_parse_simple_table
# Run with logging
RUST_LOG=debug cargo test
dbml-lsp/
├── Cargo.toml # Dependencies and project metadata
├── src/
│ ├── main.rs # Entry point
│ ├── server.rs # LSP server implementation
│ ├── state.rs # Document state management
│ ├── ast.rs # Abstract Syntax Tree definitions
│ └── analysis/ # Parsing and analysis pipeline
│ ├── mod.rs
│ ├── token.rs # Token definitions
│ ├── lexer.rs # Lexical analyzer
│ ├── parser.rs # Parser implementation
│ └── semantic.rs # Semantic analyzer
└── tests/
└── integration_tests.rs
# Check if the binary is executable
chmod +x $(which dbml-lsp)
# Verify it runs
dbml-lsp --version
Set the RUST_LOG environment variable:
# In your editor config or terminal
RUST_LOG=debug dbml-lsp
VS Code: Check the Output panel → "DBML Language Server"
Neovim: :LspLog
.dbml extensionThe server is designed for high performance:
Typical performance metrics:
Contributions are welcome! Here's how you can help:
# Clone the repository
git clone https://github.com/your-username/dbml-lsp.git
cd dbml-lsp
# Install dependencies
cargo build
# Run tests
cargo test
# Format code
cargo fmt
# Lint
cargo clippy
cargo test passes before submittingThis project is licensed under the MIT License - see the LICENSE file for details.