Skip to content

Commit cf2eb94

Browse files
committed
Make sure comments are contained in all regions where they could appear
1 parent 0be2ca2 commit cf2eb94

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

syntax/go.vim

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -397,44 +397,44 @@ syntax match goPointer /*/ contained nextgroup=@goType
397397

398398
" goTypeParens is used to ensure types within parens are highlighted correctly,
399399
" e.g. the func type in the slice literal `[](func (a, b int) bool){ ... }`
400-
syntax region goTypeParens start='(' end=')' contained contains=@goType
400+
syntax region goTypeParens start='(' end=')' contained contains=@goType,goComment
401401

402402
syntax keyword goTypeDecl type skipwhite skipempty nextgroup=goTypeDeclName,goTypeDeclGroup
403403
syntax match goTypeDeclName /\K\k*/ contained skipwhite skipempty nextgroup=goTypeDeclTypeParams,goTypeAssign,@goType
404404
syntax match goTypeAssign /=/ contained skipwhite nextgroup=@goType
405405

406406
syntax region goTypeDeclGroup matchgroup=goTypeDeclGroupParens start='(' end=')' contained contains=goTypeDeclName,goComment
407-
syntax region goTypeDeclTypeParams matchgroup=goTypeParamBrackets start='\[' end='\]' contained contains=goTypeParam,goComma nextgroup=@goType
407+
syntax region goTypeDeclTypeParams matchgroup=goTypeParamBrackets start='\[' end='\]' contained contains=goTypeParam,goComma,goComment nextgroup=@goType
408408

