-
-
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
Various improvements to syntax highlighting. #917
Conversation
Look behind regexp patterns are not recommended in syntax files, especially with the new NFA engine. So we should try to avoid them. Highlighting of methods, fields, methods, structs and interfaces should be much faster now. Consolidated two options g:go_highlight_structs and g:go_highlight_interfaces into one g:go_highlight_types.
explicitly match variadic args, so they are not detected as goField instead.
@@ -181,8 +181,7 @@ To change it: | |||
let g:go_highlight_functions = 1 | |||
let g:go_highlight_methods = 1 | |||
let g:go_highlight_fields = 1 | |||
let g:go_highlight_structs = 1 | |||
let g:go_highlight_interfaces = 1 | |||
let g:go_highlight_types = 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 is a breaking change. Is there a way to not break this? I don't want people change their vimrc
for no reason if possible :)
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.
I agree that is quite unfortunate. I don't see an efficient way to separate parsing of type Name struct
from type Name interface
. Let me think about it a bit more. Maybe it can be done using syn-region
syntax.
On the other hand, why do we need to distinguish these two cases?
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.
It was like that previously. We don't need to distinguish at all, it is just for backwards compatibility. But if you believe that making it backwards compatibility comes with increased complexity, I'm in favor of breaking it, so it means this change would be ok.
Hi @datanoise. Thanks for this wonderful improvement. Is there a way you can split this into separate PR's for each highlight group? It's hard to follow what exactly it changes and you changed a lot of things :) |
Just for the reference with these settings: let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 0
let g:go_highlight_structs = 1
let g:go_highlight_interfaces = 1 I get the following syntax profiler report:
Same settings but with the patch:
I only had to replace let g:go_highlight_structs = 1
let g:go_highlight_interfaces = 1 to let g:go_highlight_types = 1 |
Thanks a lot @datanoise I like the improvements. The syntax file really need some love (especially from someone with some regex fu skills). There are many things to do and I don't have the time to tackle all the issues. |
@datanoise @fatih I noticed this PR changed some syntax highlighting among which this one: Before the Any way/settings I can tweak this so I get the desired behaviour? |
I guess that makes sense. Could you please try this patch? diff --git a/syntax/go.vim b/syntax/go.vim
index 9dcf004..1fb3f54 100644
--- a/syntax/go.vim
+++ b/syntax/go.vim
@@ -298,7 +298,6 @@ if g:go_highlight_functions != 0
else
syn keyword goDeclaration func
endif
-hi def link goReceiverType Type
hi def link goFunction Function
" Methods;
@@ -320,6 +319,7 @@ if g:go_highlight_types != 0
syn match goTypeDecl /\<type\>/ nextgroup=goTypeName skipwhite skipnl
syn match goTypeName /\w\+/ contained nextgroup=goDeclType skipwhite skipnl
syn match goDeclType /\<interface\|struct\>/ contained skipwhite skipnl
+ hi def link goReceiverType Type
else
syn keyword goDeclType struct interface
syn keyword goDeclaration type |
@datanoise this patch stops highlighting the receiver, but it also (still) stops highlighting the pointer |
That is quite more difficult to highlight. We cannot reuse the same goOperator group name to parse the pointer Could you please try this patch? If it works I'll send a pull request. diff --git a/syntax/go.vim b/syntax/go.vim
index 9dcf004..be581b6 100644
--- a/syntax/go.vim
+++ b/syntax/go.vim
@@ -286,19 +286,22 @@ if g:go_highlight_operators != 0
syn match goOperator /:=\|||\|<-\|++\|--/
" match ...
syn match goOperator /\.\.\./
+
+ hi def link goPointerOperator Operator
endif
hi def link goOperator Operator
" Functions;
if g:go_highlight_functions != 0
syn match goDeclaration /\<func\>/ nextgroup=goReceiver,goFunction skipwhite skipnl
- syn match goReceiver /([^),]\+)/ contained nextgroup=goFunction contains=goReceiverType skipwhite skipnl
- syn match goReceiverType /\(\s\|*\)\w\+)/hs=s+1,he=e-1 contained
+ syn match goReceiver /([^),]\+)/ contained nextgroup=goFunction contains=goReceiverVar skipwhite skipnl
+ syn match goReceiverVar /\w\+/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
+ syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl
+ syn match goReceiverType /\w\+/ contained
syn match goFunction /\w\+/ contained
else
syn keyword goDeclaration func
endif
-hi def link goReceiverType Type
hi def link goFunction Function
" Methods;
@@ -320,6 +323,7 @@ if g:go_highlight_types != 0
syn match goTypeDecl /\<type\>/ nextgroup=goTypeName skipwhite skipnl
syn match goTypeName /\w\+/ contained nextgroup=goDeclType skipwhite skipnl
syn match goDeclType /\<interface\|struct\>/ contained skipwhite skipnl
+ hi def link goReceiverType Type
else
syn keyword goDeclType struct interface
syn keyword goDeclaration type |
@svanharmelen thanks for the bug reports. I've included the fix to this issue to my pull request. |
Thanks! 👍 |
Look behind regexp patterns are not recommended in syntax files,
especially with the new NFA engine. So we should try to avoid them.
Highlighting of methods, fields, methods, structs and interfaces should
be much faster now.
Consolidated two options g:go_highlight_structs and
g:go_highlight_interfaces into one g:go_highlight_types.