New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags are not shown. #664

Open
NorfairKing opened this Issue Dec 3, 2017 · 12 comments

Comments

Projects
None yet
3 participants
@NorfairKing

NorfairKing commented Dec 3, 2017

https://hackage.haskell.org/package/hledger-lib-1.4/docs/Hledger-Data-Transaction.html#v:showTransaction

Does not render tags.
The test even talks about a transaction with tags, but explicitly does not expect them in the output.

@ony

This comment has been minimized.

Show comment
Hide comment
@ony

ony Dec 3, 2017

Collaborator

@NorfairKing , I agree that it might be confusing. But reason for that is that all tags comes from comments. By the end of parsing you have tags included in both ptags/ttags and pcomment/tcomment.
showTransaction assumes that these two are consistent and takes the easiest way by rendering all comments together preserving their original representation.
If you want to manipulate with tags you should render them to comments of Posting or Transaction.

Though showTransaction may do better by checking if there is a new tags and add them. But it will be still inconsistent since there is no clear understanding how removal of tags should change comments.

You can assume that tags are simply run-time lookup similar to jinferredcommodities and other stuff useful for processing journal.

P.S. Same issue with dates that can be overridden in comments :)

Collaborator

ony commented Dec 3, 2017

@NorfairKing , I agree that it might be confusing. But reason for that is that all tags comes from comments. By the end of parsing you have tags included in both ptags/ttags and pcomment/tcomment.
showTransaction assumes that these two are consistent and takes the easiest way by rendering all comments together preserving their original representation.
If you want to manipulate with tags you should render them to comments of Posting or Transaction.

Though showTransaction may do better by checking if there is a new tags and add them. But it will be still inconsistent since there is no clear understanding how removal of tags should change comments.

You can assume that tags are simply run-time lookup similar to jinferredcommodities and other stuff useful for processing journal.

P.S. Same issue with dates that can be overridden in comments :)

@NorfairKing

This comment has been minimized.

Show comment
Hide comment
@NorfairKing

NorfairKing Dec 3, 2017

@ony Now I understand! Thanks for the clarification! The improvement to showTransaction that you describe would fix my use-case. I am trying to generate some transactions from scratch with hledger as a library and the resulting hledger journal is missing data because the tags dissappear.

NorfairKing commented Dec 3, 2017

@ony Now I understand! Thanks for the clarification! The improvement to showTransaction that you describe would fix my use-case. I am trying to generate some transactions from scratch with hledger as a library and the resulting hledger journal is missing data because the tags dissappear.

@NorfairKing

This comment has been minimized.

Show comment
Hide comment
@NorfairKing

NorfairKing Dec 3, 2017

On a related note, this duplication of information is a significant code smell and should be taken care of seperately as well, in my opinion.

NorfairKing commented Dec 3, 2017

On a related note, this duplication of information is a significant code smell and should be taken care of seperately as well, in my opinion.

@simonmichael

This comment has been minimized.

Show comment
Hide comment
@simonmichael

simonmichael Dec 3, 2017

Owner

Quick comment without looking at code: in journal syntax, tags are kept in comments. showTransaction generates journal syntax. Ie ony is right, it's best to think of ttags/ptags fields as an internal optimization.

If you still think it should behave differently, show us exactly how it would look.

Owner

simonmichael commented Dec 3, 2017

Quick comment without looking at code: in journal syntax, tags are kept in comments. showTransaction generates journal syntax. Ie ony is right, it's best to think of ttags/ptags fields as an internal optimization.

If you still think it should behave differently, show us exactly how it would look.

@NorfairKing

This comment has been minimized.

Show comment
Hide comment
@NorfairKing

NorfairKing Dec 3, 2017

@simonmichael I'd like to way to generate a transaction that has tags, such that those tags don't dissappear.
I guess a function as follows should be enough:

commentWithTags
    :: Text -- Old comment
    -> [Tag]
    -> Text -- New comment

NorfairKing commented Dec 3, 2017

