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
426 stars 51 forks source link

"Dynamic CSV" highlighting conflicts with other extensions and colors are not consistent with textmate grammars. #149

Closed sentience closed 9 months ago

sentience commented 1 year ago

Sample CSV file (filename: entries.csv):

id,title,url,quadrant,moved,ringId,date
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21

This file is correctly highlighted with rainbow columns when opened with file type "CSV (csv)":

CleanShot 2023-10-18 at 15 17 58

But when I switch to Dynamic CSV (which I want to use because it supports multi-line quoted strings), and I specify "," as the separator character, the file is not highlighted at all:

CleanShot 2023-10-18 at 15 19 20

mechatroner commented 1 year ago

I just tried this with the same filename and content and could not reproduce it.

Silly question: do you press "enter" after entering , in the "Dynamic CSV" dialog? Also: what does the file type show in the bottom right corner show? And what happens if you switch back and forth between the current and some other files?

Could you also please do the following test for me - copy the file (e.g. as entries_rfc.csv) and modify its context as follows:

id,title,url,quadrant,moved,ringId,date
nodejs,NodeJS,x,frontend,0,"adopt ->
-> next line continuation",20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21
nodejs,NodeJS,x,frontend,0,adopt,20/4/21

and then open the new file in VSCode - does it autodetect it as "Dynamic CSV" and apply the highlighting?

Could you also please check if you are running the latest version of VSCode and Rainbow CSV?

mechatroner commented 1 year ago

Actually, I have an idea what the problem could be - it looks like the extension allows to set the separator only once, so if it was mistyped the very first time - there is no way to re-enter it again. The choice is somehow kept even between VSCode restarts.

sentience commented 1 year ago

Silly question: do you press "enter" after entering , in the "Dynamic CSV" dialog?

Yep, certainly do.

Also: what does the file type show in the bottom right corner show?

It shows "Dynamic CSV".

And what happens if you switch back and forth between the current and some other files?

No change. The CSV remains un-highlighted.

Could you also please do the following test for me - copy the file (e.g. as entries_rfc.csv) and modify its context as follows: …

and then open the new file in VSCode - does it autodetect it as "Dynamic CSV" and apply the highlighting?

When I first save the file, VSCode selects file type CSV and the content is highlighted (but the highlighting of the multi-line string is broken, of course.

When I close and reopen the file, VSCode opens it as Dynamic CSV with no highlighting.

Could you also please check if you are running the latest version of VSCode and Rainbow CSV?

I'm using the current VSCode 1.84.0-insider build, and Rainbow CSV 3.8.0.

sentience commented 1 year ago

Actually, I have an idea what the problem could be - it looks like the extension allows to set the separator only once, so if it was mistyped the very first time - there is no way to re-enter it again. The choice is somehow kept even between VSCode restarts.

Hmm, does that prevent the separator from being updated with the command Rainbow CSV: Set separator - Quoted Multiline Fields? When I select a comma and run that command, nothing changes.

I should also mention that the tooltips for the columns correctly show the column titles, so it does appear that the columns are being correctly parsed.

CleanShot 2023-10-23 at 12 44 28

sentience commented 1 year ago

My issue appears to be a conflict with some other extension. Running VS Code with only Rainbow CSV enabled, the highlighting of the Dynamic CSV file type works.

sentience commented 1 year ago

OK, so the issue appears to be that many third-party color themes do not provide colors for the highlighting produced by Dynamic CSV, but do provide colors for the highlighting produced by CSV.

Are these two modes doing something significantly different in how they apply colors to the document?

mechatroner commented 1 year ago

My issue appears to be a conflict with some other extension.

Oh, wow, it is great to know that an extension conflict could cause this, I wasn't even considering such a possibility. Can you share what is the other extension that is causing this? I might look into the conflict mechanism when I have some spare time.

Are these two modes doing something significantly different in how they apply colors to the document?

Yes, CSV is powered by pre-created textmate language grammar, while "Dynamic CSV" parses the current fragment of the file on the fly and applies the highlighting via VSCode "Semantic tokenization" mechanism. There was some issue regarding how different token types are highlighted in Semantic tokenization vs pre-created grammars, but I forgot the details. Most likely the best I can do currently is to add an instruction on how to customize highlighting for "Dynamic CSV" case.

mechatroner commented 1 year ago

I just checked the docs again and it looks like there is a way to properly set up semantic token fallback mapping: https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#custom-textmate-scope-mappings Not sure if I've seen/tried this before, so I will take a look at some point.

mechatroner commented 9 months ago

I fixed inconsistent "dynamic csv" colors in version 3.10.0 I also found and fixed a bug that was preventing "dynamic csv" coloring from working with many custom color themes which might have caused the original problem.