Skip to content

Commit

Permalink
improvements and fixes to build constraint highlighting
Browse files Browse the repository at this point in the history
add missing architectures

remove multiline comment pattern for build constraints (build
constraints must always be line comments)

add a required trailing space to the build constraint region start pattern
this avoids highlighting, e.g., // +buildwindows

add a syntax match for package documentation comments that disables
highlighting build constraints when they will be interpreted as package
documentation instead

in build constraints, only use the comment color to highlight the
leading //
  • Loading branch information
chrisnc committed Nov 1, 2015
1 parent d25e1af commit 7b7a260
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions syntax/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,36 @@ hi def link goStructDef Function

" Build Constraints
if g:go_highlight_build_constraints != 0
syn keyword goBuildOs contained ignore cgo android darwin dragonfly freebsd linux nacl netbsd openbsd plan9 solaris windows
syn keyword goBuildArch contained 386 amd64 amd64p32 arm
syn match goBuildDirective display contained "+build"
syn region goBuildComment start="//\s*+build" end="$" contains=goBuildDirective,goBuildOs,goBuildArch
syn region goBuildComment start="/\*\s*+build" end="\*/" contains=goBuildDirective,goBuildOs,goBuildArch
syn match goBuildKeyword display contained "+build"
" Highlight the known values of GOOS, GOARCH, and other +build options.
syn keyword goBuildDirectives contained
\ android darwin dragonfly freebsd linux nacl netbsd openbsd plan9
\ solaris windows 386 amd64 amd64p32 arm arm64 ppc64 ppc64le
\ cgo ignore

" Other words in the build directive are build tags not listed above, so
" avoid highlighting them as comments by using a matchgroup just for the
" start of the comment.
" The rs=s+2 option lets the \s*+build portion be part of the inner region
" instead of the matchgroup so it will be highlighted as a goBuildKeyword.
syn region goBuildComment matchgroup=goBuildCommentStart
\ start="//\s*+build\s"rs=s+2 end="$"
\ contains=goBuildKeyword,goBuildDirectives
hi def link goBuildCommentStart Comment
hi def link goBuildDirectives Type
hi def link goBuildKeyword PreProc

" One or more line comments that are followed immediately by a "package"
" declaration are treated like package documentation, so these must be
" matched as comments to avoid looking like working build constraints.
" The he, me, and re options let the "package" itself be highlighted by
" the usual rules.
syn region goPackageComment start=/\v(\/\/.*\n)+\s*package/
\ end=/\v\n\s*package/he=e-7,me=e-7,re=e-7
\ contains=@goCommentGroup,@Spell
hi def link goPackageComment Comment
endif

hi def link goBuildComment Comment
hi def link goBuildOs Type
hi def link goBuildArch Type
hi def link goBuildDirective PreProc


" Search backwards for a global declaration to start processing the syntax.
"syn sync match goSync grouphere NONE /^\(const\|var\|type\|func\)\>/
Expand Down

0 comments on commit 7b7a260

Please sign in to comment.