409409
" goNonPrimitiveType is used for matching the names and packages of
410410
" non-primitive types (i.e. types other than int, bool, string, etc.). Note the
411411
" optional non-capturing group is later in the pattern to avoid backtracking.
412412
syntax match goNonPrimitiveType /\<\K\k*\%(\.\K\k*\)\?\[\?/ contained contains=goPackageName,goTypeArgs
413413
syntax match goPackageName /\<\K\k*\ze\./ contained nextgroup=goDot
414414

415-
syntax region goTypeArgs matchgroup=goTypeParamBrackets start='\[' end='\]' contained contains=@goType,goUnderscore,goComma
415+
syntax region goTypeArgs matchgroup=goTypeParamBrackets start='\[' end='\]' contained contains=@goType,goUnderscore,goComma,goComment
416416

417417
syntax keyword goPrimitiveTypes any bool byte complex128 complex64 error float32 float64 int int8 int16 int32 int64 rune string uint uint8 uint16 uint32 uint64 uintptr contained
418418

419419
syntax match goFuncType /func\s*(/ contained contains=goFuncTypeParens skipwhite nextgroup=@goType,goFuncTypeMultiReturnType
420420

421-
syntax region goFuncTypeParens matchgroup=goFuncParens start='(' end=')' contained contains=goFuncTypeParam,goComma
422-
syntax region goFuncTypeMultiReturnType matchgroup=goFuncMultiReturnParens start='(' end=')' contained contains=goNamedReturnValue,goComma
421+
syntax region goFuncTypeParens matchgroup=goFuncParens start='(' end=')' contained contains=goFuncTypeParam,goComma,goComment
422+
syntax region goFuncTypeMultiReturnType matchgroup=goFuncMultiReturnParens start='(' end=')' contained contains=goNamedReturnValue,goComma,goComment
423423

424424
syntax keyword goMap map contained skipwhite skipempty nextgroup=goMapKeyType
425425
syntax region goMapKeyType matchgroup=goMapBrackets start='\[' end='\]' contained contains=@goType skipwhite nextgroup=@goType
426426

427427
syntax 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<!\[\%(\d\+\|\.\.\.\)\?\]\ze\%(\*\|\K\|\[\|(\)/ contained contains=goNumber,goDot skipwhite nextgroup=goSliceItemType
430+
syntax match goSliceOrArrayLiteral /\k\@1<!\[[0-9.]*\]\ze\%(\*\|\K\|\[\|(\)/ contained contains=goNumber,goDot skipwhite nextgroup=goSliceItemType
431431

432432
" Only look to the end of the line for the item type, and let slices etc. extend
433433
" across lines as necessary. Note the first '(' is to match the first paren
434434
" around the type, which is then extended by goTypeParens.
435435
syntax match goSliceItemType /(\|\%(\%(interface\|struct\)\s*{\|[^{()]\)\+/ contained contains=@goType skipwhite nextgroup=goSliceItems
436436

437-
syntax region goSliceItems matchgroup=goSliceBraces start='{' end='}' contained contains=goStructLiteralBlock,@goExpr
437+
syntax region goSliceItems matchgroup=goSliceBraces start='{' end='}' contained contains=goStructLiteralBlock,@goExpr,goComment
438438

439439
syntax match goChannel /<-chan/ contained contains=goChannelDir skipwhite nextgroup=@goType
440440
syntax match goChannel /chan\%(<-\)\?/ contained contains=goChannelDir skipwhite nextgroup=@goType
@@ -476,8 +476,8 @@ call s:HiConfig('goMapBrackets', ['go_highlight_map_brackets'])
476476

477477
" Unfortunately limited to at most 3 nested type args
478478
syntax match goFuncCall /\v\K\k*\ze%(\(|\[\s*\n?%(,\n|[^\[\]]|\[\s*\n?%(,\n|[^\[\]]|\[[^\[\]]*\])*\])*\]\()/ contained nextgroup=goFuncCallTypeArgs,goFuncCallArgs
479-
syntax region goFuncCallTypeArgs matchgroup=goTypeParamBrackets start='\[' end='\]' contained contains=@goType,goUnderscore,goComma nextgroup=goFuncCallArgs
480-
syntax region goFuncCallArgs matchgroup=goFuncCallParens start='(' end=')' contained contains=@goExpr
479+
syntax region goFuncCallTypeArgs matchgroup=goTypeParamBrackets start='\[' end='\]' contained contains=@goType,goUnderscore,goComma,goComment nextgroup=goFuncCallArgs
480+
syntax region goFuncCallArgs matchgroup=goFuncCallParens start='(' end=')' contained contains=@goExpr,goComment
481481

482482
syntax keyword goFuncDecl func skipwhite skipempty nextgroup=goFuncName,goMethodReceiver
483483
syntax keyword goFuncLiteral func contained skipwhite skipempty nextgroup=goFuncName,goFuncParams
@@ -491,7 +491,7 @@ syntax match goParamComma /,/ contained skipwhite skipempty nextgroup=goPara
491491

492492
syntax match goFuncName /\K\k*/ contained skipwhite nextgroup=goFuncTypeParams,goFuncParams
493493

494-
syntax region goFuncTypeParams matchgroup=goTypeParamBrackets start='\[' end='\]' contained contains=goTypeParam,goComma nextgroup=goFuncParams
494+
syntax region goFuncTypeParams matchgroup=goTypeParamBrackets start='\[' end='\]' contained contains=goTypeParam,goComma,goComment nextgroup=goFuncParams
495495

496496
" TODO: is skipempty needed?
497497
syntax match goTypeParam /\K\k*/ contained skipwhite skipempty nextgroup=goTypeParamComma,goTypeConstraint
@@ -505,9 +505,9 @@ syntax match goTypeConstraintSymbols /[~|]/ contained
505505

506506
syntax match goFuncReturnType /\s*\zs(\@1<!\%(\%(interface\|struct\)\s*{\|[^{]\)\+{\@1<!/ contained contains=@goType skipwhite skipempty nextgroup=goFuncBlock
507507

508-
syntax region goFuncParams matchgroup=goFuncParens start='(' end=')' contained contains=goParam,goComma skipwhite nextgroup=goFuncReturnType,goFuncMultiReturn,goFuncBlock
509-
syntax region goFuncMultiReturn matchgroup=goFuncMultiReturnParens start='(' end=')' contained contains=goNamedReturnValue,goComma skipwhite skipempty nextgroup=goFuncBlock
510-
syntax region goMethodReceiver matchgroup=goReceiverParens start='(' end=')' contained contains=goFuncTypeParam skipwhite skipempty nextgroup=goFuncName
508+
syntax region goFuncParams matchgroup=goFuncParens start='(' end=')' contained contains=goParam,goComma,goComment skipwhite nextgroup=goFuncReturnType,goFuncMultiReturn,goFuncBlock
509+
syntax region goFuncMultiReturn matchgroup=goFuncMultiReturnParens start='(' end=')' contained contains=goNamedReturnValue,goComma,goComment skipwhite skipempty nextgroup=goFuncBlock
510+
syntax region goMethodReceiver matchgroup=goReceiverParens start='(' end=')' contained contains=goFuncTypeParam,goComment skipwhite skipempty nextgroup=goFuncName
511511

512512
GoFoldFunc syntax region goFuncBlock matchgroup=goFuncBraces start='{' end='}' contained contains=@goStatement skipwhite nextgroup=goFuncCallArgs
513513

@@ -567,19 +567,19 @@ syntax match goEmbeddedType /\*\?\K\k*\%(\.\K\k*\)\?\%#\@1<!$/ containe
567567
" It is technically possible to have a space between a struct name and the
568568
" braces, but it's hard to reliably highlight
569569
syntax match goStructLiteral /\v\K\k*\ze%(\{|\[\s*\n?%(,\n|[^\[\]]|\[\s*\n?%(,\n|[^\[\]]|\[[^\[\]]*\])*\])*\]\{)/ contained nextgroup=goStructLiteralTypeArgs,goStructLiteralBlock
570-
syntax region goStructLiteralTypeArgs matchgroup=goTypeParamBrackets start='\[' end='\]' contained contains=@goType,goUnderscore,goComma nextgroup=goStructLiteralBlock
570+
syntax region goStructLiteralTypeArgs matchgroup=goTypeParamBrackets start='\[' end='\]' contained contains=@goType,goUnderscore,goComma,goComment nextgroup=goStructLiteralBlock
571571

572-
GoFoldStruct syntax region goStructLiteralBlock matchgroup=goStructBraces start='{' end='}' contained contains=goStructLiteralField,goComma,@goExpr
572+
GoFoldStruct syntax region goStructLiteralBlock matchgroup=goStructBraces start='{' end='}' contained contains=goStructLiteralField,goComma,@goExpr,goComment
573573

574-
syntax match goStructLiteralField /\<\K\k*\ze:/ contained nextgroup=goStructLiteralColon
575-
syntax match goStructLiteralColon /:/ contained
574+
syntax match goStructLiteralField /\<\K\k*\ze:/ contained nextgroup=goStructLiteralColon
575+
syntax match goStructLiteralColon /:/ contained
576576

577577
syntax keyword goInterfaceType interface contained skipwhite skipempty nextgroup=goInterfaceBlock
578578
syntax region goInterfaceBlock matchgroup=goInterfaceBraces start='{' end='}' contained contains=@goType,goTypeConstraintSymbols,goInterfaceMethod,goComment extend
579579

580580
syntax match goInterfaceMethod /\K\k*\ze(/ contained skipwhite nextgroup=goInterfaceMethodParams
581-
syntax region goInterfaceMethodParams matchgroup=goInterfaceMethodParens start='(' end=')' contained contains=goFuncTypeParam,goComma skipwhite nextgroup=@goType,goInterfaceMethodMultiReturn
582-
syntax region goInterfaceMethodMultiReturn matchgroup=goFuncMultiReturnParens start='(' end=')' contained contains=goNamedReturnValue,goComma
581+
syntax region goInterfaceMethodParams matchgroup=goInterfaceMethodParens start='(' end=')' contained contains=goFuncTypeParam,goComma,goComment skipwhite nextgroup=@goType,goInterfaceMethodMultiReturn
582+
syntax region goInterfaceMethodMultiReturn matchgroup=goFuncMultiReturnParens start='(' end=')' contained contains=goNamedReturnValue,goComma,goComment
583583

584584
hi link goStructType Keyword
585585
hi link goStructTypeBraces goBraces
@@ -609,10 +609,10 @@ call s:HiConfig('goStructTypeField', ['go_highlight_struct_type_fields'], #{d
609609
syntax keyword goBuiltins append cap close complex copy delete imag len panic print println real recover contained skipwhite nextgroup=goFuncCallArgs
610610

611611
syntax keyword goMakeBuiltin make contained skipwhite nextgroup=goMakeBlock
612-
syntax region goMakeBlock matchgroup=goFuncCallParens start='(' end=')' contained contains=@goType,@goExpr
612+
syntax region goMakeBlock matchgroup=goFuncCallParens start='(' end=')' contained contains=@goType,@goExpr,goComment
613613

614614
syntax keyword goNewBuiltin new contained skipwhite nextgroup=goNewBlock
615-
syntax region goNewBlock matchgroup=goFuncCallParens start='(' end=')' contained contains=@goType
615+
syntax region goNewBlock matchgroup=goFuncCallParens start='(' end=')' contained contains=@goType,@goExpr,goComment
616616

617617
hi link goBuiltins Special
618618
hi link goMakeBuiltin goBuiltins

0 commit comments

Comments
 (0)