nickspoons / vim-cs

Official Vim Runtime Files for C#
9 stars 3 forks source link

XML syntax sets syntax spell toplevel #13

Closed mabuchner closed 4 years ago

mabuchner commented 4 years ago

All of my C# code gets spell checked. Usually only comments should get checked.

I could narrow the problem down to the fact, that syntax spell is set to toplevel instead of default.

The C# syntax definition doesn't directly set the syntax spell value, but it seems to include the XML syntax

https://github.com/nickspoons/vim-cs/blob/88657d63a53d71d334ff93faeb6dd36080d0d450/syntax/cs.vim#L97

which sets it

https://github.com/chrisbra/vim-xml-runtime/blob/aadf6b5366aa7c6fb22d7e612223424b8605fb99/syntax/xml.vim#L60

.

This was introduced quite recently with the following commit from the 4th November 2019:

https://github.com/chrisbra/vim-xml-runtime/commit/96e2698663feaa2d471de2e1d3410af63841d7e5

I guess, the C# syntax definition should set it back to default???

Please excuse, if everything I'm writing here is nonsense. I'm not very experiences with vim's syntax definitions.

mabuchner commented 4 years ago

As a workaround I added the following to my .vimrc file:

augroup fixCsSyntaxSpell
    autocmd!
    autocmd BufNewFile,BufRead *.cs syntax spell default
augroup END
nickspoons commented 4 years ago

Thanks for opening such a well-researched issue, @mabuchner.

I have never enabled spell checking in code so I haven't run across this before. I'll try to take a look at it at some stage. If it's possible to have spell-checking enabled in comments but nowhere else, that would be a pretty nice feature.

mabuchner commented 4 years ago

According to

https://unix.stackexchange.com/a/31155

only spell checking the comments is the expected behavior.

With @Spell and @NoSpell it's possible to specify where spell checking should or should not occur.

On first glance the C# syntax definition already seems to specify this correctly. However, in order for this to work correctly syntax spell default has to be set.

nickspoons commented 4 years ago

Thanks @mabuchner. I've sent the updated file to Bram for inclusion in Vim.

mabuchner commented 4 years ago

Many thanks for the quick fix.

At first, I thought, that this will break the spell checking of XML documentation strings (https://github.com/chrisbra/vim-xml-runtime/issues/19), but those seem to work just fine.

nickspoons commented 4 years ago

I wondered about that too, but no it's not an issue. The problem there was that XML node content was not contained in any syntax region, which means there was nothing to apply @Spell to. However in a C# file, the XML is embedded in a /// comment block, and this block has @Spell applied.