vscode_rainbow_csv icon indicating copy to clipboard operation
vscode_rainbow_csv copied to clipboard

allow parsing headers in comment line

Open szabi opened this issue 3 years ago • 2 comments

Rainbow csv helpfully allows

  • ignoring comment lines
  • allows to be configured to parse the first data line as a header

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

szabi avatar Jul 05 '21 09:07 szabi

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).

mechatroner avatar Jul 15 '21 23:07 mechatroner

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

  • # Surname
  • Name
  • Number

=> New behaviour:

  • Surname
  • Name
  • Number

(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 .

szabi avatar Jul 17 '21 20:07 szabi