Skip to content

fix: preserve booking method quoted string in open directive formatting#848

Open
polarmutex wants to merge 1 commit intomainfrom
fix/issue-836-booking-method-formatting
Open

fix: preserve booking method quoted string in open directive formatting#848
polarmutex wants to merge 1 commit intomainfrom
fix/issue-836-booking-method-formatting

Conversation

@polarmutex
Copy link
Copy Markdown
Owner

Summary

Fixes #836.

The formatter was stripping the leading " from booking method strings on open directives. For example:

2024-01-01 open Assets:Investment:Retirement:Fidelity-Roth-IRA:FXAIX FXAIX "FIFO"

was being mangled to:

2024-01-01 open Assets:Investment:Retirement:Fidelity-Roth-IRA:FXAIX FXAIX FIFO"

Root cause: In generate_template_edits, the code used rest_content.find(char::is_alphabetic) to skip leading whitespace/non-alpha chars before a currency token. When the rest content was a quoted booking method like "FIFO", it found F at index 1 (skipping the "), producing the corrupted output.

Fix: Check whether rest_content starts with " before applying the alpha-search. If it does, it's a quoted token (booking method) and should be preserved verbatim with a single leading space.

Test plan

  • Added test_open_directive_booking_method_preserved — verifies that "FIFO" booking methods on open directives are preserved intact after formatting
  • Verifies idempotency: second format pass produces no edits
  • All 54 existing formatting tests continue to pass

Fixes #836. The formatter was calling `rest_content.find(char::is_alphabetic)`
to skip leading whitespace before a currency token. When an `open` directive
included a booking method (e.g. `"FIFO"`), this skipped the opening quote,
producing corrupt output like `FXAIX FIFO"` instead of `FXAIX "FIFO"`.

The fix: when `rest_content` starts with a `"`, treat it as a verbatim
quoted token (booking method) and preserve it with a single leading space
rather than stripping non-alphabetic prefix characters.

Adds a regression test that covers the mangled-quote scenario and verifies
idempotency of the formatter on open directives with booking methods.

Co-Authored-By: Claude (claude-sonnet-4-6) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.91%. Comparing base (d0d7e0c) to head (2d63ea6).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #848      +/-   ##
==========================================
+ Coverage   80.88%   80.91%   +0.03%     
==========================================
  Files          31       31              
  Lines       12502    12522      +20     
==========================================
+ Hits        10112    10132      +20     
  Misses       2390     2390              
Files with missing lines Coverage Δ
crates/lsp/src/providers/formatting.rs 92.26% <100.00%> (+0.10%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Booking Method Formatting Error

1 participant