-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add operator symbols in regex to show correct field highlight termination #1907
Conversation
Hi @zkry For this kind of PR's a before/after screenshot on what this is fixed is appreciated. |
Also, could you post the results from the benchmarks with |
@Carpetsmoker I benchmarked these changes against master; they end up slowing things down about 10%, but if this PR goes one step further and uses |
4fb4b58
to
b81a447
Compare
@bhcleek Thanks. I updated the PR with your suggestion. I was having trouble figuring out how to run the benchmark and get the relevant info. I'll write here when I can confirm that there is now slowdown. |
@zkry you'll likely need to replace more |
syntax/go.vim
Outdated
@@ -291,7 +291,7 @@ hi def link goFunctionCall Type | |||
|
|||
" Fields; | |||
if go#config#HighlightFields() | |||
syn match goField /\.\w\+\([.\ \n\r\:\)\[,]\)\@=/hs=s+1 | |||
syn match goField /\.\w\+\%([}\!=\><\^|&%\/*\-\+.\ \n\r\:\)\[\],]\)\@=/hs=s+1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regular expression is now very hard to understand and/or maintain. It should probably documented better and split over multiple lines.
For example:
Lines 108 to 120 in b81a447
" [n] notation is valid for specifying explicit argument indexes | |
" 1. Match a literal % not preceded by a %. | |
" 2. Match any number of -, #, 0, space, or + | |
" 3. Match * or [n]* or any number or nothing before a . | |
" 4. Match * or [n]* or any number or nothing after a . | |
" 5. Match [n] or nothing before a verb | |
" 6. Match a formatting verb | |
syn match goFormatSpecifier /\ | |
\([^%]\(%%\)*\)\ | |
\@<=%[-#0 +]*\ | |
\%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\ | |
\%(\.\%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\)\=\ | |
\%(\[\d\+\]\)\=[vTtbcdoqxXUeEfFgGsp]/ contained containedin=goString,goRawString |
(which is still not great, but better than this).
It may also be worth adding \v
at the start of this pattern for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I can clean this regex along with updating \(
with \%(
. Sorry for having stepped away from this issue for such a long time by the way.
In addition, change sub-expression regexs \( to \%( to speed up syntax time.
b81a447
to
0a621c5
Compare
I noticed how were weren't using the |
PR #1907 was previously merged by doing a rebase, resolving conflicts, and merging the result. This merge is done using the `ours` strategy to keep the history clean and make it clear that the PR was actually merged.
Thanks, @zkry ! |
Fixes #1849. This is indeed a problem even when gofmt is on (ex. inside array index brackets). This should cover all of the operators.