From a92317c5562c281fb6a5bbe6f872854b6b242094 Mon Sep 17 00:00:00 2001 From: Karl Fleischmann Date: Sun, 10 Jun 2018 13:54:14 +0200 Subject: [PATCH 1/3] Add syntax highlighting for flow comment types - Match comment type include and annotation region. - Allow FlowType syntax inside of these regions. - Highlight single colon to represent special meaning (kept verbosely in type annotation). --- after/syntax/javascript.vim | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 after/syntax/javascript.vim diff --git a/after/syntax/javascript.vim b/after/syntax/javascript.vim new file mode 100644 index 0000000..7d4411e --- /dev/null +++ b/after/syntax/javascript.vim @@ -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,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 From 971f68dd3a71b2f4ae257822a448a325dd7684a0 Mon Sep 17 00:00:00 2001 From: Karl Fleischmann Date: Wed, 13 Jun 2018 22:06:57 +0200 Subject: [PATCH 2/3] Enable function return flow annotations This commit adds support for flow annotations to statements as the following: ``` function test() /*: $await */ {} ``` --- after/syntax/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/after/syntax/javascript.vim b/after/syntax/javascript.vim index 7d4411e..2cd0bc3 100644 --- a/after/syntax/javascript.vim +++ b/after/syntax/javascript.vim @@ -22,7 +22,7 @@ syntax region flowTypeComment matchgroup=jsComment \ start="\/\*\%(::\?\|flow-include\)\@=" end="\*\/" \ contains=jsFlowArgumentDef,jsFlowClassGroup,jsFlowType, \ jsFlowTypeStatement,flowTypeCommentKeyword - \ containedin=js.*Block,jsClassDefinition,jsFuncArgs + \ containedin=js.*Block,jsClassDefinition,jsCommentFunction,jsFuncArgs " highlight the appropriate syntax elements accordingly highlight default link flowAnnotationFlag Special From 3244412d483f60cb8976d92c0800aa63b61855ae Mon Sep 17 00:00:00 2001 From: Karl Fleischmann Date: Thu, 14 Jun 2018 09:32:37 +0200 Subject: [PATCH 3/3] Bypass comment leader on type annotations Adding `f:/*::` skips comment continuations on new lines, when in a type annotation comment. This needs to be prepended onto the existing comments, to remain the behavior of javascript's block comments. --- after/ftplugin/javascript.vim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/after/ftplugin/javascript.vim b/after/ftplugin/javascript.vim index ecc25bc..b142b3a 100644 --- a/after/ftplugin/javascript.vim +++ b/after/ftplugin/javascript.vim @@ -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