-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[Syntax highlighting] Vim comments are not detected correctly whenever a line has 2 double quotes #11560
Comments
This was discussed before: the double quotes make the text look like a string (which would be valid in Vim9 script, but we don't know in what type of script this is). |
That's because the syntax highlighting sees "..." and interprets that as a string. Get rid of the double quote following the words Plugins and groups so they don't appear to be strings. |
That's because the syntax highlighting sees "..." and interprets that
as a string. Get rid of the double quote following the words Plugins
and groups so they don't appear to be strings.
I think this is the best compromise that we have now. Some users may
have spotted the non-comment highlighting when there is a double quote,
but I still haven't seen a good reason why that extra double quote was
there. Thus removing it fixes the problem, and avoid the bad
highlighting when a double quoted string is used in Vim9 script.
The ideal solution would be if we can somehow recognize those parts of a
script that are using Vim9 script syntax. Then we can highlight
comments properly, and also the user can quickly see when using the
wrong type of comment. The big question is: Can we reliable define a
region for Vim9 script?
When there is a "vim9script" line close to the top of the file, we can
start the Vim9 region. This does require syncing from the top, which
may make scrolling backwards a bit slow. Setting a maximum number of
lines (e.g. 500) is a compromise, not unusual for syntax highlighting.
Perhaps it's possible to define another region, which would be used if
we're not sure if we are in legacy or Vim9 script. In that region we
can try to highlight both, mostly like we do now.
Inside the Vim9 script region there can be ":function" commands, which
then uses the legacy script syntax. The vimFuncBody region already
exists, thus this should just work.
In legacy script there can be a ":def Func()" command. Currently this
is not recognized. It should start a Vim9 script region.
…--
From "know your smileys":
~#:-( I just washed my hair, and I can't do nuthin' with it.
/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
See #11307, where @dkearns sketched a fix.
Maybe not in the OP's particular example, but there is at least one good reason for this kind of thing: trailing comments, which are a real thing.
Obviously one might want to comment out the whole line for a variety of reasons. And if one does, the line ought to be highlighted as a comment. |
I find that this highlighting issue turns up all the time and isn't really practical to work around. E.g., in comments with quotes and any commented out code with quotes (strings, patterns etc). I appear to have some sort of fix for this as I haven't noticed the problem in some time. It seems that, much as you described, I'm using regions for legacy and compiled functions and testing for "vim9script" when the syntax file is loaded. We could poll for that statement with the appropriate autocommands and then reload the syntax file or just clear and add the appropriate syntax groups? I'm currently testing a similar strategy in my Vim filetype plugin to change option settings for Vim9 and legacy script regions. It seems to work alright with CursorHold but I wasn't sure if that was too complicated to distribute. |
Steps to reproduce
vimrc
fileExpected behaviour
The written lines are highlighted as comments/commentLines
Version of Vim
9.0 with patch 1-887
Environment
gvim 64bits on Windows 10
Logs and stack traces
No response
The text was updated successfully, but these errors were encountered: