mechatroner / vscode_rainbow_csv

🌈Rainbow CSV - VS Code extension: Highlight CSV and TSV files in different rainbow colors to make them more readable
MIT License
436 stars 53 forks source link

allow parsing headers in comment line #90

Open szabi opened 3 years ago

szabi commented 3 years ago

Rainbow csv helpfully allows

The second is particularly helpful with long files and it's "show header on hover" feature.

However, it does not work when the header is not included as a full data line, but in a comment. This feature request is to support column headers in the comments, such as in this example file:

# This file contains a phone book.
# The fields are the following
#
# surname;name;phonenr
#
# --- DATA FOLLOWS ---
# This guy is shady as f*
McAffee;John;+1555123456
# I'd trust them:
Doe;John;+99555995511
Smith;Will;+1555446655
# End of file

A "full" feature would be to parse all comments prior to the first non-comment lines and look for CSV-formatted lines with the same number of delimiters as in the data part.

A stripped down version of this feature request could demand the header comment to be the only comment before the first data line, though that would limit the added usefulness:

# surname;name;phonenr
McAffee;John;+1555123456
# I'd trust them:
Doe;John;+99555995511
Smith;Will;+1555446655
# End of file
mechatroner commented 3 years ago

I think this may not work in some cases, for example, consider this file:

# This is the list that you asked me for, burn after reading!
Name,address
John Doe, 1240 Willow street
Jack Sparrow, Unknown
Anakin Skywalker, Tatooine

In this case, the algorithm you are suggesting would incorrectly consider This is the list that you asked me for, burn after reading! as the header line instead of Name,address. BTW you can actually use the virtual header feature to set any line as a header. I understand that it is not convenient to do this manually each time. Another option is to make your algorithm optional by adding a special setting that turns it on (it will be off by default).

szabi commented 3 years ago

I have used the "virtual header" feature, but then it picks up the "# " as part of the first field, even if it is set as the comment sign.

Maybe a solution is to strip the leading comment sign if one of configured from the virtual header's first field?

Ex:

Current behaviour for "virtual header"

# Surname; Name; Number

Leads to column labels

=> New behaviour:

(if comment marker is set to "#"; otherwise unchanged).

Dmitry Ignatovich @.***> schrieb am Fr., 16. Juli 2021, 01:10:

I think this may not work in some cases, for example, consider this file:

This is the list that you asked me for, burn after reading!

Name,address John Doe, 1240 Willow street Jack Sparrow, Unknown Anakin Skywalker, Tatooine

In this case, the algorithm you are suggesting would incorrectly consider This is the list that you asked me for, burn after reading! as the header line instead of Name address. BTW you can actually use the virtual header feature to set any line as a header. I understand that it is not convenient to do this manually each time. Another option is to make your algorithm optional by adding a special setting that turns it on (it will be off by default).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mechatroner/vscode_rainbow_csv/issues/90#issuecomment-881066483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABSPVV6IKOS6A63AVMPWTTTX5THXANCNFSM472MK54Q .