crispgm / cmp-beancount

nvim-cmp source for beancount accounts
MIT License
35 stars 4 forks source link

Fix Beancount error when file has Custom entries #1

Closed wzyboy closed 2 years ago

wzyboy commented 2 years ago

Currently the plugin assumes there is a file that contains all the account opening transactions. This PR improves the method by enumerating all entries in the file with .account attributes and deduplicating them before outputing them to nvim-cmp.

The plugin can now loads the root Beancount file (similar to the behaviours of nathangrigg/vim-beancount) instead of the just the account opening file.

crispgm commented 2 years ago

@wzyboy hello, thanks for the PR. I roughly understand what's wrong with the single account file issue. But would you mind clarifying how to reproduce this? Do I have to config account file path other than file like account.bean?

wzyboy commented 2 years ago

Hi @crispgm . The reason behind this change is that the code tried to access the .account attributes of the entries returned by load_file(). However, not all entries have .account attributes. For example, Custom entries do not:

1970-01-01 custom "fava-option" "journal-show" "transaction balance note custom budget open close"

This entry will be parsed and returned by load_file() as a Custom entry, but trying to access its .account attribute will result AttributeError: 'Custom' object has no attribute 'account'.

The PR fixes this issue.

crispgm commented 2 years ago

@wzyboy I got that. Thank you very much!