@@ -179,7 +179,7 @@ syntax region goComment start=+//+ end=+$+ contains=@goCommentSpell,goCommen
179179syntax region goComment start =+ /\* + end =+ \* /+ contains =@goCommentSpell,goCommentTodo keepend
180180
181181syntax keyword goCommentTodo contained TODO FIXME XXX TBD NOTE
182- syntax region goGenerateComment start =+ //go:generate+ end =+ $+ containedin =goComment
182+ syntax region goGenerateComment start =+ //go:generate+ end =+ $+ contained containedin =goComment
183183
184184hi link goCommentTodo Todo
185185hi link goComment Comment
@@ -277,9 +277,9 @@ call s:HiConfig('goInvalidRuneLiteral', ['go_highlight_rune_literal_error'], #{o
277277
278278" Simple Blocks {{{
279279
280- syntax region goBracketBlock matchgroup =goBrackets start =' \[ ' end =' \] ' contained transparent extend
281- syntax region goParenBlock matchgroup =goParens start =' (' end =' )' contained transparent extend
282- syntax region goBraceBlock matchgroup =goBraces start =' {' end =' }' contained transparent extend
280+ syntax region goBracketBlock matchgroup =goBrackets start =' \[ ' end =' \] ' transparent extend
281+ syntax region goParenBlock matchgroup =goParens start =' (' end =' )' transparent extend
282+ syntax region goBraceBlock matchgroup =goBraces start =' {' end =' }' transparent extend
283283
284284hi link goBraces Delimiter
285285hi link goBrackets Delimiter
@@ -427,12 +427,16 @@ syntax region goMapKeyType matchgroup=goMapBrackets start='\[' end='\]' contain
427427syntax match goSliceOrArrayType / \[\% (\d\+\|\.\.\.\)\?\] / contained contains =goNumber,goDot skipwhite nextgroup =@goType
428428
429429" A lookbehind is used to distinguish a slice/array literal with slice indexing
430- syntax match goSliceOrArrayLiteral / \k\@ 1<!\[ [0-9.]*\]\z e\% (\*\|\K\|\[\| (\) / contained contains =goNumber,goDot skipwhite nextgroup =goSliceItemType
430+ syntax match goSliceOrArrayLiteral / \k\@ 1<!\[ [0-9.]*\]\z e\% (\*\|\K\|\[\| (\) / contained contains =goNumber,goDot skipwhite nextgroup =goSliceLiteralType
431431
432- " Only look to the end of the line for the item type, and let slices etc. extend
433- " across lines as necessary. Note the first '(' is to match the first paren
434- " around the type, which is then extended by goTypeParens.
435- syntax match goSliceItemType / (\|\% (\% (interface\| struct\)\s *{\| [^{()]\)\+ / contained contains =@goType skipwhite nextgroup =goSliceItems
432+ " goSliceOrArrayLiteralType allows matching complex types for slice literals
433+ " such as named return parameters when using a slice of functions without
434+ " parentheses, e.g. "[]func() (foo, bar int) { f1, f2, f3 }", which is
435+ " technically valid, albeit hard to read. The use of a region allows the
436+ " contained matches (goSliceLiteralTypeMatch) to extend the region as necessary,
437+ " allowing the type to contain braces, such as "[]struct{X, Y int}{ ... }"
438+ syntax region goSliceLiteralType start =' \S ' end =' \z e{\| $' contained contains =goSliceLiteralTypeMatch skipwhite skipnl nextgroup =goSliceItems
439+ syntax match goSliceLiteralTypeMatch / \% (\% (interface\| struct\)\s *{\| [^{]\)\+ / contained contains =@goType
436440
437441syntax region goSliceItems matchgroup =goSliceBraces start =' {' end =' }' contained contains =goStructLiteralBlock,@goExpr,goComment
438442
@@ -493,7 +497,6 @@ syntax match goFuncName /\K\k*/ contained skipwhite nextgroup=goFuncTypeParams,g
493497
494498syntax region goFuncTypeParams matchgroup =goTypeParamBrackets start =' \[ ' end =' \] ' contained contains =goTypeParam,goComma,goComment nextgroup =goFuncParams
495499
496- " TODO: is skipempty needed?
497500syntax match goTypeParam / \K\k */ contained skipwhite skipempty nextgroup =goTypeParamComma,goTypeConstraint
498501syntax match goTypeParamComma / ,/ contained skipwhite skipempty nextgroup =goTypeParam
499502
@@ -503,7 +506,10 @@ syntax match goTypeParamComma /,/ contained skipwhite skipempty nextgroup=go
503506syntax region goTypeConstraint start =' \s ' ms =e + 1 end =/ [,\] ]/ me =s - 1 contained contains =@goType,goTypeConstraintSymbols
504507syntax match goTypeConstraintSymbols / [~|]/ contained
505508
506- syntax match goFuncReturnType / \s *\z s(\@ 1<!\% (\% (interface\| struct\)\s *{\| [^{]\)\+ {\@ 1<!/ contained contains =@goType skipwhite skipempty nextgroup =goFuncBlock
509+ " This is odd, but the \s*\zs at the start seems to ensure that the (\@1<!
510+ " negative lookbehind works as desired (i.e. to not steal a match from
511+ " goFuncMultiReturn); look into this further and try to remove this.
512+ syntax match goFuncReturnType / \s *\z s(\@ 1<!\% (\% (interface\| struct\)\s *{\| [^{]\)\+ / contained contains =@goType skipwhite skipempty nextgroup =goFuncBlock
507513
508514syntax region goFuncParams matchgroup =goFuncParens start =' (' end =' )' contained contains =goParam,goComma,goComment skipwhite nextgroup =goFuncReturnType,goFuncMultiReturn,goFuncBlock
509515syntax region goFuncMultiReturn matchgroup =goFuncMultiReturnParens start =' (' end =' )' contained contains =goNamedReturnValue,goComma,goComment skipwhite skipempty nextgroup =goFuncBlock
@@ -569,7 +575,10 @@ syntax match goEmbeddedType /\*\?\K\k*\%(\.\K\k*\)\?\%#\@1<!$/ containe
569575syntax match goStructLiteral / \v\K\k *\z e%(\{ |\[\s *\n ?%(,\n |[^\[\] ]|\[\s *\n ?%(,\n |[^\[\] ]|\[ [^\[\] ]*\] )*\] )*\]\{ )/ contained nextgroup =goStructLiteralTypeArgs,goStructLiteralBlock
570576syntax region goStructLiteralTypeArgs matchgroup =goTypeParamBrackets start =' \[ ' end =' \] ' contained contains =@goType,goUnderscore,goComma,goComment nextgroup =goStructLiteralBlock
571577
572- GoFoldStruct syntax region goStructLiteralBlock matchgroup= goStructBraces start = ' {' end = ' }' contained contains= goStructLiteralField,goComma,@g oExpr,goComment
578+ " goStructLiteralBlock contains itself to 1) prevent weird highlighting while
579+ " typing, and 2) allow slice literals of slices of structs to highlight
580+ " correctly
581+ GoFoldStruct syntax region goStructLiteralBlock matchgroup= goStructBraces start = ' {' end = ' }' contained contains= goStructLiteralField,goComma,@g oExpr,goComment,goStructLiteralBlock
573582
574583syntax match goStructLiteralField / \<\K\k *\z e:/ contained nextgroup =goStructLiteralColon
575584syntax match goStructLiteralColon / :/ contained
@@ -609,10 +618,11 @@ call s:HiConfig('goStructTypeField', ['go_highlight_struct_type_fields'], #{d
609618syntax keyword goBuiltins append cap close complex copy delete imag len panic print println real recover contained skipwhite nextgroup =goFuncCallArgs
610619
611620syntax keyword goMakeBuiltin make contained skipwhite nextgroup =goMakeBlock
612- syntax region goMakeBlock matchgroup =goFuncCallParens start =' (' end =' )' contained contains =@goType,@goExpr,goComment
621+ syntax region goMakeBlock matchgroup =goFuncCallParens start =' (' end =' )' contained contains =@goType,goMakeArguments,goComment
622+ syntax region goMakeArguments start =' ,' end =' \z e)' contained contains =@goExpr,gComment
613623
614624syntax keyword goNewBuiltin new contained skipwhite nextgroup =goNewBlock
615- syntax region goNewBlock matchgroup =goFuncCallParens start =' (' end =' )' contained contains =@goType,@goExpr, goComment
625+ syntax region goNewBlock matchgroup =goFuncCallParens start =' (' end =' )' contained contains =@goType,goComment
616626
617627hi link goBuiltins Special
618628hi link goMakeBuiltin goBuiltins
0 commit comments