Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ This is a **beancount language server** implementation written in Rust that prov
This is a Rust workspace with the following structure:

- **`crates/lsp/`** - Main Rust language server implementation
- **`src/checkers/`** - Bean-check validation implementations (Strategy pattern)
- **`mod.rs`** - Strategy trait and factory pattern
- **`system_call.rs`** - Traditional bean-check binary execution
- **`python.rs`** - Python script integration via subprocess
- **`pyo3_embedded.rs`** - PyO3 embedded Python integration
- **`types.rs`** - Shared data structures
- **`vscode/`** - VSCode extension (TypeScript)
- **`python/`** - Python utilities for beancount integration
- **`bean_check.py`** - Enhanced Python validation script with JSON output
- **Root workspace** - Cargo workspace configuration

## Key Files
Expand All @@ -27,9 +34,15 @@ This is a Rust workspace with the following structure:
# Build the language server
cargo build

# Build with PyO3 embedded Python support (experimental)
cargo build --features python-embedded

# Run tests with coverage
cargo llvm-cov --all-features --locked --workspace --lcov --output-path lcov.info -- --include-ignored

# Run tests with PyO3 feature
cargo test --features python-embedded

# Format code
cargo fmt

Expand Down Expand Up @@ -83,25 +96,44 @@ nix flake check

### Language Server Features

- **Diagnostics** - Provided via beancount Python integration
- **Diagnostics** - Multi-method validation system with pluggable checkers
- **System Call** - Traditional bean-check binary execution (default)
- **Python Script** - Enhanced Python script with JSON output (experimental)
- **PyO3 Embedded** - Direct Python library integration (experimental)
- **Formatting** - Generates edits similar to bean-format
- **Completions** - Shows completions for Payees, Accounts, Dates
- **Future planned**: definitions, folding, hover, rename

### Bean-check Integration Architecture

The diagnostics system uses a Strategy pattern with three implementations:

1. **SystemCallChecker** - Executes bean-check binary via subprocess and parses stderr
2. **PythonChecker** - Runs Python script that outputs structured JSON
3. **PyO3EmbeddedChecker** - Calls beancount library directly via embedded Python

Factory pattern in `checkers/mod.rs` handles creation based on configuration.

### Key Dependencies

- **tree-sitter-beancount** - Parsing via tree-sitter
- **lsp-server** / **lsp-types** - LSP protocol implementation
- **ropey** - Efficient text rope data structure
- **tracing** - Structured logging
- **anyhow** / **thiserror** - Error handling
- **regex** - Pattern matching
- **regex** - Pattern matching for error parsing
- **chrono** - Date/time handling
- **serde** / **serde_json** - JSON serialization for Python integration
- **pyo3** - Python integration (optional, feature-gated)

## Configuration

Language server accepts configuration via LSP initialization:
- **journal_file** - Path to main beancount journal file
- **bean_check.method** - Validation method: "system" (default), "python-script", or "python-embedded"
- **bean_check.bean_check_cmd** - Path to bean-check binary (for system method)
- **bean_check.python_cmd** - Path to Python executable (for Python methods)
- **bean_check.python_script** - Path to Python validation script (for python-script method)

## Testing

Expand Down Expand Up @@ -146,7 +178,9 @@ Supports multiple editors:

- **Add new LSP feature**: Modify `crates/lsp/src/handlers.rs` and related provider files
- **Update completions**: Modify `crates/lsp/src/providers/completion.rs`
- **Add diagnostics**: Integrate with beancount via `python/bean_check.py`
- **Add new checker method**: Implement `BeancountChecker` trait in `crates/lsp/src/checkers/`
- **Modify bean-check integration**: Update checker implementations or factory in `crates/lsp/src/checkers/`
- **Enhance Python validation**: Modify `python/bean_check.py` script
- **Update VSCode extension**: Modify files in `vscode/src/`

## External Dependencies
Expand Down
100 changes: 98 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading