go.vim 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. if !exists("g:go_highlight_fields")
  2. let g:go_highlight_fields = 0
  3. endif
  4. if g:go_highlight_fields != 0
  5. syn match goField /\(\.\)\@1<=\w\+\([.\ \n\r\:\)\[,+-\*}\\\]]\)\@=/
  6. endif
  7. " Order matters...
  8. if !exists("g:go_highlight_functions")
  9. let g:go_highlight_functions = 0
  10. endif
  11. if g:go_highlight_functions != 0
  12. " FIXME: This is too greedy
  13. syn match listOfTypes /\(\S\+\ze[,)]\)\+/ contains=@goDeclarations,@goDeclTypeBegin,goMapKeyRegion,goFunctionParamRegion,goFunctionReturnRegion,goDeclStructRegion,goDeclInterfaceRegion contained
  14. syn match listOfVars /\([,(]\s*\)\@<=\w\+\(\(, \w\+\)*, \w\+ \)\@=/ contained
  15. endif
  16. if !exists("g:go_highlight_types")
  17. let g:go_highlight_types = 0
  18. endif
  19. if g:go_highlight_types != 0
  20. syn clear goTypeDecl
  21. syn clear goTypeName
  22. syn clear goDeclType
  23. syn match goTypeConstructor /\<\w\+\({\)\@1=/
  24. syn cluster validTypeContains contains=goComment,goDeclSIName,goDeclTypeField
  25. " FIXME: not sure I _need_ to state goDecl_Region
  26. syn cluster validStructContains contains=goComment,goDeclSIName,goDeclTypeField,goString,goRawString,goMapType,goMapKeyRegion,goDeclStructRegion,goDeclInterfaceRegion
  27. syn cluster validInterfaceContains contains=goComment,goFunction,goNestedInterfaceType
  28. syn match goDeclTypeField /\w\+/ nextgroup=@goDeclTypeBegin skipwhite contained
  29. syn match goTypeDecl /\<type\>/ nextgroup=goDeclSIName,goTypeRegion skipwhite skipnl
  30. syn region goTypeRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validTypeContains skipwhite fold contained
  31. syn region goDeclStructRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validStructContains skipwhite fold contained
  32. syn region goDeclInterfaceRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validInterfaceContains skipwhite fold contained
  33. syn match goNestedInterfaceType /\w\+/ contained
  34. syn match goDeclTypeStart /\*/ contains=OperatorChars nextgroup=goDeclTypeStart,goDeclTypeNamespace,goDeclTypeWord,goMapType,@goDeclarations skipwhite contained
  35. syn region goDeclTypeStart matchgroup=goContainer start=/\[/ end=/\]/ contains=@goNumbers nextgroup=goDeclTypeStart,goDeclTypeNamespace,goDeclTypeWord,goMapType,@goDeclarations skipwhite transparent contained
  36. syn match goDeclTypeWord /\w\+/ contains=goMapType,@goDeclarations skipwhite contained
  37. syn match goDeclTypeNamespace /\w\+\./ contains=OperatorChars nextgroup=goDeclTypeWord skipwhite contained
  38. syn cluster goDeclTypeBegin contains=goDeclTypeStart,goDeclTypeWord,goDeclTypeNamespace
  39. syn region goMapKeyRegion matchgroup=goContainer start=/\[/ end=/\]/ contains=@goDeclTypeBegin,goDeclaration nextgroup=@goDeclTypeBegin skipwhite contained
  40. syn keyword goMapType map nextgroup=goMapKeyRegion skipwhite
  41. " This is important in order to differentiate "field type" from "field struct"
  42. " and "field interface"
  43. " FIXME: seems fishy, see @validStructContains
  44. syn match goDeclSIName /\w\+\(\s\([*\[\] ]\)*\<\(struct\|interface\)\>\)\@=/ nextgroup=@goDeclTypeBegin,goDeclStruct,goDeclInterface skipwhite contained
  45. syn match goDeclStruct /\<struct\>/ nextgroup=goDeclStructRegion skipwhite skipnl
  46. syn match goDeclInterface /\<interface\>/ nextgroup=goDeclInterfaceRegion skipwhite skipnl
  47. syn match goVarVar /[^, ]\+/ nextgroup=goVarSep,@goDeclTypeBegin,goMapType skipwhite contained
  48. syn match goVarSep /,/ nextgroup=goVarVar skipwhite contained
  49. syn region goVarRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  50. syn keyword goVarDecl var nextgroup=goVarVar,goVarRegion skipwhite
  51. syn region goTypeAssertionRegion matchgroup=goContainer start=/(/ end=/)/ contains=@goDeclTypeBegin,goMapType,goMapKeyRegion skipwhite contained
  52. syn match goTypeAssertionOp /\.\((\)\@=/ nextgroup=goTypeAssertionRegion skipwhite
  53. endif
  54. if g:go_highlight_functions != 0
  55. syn clear goFunctionCall
  56. syn clear goFunction
  57. syn clear goReceiverType
  58. syn match goFunctionCall /\(\.\)\@1<!\w\+\((\)\@1=/ nextgroup=goFuncMethCallRegion
  59. " FIXME: ^{\], is a lazy hack-fix
  60. syn match goFunctionReturn /[^{\]), ]\+/ contains=@goDeclarations,@goDeclTypeBegin skipwhite contained
  61. syn region goFunctionParamRegion matchgroup=goContainer start=/(/ end=/)/ contains=@goDeclarations,listOfTypes,listOfVars,OperatorChars nextgroup=goFunctionReturn,goFunctionReturnRegion skipwhite transparent contained
  62. syn region goFunctionReturnRegion matchgroup=goContainer start=/(/ end=/)/ contains=@goDeclarations,listOfTypes,listOfVars,OperatorChars skipwhite transparent contained
  63. syn match goFunction /\w\+\((\)\@1=/ nextgroup=goFunctionParamRegion skipwhite contained
  64. syn match goDeclaration /\<func\>/ nextgroup=goReceiverRegion,goFunction,goFunctionParamRegion skipwhite skipnl
  65. " Use the space between func and ( to determine if the next group is a
  66. " receiver or an inlined function (which matches gofmt)
  67. syn region goReceiverRegion matchgroup=goContainer start=/ (/ end=/)/ contains=goReceiver nextgroup=goFunction skipwhite contained
  68. syn match goReceiver /\(\w\|[ *]\)\+/ contains=goReceiverVar,goPointerOperator skipwhite skipnl contained
  69. syn match goReceiverVar /\w\+/ nextgroup=goPointerOperator,@goDeclTypeBegin skipwhite skipnl contained
  70. syn match goPointerOperator /\*/ nextgroup=@goDeclTypeBegin skipwhite skipnl contained
  71. endif
  72. if !exists("g:go_highlight_methods")
  73. let g:go_highlight_methods = 0
  74. endif
  75. if g:go_highlight_methods != 0
  76. syn clear goMethodCall
  77. syn match goMethodCall /\(\.\)\@1<=\w\+\((\)\@1=/ nextgroup=goFuncMethCallRegion
  78. endif
  79. syn cluster goDeclarations contains=goDeclaration,goDeclStruct,goDeclInterface
  80. syn cluster goTypes contains=goType,goSignedInts,goUnsignedInts,goFloats,goComplexes
  81. syn cluster goNumbers contains=goDecimalInt,goHexadecimalInt,goOctalInt,goFloat,goImaginary,goImaginaryFloat
  82. syn region goFuncMethCallRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  83. syn match goLiteralStructField /\w\+\ze:[^=]/
  84. " Order is important, so redefine
  85. syn match goBuiltins /\<\(append\|cap\|close\|complex\|copy\|delete\|imag\|len\)\((\)\@=/ nextgroup=goBuiltinRegion
  86. syn match goBuiltins /\<\(make\|new\|panic\|print\|println\|real\|recover\)\((\)\@=/ nextgroup=goBuiltinRegion
  87. syn region goBuiltinRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  88. hi link goPointerOperator Operator
  89. hi link goTypeAssertionOp Operator
  90. hi link goVarSep Operator
  91. hi link goTypeConstructor Type
  92. hi link goDeclSIName Type
  93. hi link goDeclTypeWord Type
  94. hi link goNestedInterfaceType Type
  95. hi link goMapType Type
  96. hi link goVarDecl goDeclaration
  97. hi link goDeclInterface goDeclaration
  98. hi link goDeclStruct goDeclaration
  99. hi link goFunction Function
  100. hi link goMethodCall Function
  101. hi link goFunctionCall Function
  102. hi link goContainer ContainerChars
  103. hi link goLiteralStructField Special
  104. " don't commit this
  105. "func (c *Client) shipmentConfirmRequest(ctx context.Context, request shipmentConfirmRequest) (*shipmentConfirmResponse, error) {
  106. "var response, bar shipmentConfirmResponse
  107. "a := make(map[foo]bar)
  108. "a := make(map[func()]bar)
  109. "a := func(int, interface{}, struct{ foo int }) (a foo, b []bar, c map[foo][2]bar, d, e, f baz) { return 0 }
  110. "a := func(a foo, b []bar, c map[foo]bar) int {}
  111. "a := func(a foo, b []bar, c map[foo]interface{}) int {}
  112. "a := func(a foo, b []bar, c map[func()]bar) int {}
  113. "a := func(a foo, b []bar, c map[func()]func()) int {}
  114. "b := func(f foo, c, a map[foo]int) (int, int) {}
  115. "a := func(int) (a, b foo, c, d bar) {}
  116. "b := func(int) interface{} {}
  117. "c := func(int) int {}
  118. "d := func(f func(int, asdf) int, a word) (int, thing, func(func())) {}
  119. "e := func(f func() int, a word) func() {}
  120. "f := func(f func() int, a word) (interface{}, interface{}) {}
  121. "var g func() func(Service) int
  122. "h := func(int) (int, string) {}
  123. "}