Skip to content

Develop -> Master #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Jun 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ea58033
a solution for 486 (#488)
bounceme Jun 17, 2016
52e8f90
incorrect change in cursor pos (#489)
bounceme Jun 17, 2016
939f478
Improvements to destructuring
amadeus Jun 14, 2016
47951ee
Refinements to destructuring
amadeus Jun 14, 2016
afe6179
Improved array destructuring
amadeus Jun 14, 2016
9d816e3
Fixes to array destructuring
amadeus Jun 14, 2016
7d41c3c
Improvements to Spread and Rest
amadeus Jun 18, 2016
0e08785
Merge pull request #494 from pangloss/improve-destructuring
amadeus Jun 18, 2016
6bb633f
comment misalignment (#495)
bounceme Jun 18, 2016
420f98c
let a continuation be determined with block close (#496)
bounceme Jun 18, 2016
0115077
accurate switch indenting (#499)
bounceme Jun 20, 2016
82fb8b9
Adding some basic Flow support
amadeus Jun 11, 2016
ef37a14
Adds a ton of support for various parts of jsFlow
amadeus Jun 12, 2016
926b7f9
Adding < and > to jsFlowNoise
amadeus Jun 12, 2016
5f839a2
Removing jsFlow from jsAll cluster
amadeus Jun 18, 2016
9d0bea5
Masking Flow support behind a global var
amadeus Jun 18, 2016
752cee2
Moving jsdoc support into a separate file.
amadeus Jun 18, 2016
b6eccf9
Adding NGDoc support
amadeus Jun 18, 2016
be52070
Using runtime over syntax include
amadeus Jun 18, 2016
af791ed
Adding object key flow support
amadeus Jun 19, 2016
37bfc8c
Plugin usage tweaks
amadeus Jun 20, 2016
5cefcff
Unpluralizing files and variable names
amadeus Jun 20, 2016
8deb698
Merge pull request #470 from pangloss/js-flow-support
amadeus Jun 20, 2016
4eab47d
First pass at improved export support
amadeus Jun 19, 2016
57f5013
Merge pull request #500 from pangloss/improved-exports
amadeus Jun 20, 2016
fb1c662
Support destructuring values following assignment
amadeus Jun 20, 2016
8a972d3
Whitespace
amadeus Jun 20, 2016
5b42338
Fixes for Flow on Classes
amadeus Jun 20, 2016
7541e02
Merge pull request #503 from pangloss/misc-fixes
amadeus Jun 21, 2016
3306f63
jsComment updates
amadeus Jun 21, 2016
f90113a
Merge pull request #504 from pangloss/jscomment-tweaks
amadeus Jun 21, 2016
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
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,37 @@ And install it:

## Configuration Variables

The following variables control certain syntax highlighting features. You can
add them to your `.vimrc` to enable/disable their features.
The following variables control certain syntax highlighting plugins. You can
add them to your `.vimrc` to enable their features.

-----------------

```
let g:javascript_plugin_jsdoc = 1
```

Enables syntax highlighting for [JSDocs](http://usejsdoc.org/).

Default Value: 0

-----------------

```
let g:javascript_enable_domhtmlcss = 1
let g:javascript_plugin_ngdoc = 1
```

Enables HTML/CSS syntax highlighting in your JavaScript file.
Enables some additional syntax highlighting for NGDocs. Requires JSDoc plugin
to be enabled as well.

Default Value: 0

-----------------

```
let g:javascript_ignore_javaScriptdoc = 1
let g:javascript_plugin_flow = 1
```

Disables JSDoc syntax highlighting
Enables syntax highlighting for [Flow](https://flowtype.org/).

Default Value: 0

Expand Down
36 changes: 36 additions & 0 deletions extras/flow.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
syntax region jsFlowTypeStatement start=/type/ end=/=/ oneline skipwhite skipempty nextgroup=jsFlowTypeObject
syntax region jsFlowDeclareBlock start=/declare/ end=/[;\n]/ oneline contains=jsFlow,jsFlowDeclareKeyword,jsFlowStorageClass
syntax region jsFlow start=/:/ end=/\%(\%([),=;\n]\|{\%(.*}\)\@!\|\%({.*}\)\@<=\s*{\)\@=\|void\)/ contains=@jsFlowCluster oneline skipwhite skipempty nextgroup=jsFuncBlock
syntax region jsFlowReturn contained start=/:/ end=/\%(\S\s*\%({\)\@=\|\n\)/ contains=@jsFlowCluster oneline skipwhite skipempty nextgroup=jsFuncBlock keepend
syntax region jsFlowTypeObject contained start=/{/ end=/}/ skipwhite skipempty nextgroup=jsFunctionBlock extend
syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ oneline contains=@jsFlowCluster
syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ oneline contains=@jsFlowCluster
syntax keyword jsFlowDeclareKeyword contained declare
syntax keyword jsFlowType contained boolean number string null void any mixed JSON array function object Array
syntax match jsFlowClassProperty contained /\<[0-9a-zA-Z_$]*\>:\@=/ skipwhite skipempty nextgroup=jsFlow
syntax match jsFlowNoise contained /[:;,<>]/
syntax cluster jsFlowCluster contains=jsFlowType,jsFlowArray,jsFlowObject,jsFlowNoise
syntax keyword jsFlowStorageClass contained const var let
syntax region jsFlowParenRegion contained start=/:\s*(/ end=/)\%(\s*:\)\@=/ oneline contains=@jsFlowCluster skipwhite skipempty nextgroup=jsObjectValue
syntax region jsFlowClass contained matchgroup=jsFlowNoise start=/</ end=/>/ oneline contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassBlock

if version >= 508 || !exists("did_javascript_syn_inits")
if version < 508
let did_javascript_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink jsFlow PreProc
HiLink jsFlowReturn PreProc
HiLink jsFlowArray PreProc
HiLink jsFlowDeclareBlock PreProc
HiLink jsFlowObject PreProc
HiLink jsFlowParenRegion PreProc
HiLink jsFlowClass PreProc
HiLink jsFlowClassProperty jsClassProperty
HiLink jsFlowType Type
HiLink jsFlowDeclareKeyword Type
HiLink jsFlowNoise Noise
delcommand HiLink
endif
39 changes: 39 additions & 0 deletions extras/jsdoc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"" syntax coloring for javadoc comments (HTML)
syntax region jsComment matchgroup=jsComment start="/\*\s*" end="\*/" contains=jsDocTags,jsCommentTodo,jsCvsTag,@jsHtml,@Spell fold

" tags containing a param
syntax match jsDocTags contained "@\(alias\|api\|augments\|borrows\|class\|constructs\|default\|defaultvalue\|emits\|exception\|exports\|extends\|fires\|kind\|link\|listens\|member\|member[oO]f\|mixes\|module\|name\|namespace\|requires\|template\|throws\|var\|variation\|version\)\>" skipwhite nextgroup=jsDocParam
" tags containing type and param
syntax match jsDocTags contained "@\(arg\|argument\|cfg\|param\|property\|prop\)\>" skipwhite nextgroup=jsDocType
" tags containing type but no param
syntax match jsDocTags contained "@\(callback\|define\|enum\|external\|implements\|this\|type\|typedef\|return\|returns\)\>" skipwhite nextgroup=jsDocTypeNoParam
" tags containing references
syntax match jsDocTags contained "@\(lends\|see\|tutorial\)\>" skipwhite nextgroup=jsDocSeeTag
" other tags (no extra syntax)
syntax match jsDocTags contained "@\(abstract\|access\|accessor\|author\|classdesc\|constant\|const\|constructor\|copyright\|deprecated\|desc\|description\|dict\|event\|example\|file\|file[oO]verview\|final\|function\|global\|ignore\|inheritDoc\|inner\|instance\|interface\|license\|localdoc\|method\|mixin\|nosideeffects\|override\|overview\|preserve\|private\|protected\|public\|readonly\|since\|static\|struct\|todo\|summary\|undocumented\|virtual\)\>"

syntax region jsDocType contained matchgroup=jsDocTypeBrackets start="{" end="}" contains=jsDocTypeRecord oneline skipwhite nextgroup=jsDocParam
syntax match jsDocType contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" skipwhite nextgroup=jsDocParam
syntax region jsDocTypeRecord contained start=/{/ end=/}/ contains=jsDocTypeRecord extend
syntax region jsDocTypeRecord contained start=/\[/ end=/\]/ contains=jsDocTypeRecord extend
syntax region jsDocTypeNoParam contained start="{" end="}" oneline
syntax match jsDocTypeNoParam contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+"
syntax match jsDocParam contained "\%(#\|\$\|-\|'\|\"\|{.\{-}}\|\w\|\.\|:\|\/\|\[.{-}]\|=\)\+"
syntax region jsDocSeeTag contained matchgroup=jsDocSeeTag start="{" end="}" contains=jsDocTags

if version >= 508 || !exists("did_javascript_syn_inits")
if version < 508
let did_javascript_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink jsDocTags Special
HiLink jsDocSeeTag Function
HiLink jsDocType Type
HiLink jsDocTypeBrackets jsDocType
HiLink jsDocTypeRecord jsDocType
HiLink jsDocTypeNoParam Type
HiLink jsDocParam Label
delcommand HiLink
endif
3 changes: 3 additions & 0 deletions extras/ngdoc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
syntax match jsDocTags contained /@\(link\|method[oO]f\|ngdoc\|ng[iI]nject\|restrict\)/ nextgroup=jsDocParam skipwhite
syntax match jsDocType contained "\%(#\|\$\|\w\|\"\|-\|\.\|:\|\/\)\+" nextgroup=jsDocParam skipwhite
syntax match jsDocParam contained "\%(#\|\$\|\w\|\"\|-\|\.\|:\|{\|}\|\/\|\[\|]\|=\)\+"
139 changes: 73 additions & 66 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ setlocal nosmartindent
setlocal indentexpr=GetJavascriptIndent()
setlocal formatexpr=Fixedgq(v:lnum,v:count)
setlocal indentkeys=0{,0},0),0],0\,*<Return>,:,!^F,o,O,e
setlocal cinoptions+=j1,J1
setlocal cinoptions+=j1,J1,c1

" Only define the function once.
if exists("*GetJavascriptIndent")
Expand Down Expand Up @@ -140,7 +140,7 @@ function s:GetMSL(lnum, in_one_line_scope)
" Start on the line we're at and use its indent.
let msl = a:lnum
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
while lnum > 0
while lnum > 0 && !s:Match(msl,s:line_pre . '[])}]')
" If we have a continuation line, or we're in a string, use line as MSL.
" Otherwise, terminate search as we have found our MSL already.
let line = getline(lnum)
Expand Down Expand Up @@ -312,6 +312,7 @@ function GetJavascriptIndent()
" 3.1. Setup {{{1
" ----------
" Set up variables for restoring position in file. Could use v:lnum here.
" Avoid use of line('.')/col('.') type functions as the curpos can change
let vcol = col('.')

" 3.2. Work on the current line {{{1
Expand All @@ -334,7 +335,7 @@ function GetJavascriptIndent()
if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1)
return cindent(v:lnum)
endif

" single opening bracket will assume you want a c style of indenting
if s:Match(v:lnum, s:line_pre . '{' . s:line_term) && !s:Match(lnum,s:block_regex) &&
\ !s:Match(lnum,s:comma_last)
Expand All @@ -343,7 +344,11 @@ function GetJavascriptIndent()

" cindent each line which has a switch label
if (line =~ s:expr_case)
return cindent(v:lnum)
let s:cpo_switch = &cpo
set cpo+=%
let ind = cindent(v:lnum)
let &cpo = s:cpo_switch
return ind
endif

" If we got a closing bracket on an empty line, find its match and indent
Expand All @@ -359,8 +364,8 @@ function GetJavascriptIndent()
continue
end
if parlnum > 0
let ind = s:InMultiVarStatement(parlnum, 0, 0)|| s:LineHasOpeningBrackets(parlnum) !~ '2'
\ ? indent(parlnum) : indent(s:GetMSL(parlnum, 0))
let ind = s:InMultiVarStatement(parlnum, 0, 0)|| s:LineHasOpeningBrackets(parlnum) !~ '2' ?
\ indent(parlnum) : indent(s:GetMSL(parlnum, 0))
endif
endwhile
return ind
Expand All @@ -369,7 +374,8 @@ function GetJavascriptIndent()

" If line starts with an operator...
if (line =~ s:operator_first)
if (s:Match(lnum, s:operator_first) || s:Match(lnum, s:line_pre . '[])}]'))
if (s:Match(lnum, s:operator_first) || (s:Match(lnum, s:line_pre . '[])}]') &&
\ !(s:Match(v:lnum,s:line_pre . '\.') && s:Match(lnum, ')' . s:line_term))))
" and so does previous line, don't indent
return indent(lnum)
end
Expand Down Expand Up @@ -411,7 +417,7 @@ function GetJavascriptIndent()
" If the line is empty and the previous nonblank line was a multi-line
" comment, use that comment's indent. Deduct one char to account for the
" space in ' */'.
if line =~ '^\s*$' && getline(prevline) !~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@<!\*\/' &&
if line =~ '^\s*$' && getline(prevline) =~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@<!\*\/' &&
\ s:IsInComment(prevline, 1)
return indent(prevline) - 1
endif
Expand All @@ -428,16 +434,16 @@ function GetJavascriptIndent()
return 0
endif

" foo('foo',
" bar('bar', function() {
" hi();
" })
" );
" foo('foo',
" bar('bar', function() {
" hi();
" })
" );

" function (a, b, c, d,
" e, f, g) {
" console.log('inner');
" }
" function (a, b, c, d,
" e, f, g) {
" console.log('inner');
" }
" If the previous line ended with a block opening, add a level of indent.
if s:Match(lnum, s:block_regex)
return s:InMultiVarStatement(lnum, 0, 0) || s:LineHasOpeningBrackets(lnum) !~ '2' ?
Expand All @@ -449,15 +455,16 @@ function GetJavascriptIndent()
let ind = indent(lnum)
" If the previous line contained an opening bracket, and we are still in it,
" add indent depending on the bracket type.
if s:Match(lnum, '\%([[({]\)\|\%([^\t \])}][})\]]\)')
if s:Match(lnum, '[[({})\]]')
let counts = s:LineHasOpeningBrackets(lnum)
if counts =~ '2'
call cursor(lnum,matchend(s:RemoveTrailingComments(line), '.\+\zs[])}]'))
call cursor(lnum,matchend(s:RemoveTrailingComments(line), '.*\zs[])}]'))
while s:lookForParens('(\|{\|\[', ')\|}\|\]', 'bW', 0) == lnum
call cursor(lnum, matchend(s:RemoveTrailingComments(strpart(line,0,col('.'))), '.*\zs[])}]'))
endwhile
if line('.') < lnum && !s:InMultiVarStatement(line('.'),0,0)
return indent(s:GetMSL(line('.'), 0))
let cur = line('.')
if cur < lnum && !s:InMultiVarStatement(cur,0,0)
return indent(s:GetMSL(cur, 0))
end
elseif counts =~ '1' || s:Onescope(lnum)
return ind + s:sw()
Expand Down Expand Up @@ -500,64 +507,64 @@ let &cpo = s:cpo_save
unlet s:cpo_save
" gq{{{2
function! Fixedgq(lnum, count)
let l:tw = &tw ? &tw : 80;
let l:tw = &tw ? &tw : 80;

let l:count = a:count
let l:first_char = indent(a:lnum) + 1
let l:count = a:count
let l:first_char = indent(a:lnum) + 1

if mode() == 'i' " gq was not pressed, but tw was set
return 1
endif
if mode() == 'i' " gq was not pressed, but tw was set
return 1
endif

" This gq is only meant to do code with strings, not comments
if s:IsInComment(a:lnum, l:first_char)
return 1
endif
" This gq is only meant to do code with strings, not comments
if s:IsInComment(a:lnum, l:first_char)
return 1
endif

if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
return 1
endif
if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
return 1
endif

" Put all the lines on one line and do normal spliting after that
if l:count > 1
while l:count > 1
let l:count -= 1
normal J
endwhile
endif
" Put all the lines on one line and do normal spliting after that
if l:count > 1
while l:count > 1
let l:count -= 1
normal J
endwhile
endif

let l:winview = winsaveview()
let l:winview = winsaveview()

call cursor(a:lnum, l:tw + 1)
let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum)
call cursor(a:lnum, l:tw + 1)
let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum)
call cursor(a:lnum, l:tw + 1)
let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum)
call cursor(a:lnum, l:tw + 1)
let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum)

" No need for special treatment, normal gq handles edgecases better
if breakpoint[1] == orig_breakpoint[1]
call winrestview(l:winview)
return 1
endif
" No need for special treatment, normal gq handles edgecases better
if breakpoint[1] == orig_breakpoint[1]
call winrestview(l:winview)
return 1
endif

" Try breaking after string
if breakpoint[1] <= indent(a:lnum)
call cursor(a:lnum, l:tw + 1)
let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum)
endif
" Try breaking after string
if breakpoint[1] <= indent(a:lnum)
call cursor(a:lnum, l:tw + 1)
let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum)
endif


if breakpoint[1] != 0
call feedkeys("r\<CR>")
else
let l:count = l:count - 1
endif
if breakpoint[1] != 0
call feedkeys("r\<CR>")
else
let l:count = l:count - 1
endif

" run gq on new lines
if l:count == 1
call feedkeys("gqq")
endif
" run gq on new lines
if l:count == 1
call feedkeys("gqq")
endif

return 0
return 0
endfunction
"}}}
" vim: foldmethod=marker:foldlevel=1
Loading