go.vim 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. let s:fold_block = 1
  2. let s:fold_import = 1
  3. let s:fold_varconst = 1
  4. if exists("g:go_fold_enable")
  5. if index(g:go_fold_enable, 'block') == -1
  6. let s:fold_block = 0
  7. endif
  8. if index(g:go_fold_enable, 'import') == -1
  9. let s:fold_import = 0
  10. endif
  11. if index(g:go_fold_enable, 'varconst') == -1
  12. let s:fold_varconst = 0
  13. endif
  14. endif
  15. if !exists("g:go_highlight_fields")
  16. let g:go_highlight_fields = 0
  17. endif
  18. if g:go_highlight_fields != 0
  19. syn match goField /\(\.\)\@1<=\w\+\([.\ \n\r\:\)\[,+-\*}\\\]]\)\@=/
  20. endif
  21. " Order matters...
  22. if !exists("g:go_highlight_functions")
  23. let g:go_highlight_functions = 0
  24. endif
  25. if g:go_highlight_functions != 0
  26. " FIXME: This is too greedy
  27. syn match listOfTypes /\([^ ,)]\+\(,\|)\)\@=\)\+/ contains=@goDeclarations,@goDeclTypeBegin,goMapKeyRegion,goFunctionParamRegion,goFunctionReturnRegion,goDeclStructRegion,goDeclInterfaceRegion contained
  28. syn match listOfVars /\([,(]\s*\)\@<=\w\+\(\(, \w\+\)*, \w\+ \)\@=/ contained
  29. endif
  30. if !exists("g:go_highlight_types")
  31. let g:go_highlight_types = 0
  32. endif
  33. if g:go_highlight_types != 0
  34. syn clear goTypeDecl
  35. syn clear goTypeName
  36. syn clear goDeclType
  37. syn match goTypeConstructor /\<\w\+\({\)\@1=/
  38. syn cluster validTypeContains contains=goComment,goDeclSIName,goDeclTypeField,goDeclTypeName
  39. " FIXME: not sure I _need_ to state goDecl*Region
  40. syn cluster validStructContains contains=goComment,goDeclSIName,goDeclTypeField,goDeclTypeSep,@goDeclEmbeddedType,goString,goRawString,goMapType,goMapKeyRegion,goDeclStructRegion,goDeclInterfaceRegion,goPointerOperator
  41. syn cluster validInterfaceContains contains=goComment,goFunction,@goDeclEmbeddedType,goDeclInterfaceRegion
  42. syn match goDeclTypeField /\w\+/ nextgroup=goDeclTypeSep,@goDeclTypeBegin skipwhite contained
  43. syn match goDeclTypeSep /,/ nextgroup=goDeclTypeField skipwhite contained
  44. syn match goDeclEmbeddedType /\w\+\s*\($\|\/\)\@=/ skipwhite contained
  45. syn match goDeclEmbeddedTypeNS /\w\+\.\(\w\+\)\@=/ contains=OperatorChars nextgroup=goDeclEmbeddedType skipwhite contained
  46. syn match goDeclTypeName /\w\+/ nextgroup=@goDeclTypeBegin skipwhite contained
  47. syn cluster goDeclEmbeddedType contains=goDeclEmbeddedType,goDeclEmbeddedTypeNS
  48. syn match goTypeDecl /\<type\>/ nextgroup=goDeclTypeName,goTypeRegion skipwhite skipnl
  49. syn region goTypeRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validTypeContains skipwhite fold contained
  50. syn region goDeclStructRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validStructContains skipwhite fold contained
  51. syn region goDeclInterfaceRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validInterfaceContains skipwhite fold contained
  52. syn match goDeclTypeStart /\*/ contains=OperatorChars nextgroup=goDeclTypeStart,goDeclTypeNamespace,goDeclTypeType,goMapType,@goDeclarations skipwhite contained
  53. syn region goDeclTypeStart matchgroup=goContainer start=/\[/ end=/\]/ contains=@goNumbers nextgroup=goDeclTypeStart,goDeclTypeNamespace,goDeclTypeType,goMapType,@goDeclarations skipwhite transparent contained
  54. syn match goDeclTypeType /\w\+/ contains=goMapType,@goDeclarations skipwhite contained
  55. syn match goDeclTypeNamespace /\w\+\./ contains=OperatorChars nextgroup=goDeclTypeType skipwhite contained
  56. syn cluster goDeclTypeBegin contains=goDeclTypeStart,goDeclTypeType,goDeclTypeNamespace,goDeclaration,goMapType,goDeclStruct,goDeclInterface
  57. syn region goMapKeyRegion matchgroup=goContainer start=/\[/ end=/\]/ contains=@goDeclTypeBegin,goDeclaration nextgroup=@goDeclTypeBegin skipwhite contained
  58. syn keyword goMapType map nextgroup=goMapKeyRegion skipwhite
  59. " This is important in order to differentiate "field type" from "field struct"
  60. " and "field interface"
  61. " FIXME: seems fishy, see @validStructContains
  62. syn match goDeclSIName /\w\+\(\s\([*\[\] ]\)*\<\(struct\|interface\)\>\)\@=/ nextgroup=@goDeclTypeBegin,goDeclStruct,goDeclInterface skipwhite contained
  63. syn match goDeclStruct /\<struct\>/ nextgroup=goDeclStructRegion skipwhite skipnl
  64. syn match goDeclInterface /\<interface\>/ nextgroup=goDeclInterfaceRegion skipwhite skipnl
  65. syn match goVarName /[^, ]\+/ nextgroup=goVarSep,@goDeclTypeBegin,goMapType skipwhite contained
  66. syn match goVarSep /,/ nextgroup=goVarName skipwhite contained
  67. syn region goVarRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  68. syn keyword goVarDecl var nextgroup=goVarName,goVarRegion skipwhite
  69. syn region goTypeAssertionRegion matchgroup=goContainer start=/(/ end=/)/ contains=@goDeclTypeBegin,goMapType,goMapKeyRegion skipwhite contained
  70. syn match goTypeAssertionOp /\.\((\)\@=/ nextgroup=goTypeAssertionRegion skipwhite
  71. endif
  72. if g:go_highlight_functions != 0
  73. syn clear goFunctionCall
  74. syn clear goFunction
  75. syn clear goReceiverType
  76. syn match goFunctionCall /\(\.\)\@1<!\w\+\((\)\@1=/ nextgroup=goFuncMethCallRegion
  77. " FIXME: [^,()] is a lazy hack-fix that works in-tandem with listOfTypes
  78. syn match goFunctionReturn /[^,()]\{-}\({\|\/\|$\)\@=/ contains=@goDeclarations,@goDeclTypeBegin,goComment skipwhite contained
  79. syn region goFunctionParamRegion matchgroup=goContainer start=/(/ end=/)/ contains=@goDeclarations,listOfTypes,listOfVars,OperatorChars nextgroup=goFunctionReturn,goFunctionReturnRegion skipwhite transparent contained
  80. syn region goFunctionReturnRegion matchgroup=goContainer start=/(/ end=/)/ contains=@goDeclarations,listOfTypes,listOfVars,OperatorChars skipwhite transparent contained
  81. syn match goFunction /\w\+\((\)\@1=/ nextgroup=goFunctionParamRegion skipwhite contained
  82. syn match goDeclaration /\<func\>/ nextgroup=goReceiverRegion,goFunction,goFunctionParamRegion skipwhite skipnl
  83. " Use the space between func and ( to determine if the next group is a
  84. " receiver or an inlined function (which matches gofmt)
  85. syn region goReceiverRegion matchgroup=goContainer start=/ (/ end=/)/ contains=goReceiverVar,goPointerOperator,@goDeclTypeBegin nextgroup=goFunction skipwhite contained
  86. syn match goReceiverVar /\w\+ / nextgroup=goPointerOperator,@goDeclTypeBegin skipnl contained
  87. syn match goPointerOperator /\*/ nextgroup=@goDeclTypeBegin skipwhite skipnl contained
  88. endif
  89. if !exists("g:go_highlight_methods")
  90. let g:go_highlight_methods = 0
  91. endif
  92. if g:go_highlight_methods != 0
  93. syn clear goMethodCall
  94. syn match goMethodCall /\(\.\)\@1<=\w\+\((\)\@1=/ nextgroup=goFuncMethCallRegion
  95. endif
  96. syn clear goImport
  97. syn clear goVar
  98. syn clear goConst
  99. syn keyword goImport import nextgroup=goImportRegion
  100. syn keyword goVar var nextgroup=goVarConstRegion
  101. syn keyword goConst const nextgroup=goVarConstRegion
  102. if s:fold_import
  103. syn region goImportRegion start='(' end=')' transparent fold contains=goString,goComment matchgroup=goContainer
  104. else
  105. syn region goImportRegion start='(' end=')' transparent contains=goString,goComment matchgroup=goContainer
  106. endif
  107. if s:fold_varconst
  108. syn region goVarConstRegion start='(' end='^\s*)$' transparent fold matchgroup=goContainer
  109. \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar
  110. else
  111. syn region goVarConstRegion start='(' end='^\s*)$' transparent matchgroup=goContainer
  112. \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar
  113. endif
  114. syn cluster goDeclarations contains=goDeclaration,goDeclStruct,goDeclInterface
  115. syn cluster goTypes contains=goType,goSignedInts,goUnsignedInts,goFloats,goComplexes
  116. syn cluster goNumbers contains=goDecimalInt,goHexadecimalInt,goOctalInt,goFloat,goImaginary,goImaginaryFloat
  117. syn region goFuncMethCallRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  118. syn match goLiteralStructField /\w\+\ze:[^=]/
  119. " Order is important, so redefine
  120. syn match goBuiltins /\<\(append\|cap\|close\|complex\|copy\|delete\|imag\|len\)\((\)\@=/ nextgroup=goBuiltinRegion
  121. syn match goBuiltins /\<\(make\|new\|panic\|print\|println\|real\|recover\)\((\)\@=/ nextgroup=goBuiltinRegion
  122. syn region goBuiltinRegion matchgroup=goContainer start=/(/ end=/)/ transparent contained
  123. syn region ParenContainer matchgroup=goContainer start=/(/ end=/)/ transparent
  124. syn region BraceContainer matchgroup=goContainer start=/{/ end=/}/ transparent
  125. syn region BracketContainer matchgroup=goContainer start=/\[/ end=/\]/ transparent
  126. hi link goPointerOperator Operator
  127. hi link goDeclTypeStart Operator
  128. hi link goTypeAssertionOp Operator
  129. hi link goVarSep Operator
  130. hi link goDeclTypeSep Operator
  131. hi link goTypeConstructor Type
  132. hi link goDeclSIName Type
  133. hi link goDeclTypeType Type
  134. hi link goMapType Type
  135. hi link goDeclTypeName Type
  136. hi link goDeclEmbeddedType Type
  137. hi link goVarDecl goDeclaration
  138. hi link goDeclInterface goDeclaration
  139. hi link goDeclStruct goDeclaration
  140. hi link goFunction Function
  141. hi link goMethodCall Function
  142. hi link goFunctionCall Function
  143. hi link goContainer ContainerChars
  144. hi link goLiteralStructField Special