rainbow_csv icon indicating copy to clipboard operation
rainbow_csv copied to clipboard

Should delimiter autodetect work in Neovim 0.8.1?

Open jweckman opened this issue 3 years ago • 6 comments

I deal with a balanced mix of files with , and ; delimiters and for some reason i've never been able to autodetect semicolons. If i forcibly set every csv file to csv_semicolon it works but it is as if i can't get the autodetect to run at all.

First i played around with various configs to see if they would change anything but e.g these did nothing: vim.g.disable_rainbow_csv_autodetect = 0 vim.g.rbql_with_headers = 1 vim.g.rcsv_delimiters = {";"} vim.g.rbql_use_system_python = 1

Despite zero vimscript knowledge, i even tried debugging the code with error messages. From what i can tell it seems that no autodetect code is ever run on file open. It always stops doing anything when it finds that "rainbow_features_enabled" is on and just always set the file type to "csv" with this: execute "set ft=" . ft_power_cycle

Am i just dumb or why is it not able to detect that e.g this is a semicolon file?:

date;amount;other_party;category;account;recipient;bank;description 2018-05-31;148.35;p;data;a;b;;data 2018-05-31;415;p;data;a;b;;data 2018-05-31;-2.6;p;data;a;b;;data 2018-06-01;-2.6;p;data;a;b;;data

Manually setting it works fine but not auto. Is there a config i'm missing?

jweckman avatar Dec 04 '22 19:12 jweckman

Hi, this looks strange, I tested your file and autodetection worked for me as expected. BTW, you can try to set vim.g.rcsv_delimiters = [";", ","] it should be an array, not a dictionary. Maybe you can also try to update rainbow_csv if you are using not the latest version. Also, autodetection doesn't work if the number of lines is less than 5, but in the case of your file, it should be fine since it has exactly 5 lines.

mechatroner avatar Dec 05 '22 05:12 mechatroner

Thanks for quick reply. Sorry i forgot to mention that i configure global variables and most other things in lua, which is why the assignment looks strange (everything is a "table" in lua). Running :echo g:rcsv_delimiters returns [';', ',']. I tried with your specific suggestion and still same result on the test file and larger "real" ones. I also tried with a minimal config that only imports your plugin and sets the global but no luck.

Also using latest version of the plugin.

Do you think you could make a quick check using latest stable neovim? Should be very easy to install from here: https://github.com/neovim/neovim/releases/tag/stable If you are on linux you can simply download and execute the appimage.

This is the init.vim config i used:

" auto-install vim-plug if empty(glob('~/.config/nvim/autoload/plug.vim')) silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

autocmd VimEnter * PlugInstall | source $MYVIMRC endif

" Plug call plug#begin('~/.vim/plugged') Plug 'mechatroner/rainbow_csv'

call plug#end()

lua << EOF vim.g.mapleader = " " vim.opt.termguicolors = false vim.g.rcsv_delimiters = {";", ","} EOF

Alternatively it would be nice to have an explanation on how the autodetect works. To my eyes it looks like it does some kind of caching not to keep setting the type for the same file over and over. If my cache is somehow acting up it would be nice to know how it works.

jweckman avatar Dec 05 '22 17:12 jweckman

Thanks, I might try to reproduce this when I have more time. If you want you can also try to debug this further by using "echo"/"echom"/"messages" commands inside the autodetection call stack. The extension caches autodetection results in `~/.rbql_table_index' text file so you can also try to clean/remove the file or see if it contains suspicious entries and remove them.

mechatroner avatar Dec 05 '22 22:12 mechatroner

I removed the rbql_table_index and found that its contents are set correctly for my file if i do it manually via RainbowDelim. What is very interesting is that even if the only file contents are as follows: /home/joakim/ksjgsg.csv ; quoted @auto_comment_prefix@

The delimiter loading fails when i open the file. Even more interesting is that it DOES load correctly if i e.g. add this echoerr to the following location:

func! rainbow_csv#handle_syntax_change()
    let [delim, policy, comment_prefix] = rainbow_csv#get_current_dialect()
    echoerr 'delim:' .. delim

Then it prints the correct delimiter ";", stops executing certain code and highlighting works as expected. Looks to me like there is some code that resets the delimiter or makes the highlighting fail.

jweckman avatar Dec 06 '22 08:12 jweckman

Syntax autodetection for semicolons and Rainbow features seem work if I comment out this line: https://github.com/mechatroner/rainbow_csv/blob/3dbbfd7d17536aebfb80f571255548495574c32b/autoload/rainbow_csv.vim#L1881

Serega124 avatar Jul 16 '24 13:07 Serega124

Does it break something else? You would think that line is there for a reason. I can try to look into this when i have some time again. Very busy at work atm.

jweckman avatar Aug 13 '24 19:08 jweckman