@simonmichael I'd like to way to generate a transaction that has tags, such that those tags don't dissappear.
I guess a function as follows should be enough:

commentWithTags
    :: Text -- Old comment
    -> [Tag]
    -> Text -- New comment
@simonmichael

This comment has been minimized.

Show comment
Hide comment
@simonmichael

simonmichael Dec 3, 2017

Owner

If you're generating a transaction, it's easy to just generate a comment containing the tags, but if you're adding tags to an existing transaction yes I can see that will be useful. You're the first person to need this so you get to define its behaviour. :)

Owner

simonmichael commented Dec 3, 2017

If you're generating a transaction, it's easy to just generate a comment containing the tags, but if you're adding tags to an existing transaction yes I can see that will be useful. You're the first person to need this so you get to define its behaviour. :)

@simonmichael simonmichael added the A WISH label Dec 3, 2017

@NorfairKing

This comment has been minimized.

Show comment
Hide comment
@NorfairKing

NorfairKing Dec 3, 2017

it's easy to just generate a comment containing the tags

Maybe, but I don't want to be the one to maintain that code :p
Thanks for the label and triage. I will get back to this if it turns out to be mission-critical.

NorfairKing commented Dec 3, 2017

it's easy to just generate a comment containing the tags

Maybe, but I don't want to be the one to maintain that code :p
Thanks for the label and triage. I will get back to this if it turns out to be mission-critical.

@simonmichael

This comment has been minimized.

Show comment
Hide comment
@simonmichael

simonmichael Dec 3, 2017

Owner

Ok, if it helps:

renderTag (n,v) = n ++ ":" ++ v
renderTags tags = intercalate ", " . map renderTag
transactionSetTags tags t = t{tcomment=renderTags tags}
Owner

simonmichael commented Dec 3, 2017

Ok, if it helps:

renderTag (n,v) = n ++ ":" ++ v
renderTags tags = intercalate ", " . map renderTag
transactionSetTags tags t = t{tcomment=renderTags tags}
@NorfairKing

This comment has been minimized.

Show comment
Hide comment
@NorfairKing

NorfairKing Dec 5, 2017

@simonmichael Thanks!
I had to fix that a bit:

renderTag :: Tag -> Text
renderTag (n, v) = n <> ":" <> v

renderTags :: [Tag] -> Text
renderTags = T.intercalate ", " . map renderTag

transactionSetTags :: [Tag] -> Transaction -> Transaction
transactionSetTags tags t = t {tcomment = renderTags tags}

NorfairKing commented Dec 5, 2017

@simonmichael Thanks!
I had to fix that a bit:

renderTag :: Tag -> Text
renderTag (n, v) = n <> ":" <> v

renderTags :: [Tag] -> Text
renderTags = T.intercalate ", " . map renderTag

transactionSetTags :: [Tag] -> Transaction -> Transaction
transactionSetTags tags t = t {tcomment = renderTags tags}
@NorfairKing

This comment has been minimized.

Show comment
Hide comment
@NorfairKing

NorfairKing Dec 9, 2017

These are not unambiguously parseable, are they? What happens if there are commas or colons in tags?

NorfairKing commented Dec 9, 2017

These are not unambiguously parseable, are they? What happens if there are commas or colons in tags?

@simonmichael

This comment has been minimized.

Show comment
Hide comment
@simonmichael

simonmichael Dec 10, 2017

Owner

Tag values continue until the first comma or end of line. More details at http://hledger.org/manual.html#tags-1

Owner

simonmichael commented Dec 10, 2017

Tag values continue until the first comma or end of line. More details at http://hledger.org/manual.html#tags-1

@simonmichael

This comment has been minimized.

Show comment
Hide comment
@simonmichael

simonmichael Dec 10, 2017

Owner

(And tag names may not contain commas or colons. Not sure which you meant.)

Owner

simonmichael commented Dec 10, 2017

(And tag names may not contain commas or colons. Not sure which you meant.)

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