A language server for the Ledger plain text accounting format. Powered by Rust and tree-sitter.
- completion suggestions for payees, accounts, tags and more
- document formatting & sorting
- diagnostics
- code actions
Autocomplete suggestions are provided for payees, accounts, tags, directives,
intervals (eg for periodic transactions) and filenames (eg for include
directives).
Completions are sourced from:
- for payees, accounts and tags, they are generated by querying the current
document tree (ie current file and all
included files) - filenames are generated by looking for all
.ledgerfiles in or under the current directory - directive and interval suggestions are hard-coded
Format-on-save is supported, and can be disabled by the client. The format is
meant to match that of ledger-mode-clean-buffer in Emacs ledger-mode,
with a few tweaks tossed in.
- right alignment of posting amounts
- separate transactions by a single blank line
- removes extra whitespace, including multiple blank lines
- preserve "blocks" of comments and directives, while also keeping separate blocks separate
Upon format, transactions are also automatically sorted by date, also similar to ledger-mode. Comments preceeding transactions are kept with their transactions.
Diagnostics are currently limited to a single check: does an included file
exist.
Supported code actions include:
- Mark a single transaction as pending, cleared or not cleared.
- Mark all pending transactions as cleared.
The following client-side configuration options are supported:
formatting: enable/disable formatting (default:true)sort_transactions: when formatting, should transactions also be sorted (default:true)
For example, in Zed, these could be set in your settings.json, like so:
{
...
"lsp": {
"ledger-language-server": {
"initialization_options": {
"formatting": true,
"sort_transactions": false
}
}
},
...
}I've built this to scratch my own itch, and I've only tested it with one client. It works for me, for my use cases. Experimental, beta, use at your own risk, WFM, YMMV, PRs welcome, etc.
PRs are welcome, especially in any of these areas:
- improve performance or memory-usage
- increase robustness and improve error handling
- improve correctness of formatting