rainbow icon indicating copy to clipboard operation
rainbow copied to clipboard

[Bug] Rainbow breaks incomming patch bringing python f-strings to vim

Open Felixoid opened this issue 1 year ago • 2 comments

Describe the bug

I am testing a patch from https://github.com/vim/vim/pull/14057, and together with this plugin it breaks the syntax.

To Reproduce

Download the syntax as following:

mkdir "$HOME/.vim/syntax" -p
curl -s https://raw.githubusercontent.com/vim/vim/21c6d8b5b6ef510c9c78b9dfb89a41146599505f/runtime/syntax/python.vim > ~/.vim/syntax/python.vim

And open the test.py file with the following content

VAR = (
    "placeholderplaceholderplaceholderplaceholderplaceholderplaceholderplaceholder"
    if not bool()
    else f"placeholder {bool()}"
)
if not VAR:
    logging.debug("placeholder")
    _ = VAR

image

The closing bracket in f-string is white for some reason, and the whole following block is a part of string

I tried the following config in $MYVIMRC. It doesn't help

let g:rainbow_conf = {
\		'python': {
\			'parentheses_options': 'contains=@NopythonFStringContained',
\		},
\}

Expected behavior

F-string and rainbow shouldn't break each other. I am glad it's caught at the development phase. Hopefully, it could be solved before the release.

Felixoid avatar Sep 28 '24 21:09 Felixoid

Thanks for your report, do you know what syntax rules this patch is adding?

luochen1990 avatar Sep 29 '24 08:09 luochen1990

Reproduced that.

The reproduce step is:

  1. wget https://raw.githubusercontent.com/vim/vim/21c6d8b5b6ef510c9c78b9dfb89a41146599505f/runtime/syntax/python.vim
  2. Inside vim :syn clear
  3. Inside vim :source python.vim
  4. Inside vim :RainbowToggleOn

I have tried to compare 4 cases:

  1. old version python syntax with rainbow on
  2. new version python syntax with rainbow off
  3. no python syntax with rainbow on
  4. new version python syntax with rainbow on

Syntax under line2 col14 is:

image

Let's check the syntax rules

syn region  pythonFStringReplacement matchgroup=pythonFStringBrace start=+{+ end=+}+ contained contains=pythonFStringExpression

syn region  pythonFStringExpression
      \ start="." end="\ze[=!:}]"
      \ contained contains=@pythonExpression
      \ nextgroup=pythonFStringEquals,pythonFStringConversion,pythonFStringFormatSpec

Seems like contains=pythonFStringExpression and start="." caused this issue.

luochen1990 avatar Sep 29 '24 09:09 luochen1990