Skip to content

[Feature Request]: Add rainbow-parens Query Support for Vue #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hungvx-dev opened this issue Oct 26, 2024 · 8 comments
Open

[Feature Request]: Add rainbow-parens Query Support for Vue #141

hungvx-dev opened this issue Oct 26, 2024 · 8 comments

Comments

@hungvx-dev
Copy link

I'm requesting the addition of rainbow-parens support specifically for script blocks in Vue files within the rainbow-delimiters.nvim plugin. Currently, while there are good highlights for other languages, Vue files do not have consistent parentheses highlighting for script tags, which can lead to readability issues when working with complex JavaScript code.

@HiPhish
Copy link
Owner

HiPhish commented Nov 3, 2024

Can you please elaborate? I don't understand what exactly the problem is.

@hungvx-dev
Copy link
Author

hungvx-dev commented Nov 4, 2024

image

@HiPhish
The current query for Vue only includes rainbow-delimiters (which highlights tags in the template tag).
-> You can add a new query to apply rainbow colors only to parentheses in the <script/> tag (without affecting the template tag).

@HiPhish
Copy link
Owner

HiPhish commented Nov 5, 2024

If I understand you correctly what you want is to highlight delimiters inside the script tag only, but not inside template tag. Is that right?

@hungvx-dev
Copy link
Author

If I understand you correctly what you want is to highlight delimiters inside the script tag only, but not inside template tag. Is that right?

Yes, exactly. Please help me implement this feature.

@HiPhish
Copy link
Owner

HiPhish commented Nov 5, 2024

I don't think I want to include this sort of thing with the plugin, but you can add it to your personal configuration. In your Neovim configuration (e.g. ~/.config/nvim on Unix) create the file after/queries/vue/rainbow-script.scm (the name rainbow-script is arbitrary, you can call it whatever you want) with the following contents:

(script_element
  (start_tag
    "<" @delimiter
    (tag_name) @delimiter
    ">" @delimiter)
  (end_tag
    "</" @delimiter
    (tag_name) @delimiter
    ">" @delimiter @sentinel)) @container

This is a subset of the default query. Next in your rainbow delimiters configuration you need to tell the plugin to use your own custom query.

vim.g.rainbow_delimiters = {
	query = {
		vue = 'rainbow-script'
	},
}

Or if you prefer Vim script

let g:rainbow_delimiters = {
    \ 'query': {
        \ 'vue': 'rainbow-script'
    \ },
\ }

Note that your CSS will still be highlighted because it is not part of the Vue language. You will have to blacklist CSS if you don't want to highlight it. For more information see :h g:rainbow_delimiters, :h rb-delimiters-query and :h rb-delimiters-custom-query.

If more people want this type of query I can make it official, but until then you can add it to your configuration.

@hungvx-dev
Copy link
Author

Thank you for the recommendation. I applied that configuration, and it works well for me.

Evidence of the result:
image

@HiPhish
Copy link
Owner

HiPhish commented Nov 6, 2024 via email

@hungvx-dev
Copy link
Author

Thanks for the help, I am happy with it now.

@hungvx-dev hungvx-dev changed the title Feature Request: Add rainbow-parens Query Support for Vue [Feature Request]: Add rainbow-parens Query Support for Vue Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants