vim-python / python-syntax

Python syntax highlighting for Vim
MIT License
438 stars 84 forks source link

Spellchecker gets confused by f-strings #43

Open memeplex opened 6 years ago

memeplex commented 6 years ago

The spellchecker is considering f'this in f'this is a f-string as a potential dictionary word and thereby highlighting it as wrong.

kfollstad commented 3 years ago

Hi @nfnty and all the other contributors,

First off, I just wanted to say thanks for making such a great enhanced version of python syntax highlighting for vim. All the work that you guys have done to make this repo is so far ahead of upstream in terms of incorporating more coloring / new language features really shows.

As far as this issue is concerned, the problem is essentially this:

f"this"  # Will not be marked
r"this"  # Will not be marked
rf"this" # Will not be marked
rf'this' # Will be marked as spelling error
r'this'  # Will be marked as a spelling error
f'this'  # Will be marked as a spelling error

So I think what is happening is that spell check is being applied against the whole region including the start / end in all cases. However, in the case of the double quote (or triple double quotes) vim recognizes it as a word separation character and so checks "rf" and "this" as separate words. (R,f, rf, all pass). However in the case of a single quote, vim doesn't recognize it as a word separation character so it spellchecks the 'contraction' rf'this.

I think the solution is wall off the start and end of the region with matchgroup

Ref :help matchgroup In a start or end pattern that is highlighted with "matchgroup" the contained items of the region are not used. This can be used to avoid that a contained item matches in the start or end pattern match.