Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Add syntax highlighting for flow comment types #77

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions after/ftplugin/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ endif
if exists('&omnifunc') && g:flow#omnifunc
setl omnifunc=flowcomplete#Complete
endif

" Setup `/*::` to not be continued as a javascript block comment
" - Prepend the currently setup `comments` options, so that '/*' is
" still evaluated as before
let &comments = "f:/*::," . &comments
33 changes: 33 additions & 0 deletions after/syntax/javascript.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
if exists("b:current_syntax")
let s:current_syntax=b:current_syntax
unlet b:current_syntax
endif

" classify flow flag
syntax match flowAnnotationFlag "@flow" contained
\ containedin=jsComment

" classify keywords, that indicate flow comment include
syntax match flowTypeCommentKeyword "::"
syntax match flowTypeCommentKeyword "flow-include"

" classify flow comment include and type annotation regions
" - \/\* - (= "/*") begin of a js block comment
" - \%(::\?\|flow-include\) - check for keywords to begin type comments
" - \@= - check but don't include in the matched
" group
" - \*\/ - (= "*/") end of a js block comment
syntax region flowTypeComment matchgroup=jsComment
\ transparent fold keepend
\ start="\/\*\%(::\?\|flow-include\)\@=" end="\*\/"
\ contains=jsFlowArgumentDef,jsFlowClassGroup,jsFlowType,
\ jsFlowTypeStatement,flowTypeCommentKeyword
\ containedin=js.*Block,jsClassDefinition,jsCommentFunction,jsFuncArgs

" highlight the appropriate syntax elements accordingly
highlight default link flowAnnotationFlag Special
highlight default link flowTypeCommentKeyword Comment

if exists("s:current_syntax")
let b:current_syntax=s:current_syntax
endif