ap / vim-css-color

Preview colours in source code while editing
http://www.vim.org/scripts/script.php?script_id=5056
MIT License
1.77k stars 78 forks source link

Add support for lua #180

Open jessebot opened 1 year ago

jessebot commented 1 year ago

I'm not sure if I'm supposed to have the Comment and String there, but happy to remove it if needed.

Thanks for maintaining this project!

ap commented 1 year ago

I'm not sure if I'm supposed to have the Comment and String there

As far as I can see the Lua syntax is not defining any match or region or keyword directly on Comment or String, so the answer would be no.

this plugin is incompatible with treesitter

I do want to look into that at some point and see if it’s possible to make it cooperate with treesitter. But I don’t use NeoVim so it’s somewhere on the back burner.

I can't find anything like vim-css-color in the neovim community yet, so I still pop back over to vim, mostly to use this plugin

Wow, thank you. That is incredibly high praise.

The alternatives are still either non-functional or very slow, so even though I try to give lots of projects a shot, I always come back to this one 💙

Once more, thank you.

Unfortunately after all that praise I’m going to have to disappoint you… because your request happens to concern Lua. 🙁

The plugin in fact used to have Lua support. However, I had to drop it (81ce9558b0f5c8f0b015042415566f02360c67d0):

At the time of this writing, the Lua syntax defines its regions in terms of contains=ALLBUT, which is impossible to cooperate with.

Looking at the Lua syntax again right now, it is still designed the same way (though it just recently switched from ALLBUT to TOP, which is less bad, but is also an “include every group except” kind of directive, and therefore still problematic in the same way).

Now looking back at it with more experience (but also without the benefit of having had my head in the codebase recently), I think it’s not impossible to cooperate with the syntax – just a lot more work than for “normal” ones. Namely, the after/syntax/lua.vim needs to have a bunch of commands to add the CSS Color syntax groups to (almost?) every ALLBUT/TOP Lua syntax group. Something like that. I think. (And this would be a moving target. Any time the Lua syntax is updated upstream, the CSS Color support for it may have to be updated to match. Annoying.)

So the Lua support as submitted is incomplete – so I can’t ship it in CSS Color without the extra work.

I don’t know if you can or want to tackle that yourself or if you’d have to wait for me. But if you haven’t seen or don’t mind the shortcomings yourself, you don’t need to wait and don’t have to patch the plugin: you can just put the file from your PR into ~/.vim/after/syntax/lua.vim and just use it as part of your personal config.