-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,12 +71,8 @@ if !exists("g:go_highlight_fields") | |
let g:go_highlight_fields = 0 | ||
endif | ||
|
||
if !exists("g:go_highlight_structs") | ||
let g:go_highlight_structs = 0 | ||
endif | ||
|
||
if !exists("g:go_highlight_interfaces") | ||
let g:go_highlight_interfaces = 0 | ||
if !exists("g:go_highlight_types") | ||
let g:go_highlight_types = 0 | ||
endif | ||
|
||
if !exists("g:go_highlight_build_constraints") | ||
|
@@ -98,12 +94,10 @@ endif | |
syn case match | ||
|
||
syn keyword goDirective package import | ||
syn keyword goDeclaration var const type | ||
syn keyword goDeclType struct interface | ||
syn keyword goDeclaration var const | ||
|
||
hi def link goDirective Statement | ||
hi def link goDeclaration Keyword | ||
hi def link goDeclType Keyword | ||
|
||
" Keywords within functions | ||
syn keyword goStatement defer go goto return break continue fallthrough | ||
|
@@ -129,10 +123,6 @@ hi def link goUnsignedInts Type | |
hi def link goFloats Type | ||
hi def link goComplexes Type | ||
|
||
" Treat func specially: it's a declaration at the start of a line, but a type | ||
" elsewhere. Order matters here. | ||
syn match goDeclaration /\<func\>/ | ||
|
||
|
||
" Predefined functions and values | ||
syn match goBuiltins /\<\v(append|cap|close|complex|copy|delete|imag|len)\ze\(/ | ||
|
@@ -301,38 +291,42 @@ hi def link goOperator Operator | |
|
||
" Functions; | ||
if g:go_highlight_functions != 0 | ||
syn match goFunction /\(func\s\+\)\@<=\w\+\((\)\@=/ | ||
syn match goFunction /\()\s\+\)\@<=\w\+\((\)\@=/ | ||
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 goFunction /\w\+/ contained | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we have the else clause here? If it's not enabled we should not highlight anything at all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to pull down |
||
syn match goDeclaration /\<func\>/ | ||
endif | ||
hi def link goReceiverType Type | ||
hi def link goFunction Function | ||
|
||
" Methods; | ||
if g:go_highlight_methods != 0 | ||
syn match goMethod /\(\.\)\@<=\w\+\((\)\@=/ | ||
syn match goMethod /\.\w\+(/hs=s+1,he=e-1 | ||
endif | ||
hi def link goMethod Type | ||
|
||
" Fields; | ||
if g:go_highlight_fields != 0 | ||
syn match goField /\(\.\)\@<=\a\+\([\ \n\r\:\)]\)\@=/ | ||
syn match goVarArgs /\.\.\.\w\+\>/ | ||
syn match goField /\.\a\+\([\ \n\r\:\)\[]\)\@=/hs=s+1 | ||
endif | ||
hi def link goField Type | ||
|
||
" Structs; | ||
if g:go_highlight_structs != 0 | ||
syn match goStruct /\(.\)\@<=\w\+\({\)\@=/ | ||
syn match goStructDef /\(type\s\+\)\@<=\w\+\(\s\+struct\s\+{\)\@=/ | ||
endif | ||
hi def link goStruct Function | ||
hi def link goStructDef Function | ||
|
||
" Interfaces; | ||
if g:go_highlight_interfaces != 0 | ||
syn match goInterface /\(.\)\@<=\w\+\({\)\@=/ | ||
syn match goInterfaceDef /\(type\s\+\)\@<=\w\+\(\s\+interface\s\+{\)\@=/ | ||
hi def link goField Identifier | ||
|
||
" Structs & Interfaces; | ||
if g:go_highlight_types != 0 | ||
syn match goTypeConstructor /\<\w\+{/he=e-1 | ||
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 | ||
else | ||
syn keyword goDeclType struct interface | ||
endif | ||
hi def link goInterface Function | ||
hi def link goInterfaceDef Function | ||
hi def link goTypeConstructor Type | ||
hi def link goTypeName Type | ||
hi def link goTypeDecl Keyword | ||
hi def link goDeclType Keyword | ||
|
||
" Build Constraints | ||
if g:go_highlight_build_constraints != 0 | ||
|
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
fromtype Name interface
. Let me think about it a bit more. Maybe it can be done usingsyn-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.