rustledger-lsp
Language Server Protocol (LSP) implementation for Beancount files.
Features
- Diagnostics: Real-time syntax and validation errors
- Completion: Accounts, currencies, payees, tags, links
- Hover: Account balances, metadata, directive info
- Go to Definition: Jump to account/commodity declarations
- Find References: Find all uses of an account or commodity
- Document Symbols: Outline view of accounts and directives
- Workspace Symbols: Search across all files
- Rename: Rename accounts across files
- Code Actions: Quick fixes for common issues
- Formatting: Format documents and selections
- Folding: Collapse transactions and sections
- Semantic Highlighting: Rich syntax coloring
- Inlay Hints: Inline balance and cost annotations
- Code Lens: Inline account statistics
Installation
The LSP server is included with rustledger:
# Via package manager (includes rledger-lsp)
# Via Cargo (LSP is a separate crate)
# Or build from source
Usage
# Start the LSP server (communicates via stdio)
# Check version
Editor Setup
VS Code
Install two extensions:
- Lencerf.beancount for syntax highlighting
- Generic LSP Client (v2) to connect to
rledger-lsp
Add to .vscode/settings.json:
Neovim (nvim-lspconfig)
-- Add to your Neovim config
local lspconfig = require
local configs = require
-- Register rledger-lsp if not already defined
if not configs.
lspconfig..
Helix
Add to ~/.config/helix/languages.toml:
[[]]
= "beancount"
= ["rledger-lsp"]
[]
= "rledger-lsp"
Zed
Add to ~/.config/zed/settings.json:
Emacs (lsp-mode)
(use-package lsp-mode
:hook (beancount-mode . lsp)
:config
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection '("rledger-lsp"))
:major-modes '(beancount-mode)
:server-id 'rledger-lsp)))
Emacs (eglot)
(add-to-list 'eglot-server-programs
'(beancount-mode . ("rledger-lsp")))
Sublime Text (LSP)
Install the LSP package, then add to LSP settings:
Troubleshooting
LSP not starting?
- Ensure
rledger-lspis in your PATH:which rledger-lsp - Check logs: most editors have an LSP log panel
- Try running manually:
echo '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{}}' | rledger-lsp
No completions?
- Ensure the file has
.beancountextension - Check that your editor's LSP client is configured for the beancount filetype
Architecture
Based on rust-analyzer patterns:
- Main loop handles LSP messages via stdio
- Notifications processed synchronously
- Requests dispatched to threadpool
- Revision-based cancellation for stale requests
- Virtual file system for unsaved buffers
License
GPL-3.0-only