go.vim 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. syn cluster goTypes contains=goType,goSignedInts,goUnsignedInts,goFloats,goComplexes
  2. syn cluster goNumber contains=goDecimalInt,goHexadecimalInt,goOctalInt,goFloat,goImaginary,goImaginaryFloat
  3. if !exists("g:go_highlight_fields")
  4. let g:go_highlight_fields = 0
  5. endif
  6. if g:go_highlight_fields != 0
  7. syn match goField /\(\.\)\@1<=\w\+\([.\ \n\r\:\)\[,+-\*}\\\]]\)\@=/
  8. endif
  9. if !exists("g:go_highlight_types")
  10. let g:go_highlight_types = 0
  11. endif
  12. if g:go_highlight_types != 0
  13. syn match goTypeConstructor /\<\w\+\({\)\@1=/
  14. " This is most likely bad... probably very bad.. and brittle?
  15. " mostly, it's incomplete but kinda matches gofmt, so theres that at least
  16. syn clear goTypeDecl
  17. syn clear goTypeName
  18. syn clear goDeclType
  19. syn cluster validTypeContains contains=goComment,goNewDeclType,goDeclTypeField,goDeclTypeW,goDeclTypeFieldSlice,goDeclTypeFieldPointerOp,goString,goRawString,OperatorChars,goContainer
  20. syn cluster validStructContains contains=goComment,goNewDeclType,goDeclTypeField,goDeclTypeW,goString,goRawString,OperatorChars,goContainer
  21. syn cluster validInterfaceContains contains=goComment,goFunctionTagLine,OperatorChars,goContainer,goType,goNestedInterfaceType
  22. syn match goTypeDecl /\<type\>/ nextgroup=goNewDeclType,goTypeRegion skipwhite skipnl
  23. syn region goTypeRegion matchgroup=goContainer start=/(/ end=/)/ contains=@validTypeContains fold contained
  24. syn region goDeclStructRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validStructContains fold contained
  25. syn region goDeclInterfaceRegion matchgroup=goContainer start=/{/ end=/}/ contains=@validInterfaceContains fold contained
  26. syn match goNestedInterfaceType /\w\+/ contained
  27. " I think I hate this
  28. syn cluster goDeclTypeContains contains=goDeclTypeNS,goDeclTypeType,goDeclTypeMapType,goDeclTypeMap,ContainerChars,OperatorChars,goDeclaration,goDeclStruct,goDeclInterface
  29. " Match \w+\.\w+ but only highlight lone \w+ or (?>\.)\w+
  30. syn match goDeclTypeW /\(\[.*\]\|\*\)*\(\w\+\.\)\?\w\+\(\[.*\]\S\+\)\?/ contains=@goDeclTypeContains skipwhite contained
  31. " this is actually horribly broken for nested maps but appears to work.. 🤷
  32. syn match goDeclTypeType /\w\+/ contains=@goNumber nextgroup=goDeclTypeMap skipwhite contained
  33. syn region goDeclTypeMap matchgroup=goContainer start=/\[/ end=/\]/ contains=goDeclTypeW,ContainerChars nextgroup=goDeclTypeW skipwhite contained
  34. syn match goDeclTypeNS /\w\+\(\.\)\@1=/ skipwhite contained
  35. syn match goDeclTypeField /\w\+/ nextgroup=goDeclTypeW skipwhite contained
  36. syn match goNewDeclType /\w\+\(\s\([\*\[\] ]\)*\<\(struct\|interface\)\>\)\@=/ nextgroup=goDeclStruct,goDeclInterface skipwhite contained
  37. syn match goDeclStruct /\<struct\>/ nextgroup=goDeclStructRegion skipwhite skipnl
  38. syn match goDeclInterface /\<interface\>/ nextgroup=goDeclInterfaceRegion skipwhite skipnl
  39. syn match goVarVar /[^, ]\+/ nextgroup=goVarSep,goDeclTypeW skipwhite contained
  40. syn match goVarSep /,/ nextgroup=goVarVar skipwhite contained
  41. syn keyword goVarDecl var nextgroup=goVarVar skipwhite
  42. endif
  43. if !exists("g:go_highlight_functions")
  44. let g:go_highlight_functions = 0
  45. endif
  46. if g:go_highlight_functions != 0
  47. syn clear goFunctionCall
  48. syn clear goFunction
  49. syn clear goReceiverType
  50. syn match goFunctionCall /\(\.\)\@1<!\w\+\((\)\@1=/
  51. syn match goFunctionTagLine /\w\+(.*)\s*\((.*)\|\S\+\)\?/ nextgroup=goFunction contains=goFunction,goDeclaration,goFunctionParamRegion,goFunctionReturnRegion,goFunctionReturn,OperatorChars,ContainerChars,goComment contained
  52. " This works but much like everything else, it is quite fragile. It doesn't
  53. " handle inline interfaces or structs (but should it, really?). Though, that
  54. " is probably more because of the terrible goDeclTypeW.. who knows...
  55. " Whatever.. it seems to fit 98% of my use cases
  56. syn match listOfVars /\(\w\+, \)*\w\+ / contained
  57. syn match listOfTypes /\(\S\+\ze[,)]\)\+/ contains=goDeclTypeW,ContainerChars contained
  58. syn match listOfVars /\(, \|(\)\@<=\w\+\(\(, \w\+\)*, \w\+ \)\@=/ contained
  59. syn match goFunctionReturn /[^{, ]\+/ contains=goDeclaration,goDeclTypeW skipwhite contained
  60. syn region goFunctionParamRegion matchgroup=goContainer start=/(/ end=/)/ contains=goDeclaration,listOfTypes,listOfVars,ContainerChars,OperatorChars nextgroup=goFunctionReturn,goFunctionReturnRegion skipwhite contained
  61. syn region goFunctionReturnRegion matchgroup=goContainer start=/(/ end=/)/ contains=goDeclaration,listOfTypes,listOfVars,ContainerChars,OperatorChars skipwhite contained
  62. syn match goFunction /\w\+\((\)\@1=/ nextgroup=goFunctionParamRegion skipwhite contained
  63. syn match goDeclaration /\<func\>/ nextgroup=goReceiverRegion,goFunction,goFunctionParamRegion skipwhite skipnl
  64. " Use the space between func and ( to determine if the next group is a
  65. " receiver or an inlined function
  66. syn region goReceiverRegion matchgroup=goContainer start=/ (/ end=/)/ contains=goReceiver nextgroup=goFunction skipwhite contained
  67. syn match goReceiver /\(\w\|[ *]\)\+/ contains=goReceiverVar,goPointerOperator skipwhite skipnl contained
  68. syn match goReceiverVar /\w\+/ nextgroup=goPointerOperator,goDeclTypeW skipwhite skipnl contained
  69. syn match goPointerOperator /\*/ nextgroup=goDeclTypeW skipwhite skipnl contained
  70. endif
  71. if !exists("g:go_highlight_methods")
  72. let g:go_highlight_methods = 0
  73. endif
  74. if g:go_highlight_methods != 0
  75. syn clear goMethodCall
  76. syn match goMethodCall /\(\.\)\@1<=\w\+\((\)\@1=/
  77. endif
  78. " Order is important, so redefine
  79. syn match goBuiltins /\<\v(append|cap|close|complex|copy|delete|imag|len)\ze\(/
  80. syn match goBuiltins /\<\v(make|new|panic|print|println|real|recover)\ze\(/
  81. hi link goPointerOperator Operator
  82. hi link goDeclTypeFieldPointerOp Operator
  83. hi link goTypeConstructor Type
  84. hi link goTypeOpen goContainer
  85. hi link goDeclTypeFieldType Type
  86. hi link goNewDeclType Type
  87. hi link goDeclTypeType Type
  88. hi link goTypeVar Type
  89. hi link goNestedInterfaceType Type
  90. hi link goVarDecl goDeclaration
  91. hi link goVarSep Operator
  92. hi link goDeclInterface goDeclaration
  93. hi link goDeclStruct goDeclaration
  94. hi link goFunction Function
  95. hi link goMethodCall Function
  96. hi link goFunctionCall Function
  97. hi link goContainer ContainerChars