Merge c2cda44ef5
into c4fbfe8aa8
This commit is contained in:
commit
f41ccd5995
1
my_configs.vim
Normal file
1
my_configs.vim
Normal file
|
@ -0,0 +1 @@
|
|||
set number
|
1
sources_non_forked/grep
Submodule
1
sources_non_forked/grep
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit ac33b4e2e0cde6857d867dfa6a0bfb67692b24f1
|
13
sources_non_forked/vim-javascript/CONTRIBUTING.md
Normal file
13
sources_non_forked/vim-javascript/CONTRIBUTING.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
## Contributing
|
||||
|
||||
This project uses the [git
|
||||
flow](http://nvie.com/posts/a-successful-git-branching-model/) model for
|
||||
development. There's [a handy git module for git
|
||||
flow](//github.com/nvie/gitflow). If you'd like to be added as a contributor,
|
||||
the price of admission is 1 pull request. Please follow the general code style
|
||||
guides (read the code) and in your pull request explain the reason for the
|
||||
proposed change and how it is valuable.
|
||||
|
||||
## Bug report
|
||||
|
||||
Report a bug on [GitHub Issues](https://github.com/pangloss/vim-javascript/issues).
|
82
sources_non_forked/vim-javascript/README.md
Normal file
82
sources_non_forked/vim-javascript/README.md
Normal file
|
@ -0,0 +1,82 @@
|
|||
# vim-javascript v0.9.0
|
||||
|
||||
JavaScript bundle for vim, this bundle provides syntax and indent plugins.
|
||||
|
||||
## A Quick Note on Regexes
|
||||
|
||||
Vim 7.4 was released recently, and unfortunately broke how this plugin
|
||||
handles regexes. There was no real easy way for us to fix this unless we
|
||||
completely rewrote how regexes work.
|
||||
|
||||
Good News: There was a recent update to Vim 7.4 that fixes this issue.
|
||||
|
||||
Make sure you are at least using Vim 7.4, with patches 1-7.
|
||||
|
||||
If you are stuck on an older version of Vim 7.4 with no way to update,
|
||||
then simply perform the following commands to fix your current buffer:
|
||||
|
||||
```
|
||||
:set regexpengine=1
|
||||
:syntax enable
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
### Install with [Vundle](https://github.com/gmarik/vundle)
|
||||
|
||||
Add to vimrc:
|
||||
|
||||
Bundle "pangloss/vim-javascript"
|
||||
|
||||
And install it:
|
||||
|
||||
:so ~/.vimrc
|
||||
:BundleInstall
|
||||
|
||||
### Install with [pathogen](https://github.com/tpope/vim-pathogen)
|
||||
|
||||
cd ~/.vim/bundle
|
||||
git clone https://github.com/pangloss/vim-javascript.git
|
||||
|
||||
## Configuration
|
||||
|
||||
The following variables control certain syntax highlighting features. You can
|
||||
add them to your `.vimrc` to enable/disable their features.
|
||||
|
||||
#### javascript_enable_domhtmlcss
|
||||
|
||||
Enables HTML/CSS syntax highlighting in your JavaScript file.
|
||||
|
||||
Default Value: 0
|
||||
|
||||
#### b:javascript_fold
|
||||
|
||||
Enables JavaScript code folding.
|
||||
|
||||
Default Value: 1
|
||||
|
||||
#### g:javascript_conceal
|
||||
|
||||
Enables concealing characters. For example, `function` is replaced with `ƒ`
|
||||
|
||||
Default Value: 0
|
||||
|
||||
#### javascript_ignore_javaScriptdoc
|
||||
|
||||
Disables JSDoc syntax highlighting
|
||||
|
||||
Default Value: 0
|
||||
|
||||
## Contributing
|
||||
|
||||
This project uses the [git
|
||||
flow](http://nvie.com/posts/a-successful-git-branching-model/) model for
|
||||
development. There's [a handy git module for git
|
||||
flow](//github.com/nvie/gitflow). If you'd like to be added as a contributor,
|
||||
the price of admission is 1 pull request. Please follow the general code style
|
||||
guides (read the code) and in your pull request explain the reason for the
|
||||
proposed change and how it is valuable.
|
||||
|
||||
## Bug report
|
||||
|
||||
Report a bug on [GitHub Issues](https://github.com/pangloss/vim-javascript/issues).
|
8
sources_non_forked/vim-javascript/extras/ctags
Normal file
8
sources_non_forked/vim-javascript/extras/ctags
Normal file
|
@ -0,0 +1,8 @@
|
|||
--langdef=js
|
||||
--langmap=js:.js
|
||||
--regex-js=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\{/\1/,object/
|
||||
--regex-js=/([A-Za-z0-9._$()]+)[ \t]*[:=][ \t]*function[ \t]*\(/\1/,function/
|
||||
--regex-js=/function[ \t]+([A-Za-z0-9._$]+)[ \t]*([^)])/\1/,function/
|
||||
--regex-js=/([A-Za-z0-9._$]+)[ \t]*[:=][ \t]*\[/\1/,array/
|
||||
--regex-js=/([^= ]+)[ \t]*=[ \t]*[^"]'[^']*/\1/,string/
|
||||
--regex-js=/([^= ]+)[ \t]*=[ \t]*[^']"[^"]*/\1/,string/
|
10
sources_non_forked/vim-javascript/ftdetect/javascript.vim
Normal file
10
sources_non_forked/vim-javascript/ftdetect/javascript.vim
Normal file
|
@ -0,0 +1,10 @@
|
|||
au BufNewFile,BufRead *.js setf javascript
|
||||
au BufNewFile,BufRead *.jsm setf javascript
|
||||
au BufNewFile,BufRead Jakefile setf javascript
|
||||
|
||||
fun! s:SelectJavascript()
|
||||
if getline(1) =~# '^#!.*/bin/env\s\+node\>'
|
||||
set ft=javascript
|
||||
endif
|
||||
endfun
|
||||
au BufNewFile,BufRead * call s:SelectJavascript()
|
439
sources_non_forked/vim-javascript/indent/javascript.vim
Normal file
439
sources_non_forked/vim-javascript/indent/javascript.vim
Normal file
|
@ -0,0 +1,439 @@
|
|||
" Vim indent file
|
||||
" Language: Javascript
|
||||
" Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org
|
||||
|
||||
" 0. Initialization {{{1
|
||||
" =================
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
if exists("b:did_indent")
|
||||
finish
|
||||
endif
|
||||
let b:did_indent = 1
|
||||
|
||||
setlocal nosmartindent
|
||||
|
||||
" Now, set up our indentation expression and keys that trigger it.
|
||||
setlocal indentexpr=GetJavascriptIndent()
|
||||
setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
|
||||
|
||||
" Only define the function once.
|
||||
if exists("*GetJavascriptIndent")
|
||||
finish
|
||||
endif
|
||||
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" 1. Variables {{{1
|
||||
" ============
|
||||
|
||||
let s:js_keywords = '^\s*\(break\|case\|catch\|continue\|debugger\|default\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)'
|
||||
|
||||
" Regex of syntax group names that are or delimit string or are comments.
|
||||
let s:syng_strcom = 'string\|regex\|comment\c'
|
||||
|
||||
" Regex of syntax group names that are strings.
|
||||
let s:syng_string = 'regex\c'
|
||||
|
||||
" Regex of syntax group names that are strings or documentation.
|
||||
let s:syng_multiline = 'comment\c'
|
||||
|
||||
" Regex of syntax group names that are line comment.
|
||||
let s:syng_linecom = 'linecomment\c'
|
||||
|
||||
" Expression used to check whether we should skip a match with searchpair().
|
||||
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'"
|
||||
|
||||
let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
|
||||
|
||||
" Regex that defines continuation lines, not including (, {, or [.
|
||||
let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)' . s:line_term
|
||||
|
||||
" Regex that defines continuation lines.
|
||||
" TODO: this needs to deal with if ...: and so on
|
||||
let s:msl_regex = '\%([\\*+/.:([]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)' . s:line_term
|
||||
|
||||
let s:one_line_scope_regex = '\<\%(if\|else\|for\|while\)\>[^{;]*' . s:line_term
|
||||
|
||||
" Regex that defines blocks.
|
||||
let s:block_regex = '\%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
|
||||
|
||||
let s:var_stmt = '^\s*var'
|
||||
|
||||
let s:comma_first = '^\s*,'
|
||||
let s:comma_last = ',\s*$'
|
||||
|
||||
let s:ternary = '^\s\+[?|:]'
|
||||
let s:ternary_q = '^\s\+?'
|
||||
|
||||
" 2. Auxiliary Functions {{{1
|
||||
" ======================
|
||||
|
||||
" Check if the character at lnum:col is inside a string, comment, or is ascii.
|
||||
function s:IsInStringOrComment(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a string.
|
||||
function s:IsInString(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is inside a multi-line comment.
|
||||
function s:IsInMultilineComment(lnum, col)
|
||||
return !s:IsLineComment(a:lnum, a:col) && synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_multiline
|
||||
endfunction
|
||||
|
||||
" Check if the character at lnum:col is a line comment.
|
||||
function s:IsLineComment(lnum, col)
|
||||
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_linecom
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
|
||||
function s:PrevNonBlankNonString(lnum)
|
||||
let in_block = 0
|
||||
let lnum = prevnonblank(a:lnum)
|
||||
while lnum > 0
|
||||
" Go in and out of blocks comments as necessary.
|
||||
" If the line isn't empty (with opt. comment) or in a string, end search.
|
||||
let line = getline(lnum)
|
||||
if line =~ '/\*'
|
||||
if in_block
|
||||
let in_block = 0
|
||||
else
|
||||
break
|
||||
endif
|
||||
elseif !in_block && line =~ '\*/'
|
||||
let in_block = 1
|
||||
elseif !in_block && line !~ '^\s*\%(//\).*$' && !(s:IsInStringOrComment(lnum, 1) && s:IsInStringOrComment(lnum, strlen(line)))
|
||||
break
|
||||
endif
|
||||
let lnum = prevnonblank(lnum - 1)
|
||||
endwhile
|
||||
return lnum
|
||||
endfunction
|
||||
|
||||
" Find line above 'lnum' that started the continuation 'lnum' may be part of.
|
||||
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
|
||||
" 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)
|
||||
let col = match(line, s:msl_regex) + 1
|
||||
if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line))
|
||||
let msl = lnum
|
||||
else
|
||||
" Don't use lines that are part of a one line scope as msl unless the
|
||||
" flag in_one_line_scope is set to 1
|
||||
"
|
||||
if a:in_one_line_scope
|
||||
break
|
||||
end
|
||||
let msl_one_line = s:Match(lnum, s:one_line_scope_regex)
|
||||
if msl_one_line == 0
|
||||
break
|
||||
endif
|
||||
endif
|
||||
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
||||
endwhile
|
||||
return msl
|
||||
endfunction
|
||||
|
||||
function s:RemoveTrailingComments(content)
|
||||
let single = '\/\/\(.*\)\s*$'
|
||||
let multi = '\/\*\(.*\)\*\/\s*$'
|
||||
return substitute(substitute(a:content, single, '', ''), multi, '', '')
|
||||
endfunction
|
||||
|
||||
" Find if the string is inside var statement (but not the first string)
|
||||
function s:InMultiVarStatement(lnum)
|
||||
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
||||
|
||||
" let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name')
|
||||
|
||||
" loop through previous expressions to find a var statement
|
||||
while lnum > 0
|
||||
let line = getline(lnum)
|
||||
|
||||
" if the line is a js keyword
|
||||
if (line =~ s:js_keywords)
|
||||
" check if the line is a var stmt
|
||||
" if the line has a comma first or comma last then we can assume that we
|
||||
" are in a multiple var statement
|
||||
if (line =~ s:var_stmt)
|
||||
return lnum
|
||||
endif
|
||||
|
||||
" other js keywords, not a var
|
||||
return 0
|
||||
endif
|
||||
|
||||
let lnum = s:PrevNonBlankNonString(lnum - 1)
|
||||
endwhile
|
||||
|
||||
" beginning of program, not a var
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" Find line above with beginning of the var statement or returns 0 if it's not
|
||||
" this statement
|
||||
function s:GetVarIndent(lnum)
|
||||
let lvar = s:InMultiVarStatement(a:lnum)
|
||||
let prev_lnum = s:PrevNonBlankNonString(a:lnum - 1)
|
||||
|
||||
if lvar
|
||||
let line = s:RemoveTrailingComments(getline(prev_lnum))
|
||||
|
||||
" if the previous line doesn't end in a comma, return to regular indent
|
||||
if (line !~ s:comma_last)
|
||||
return indent(prev_lnum) - &sw
|
||||
else
|
||||
return indent(lvar) + &sw
|
||||
endif
|
||||
endif
|
||||
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
|
||||
" Check if line 'lnum' has more opening brackets than closing ones.
|
||||
function s:LineHasOpeningBrackets(lnum)
|
||||
let open_0 = 0
|
||||
let open_2 = 0
|
||||
let open_4 = 0
|
||||
let line = getline(a:lnum)
|
||||
let pos = match(line, '[][(){}]', 0)
|
||||
while pos != -1
|
||||
if !s:IsInStringOrComment(a:lnum, pos + 1)
|
||||
let idx = stridx('(){}[]', line[pos])
|
||||
if idx % 2 == 0
|
||||
let open_{idx} = open_{idx} + 1
|
||||
else
|
||||
let open_{idx - 1} = open_{idx - 1} - 1
|
||||
endif
|
||||
endif
|
||||
let pos = match(line, '[][(){}]', pos + 1)
|
||||
endwhile
|
||||
return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
|
||||
endfunction
|
||||
|
||||
function s:Match(lnum, regex)
|
||||
let col = match(getline(a:lnum), a:regex) + 1
|
||||
return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0
|
||||
endfunction
|
||||
|
||||
function s:IndentWithContinuation(lnum, ind, width)
|
||||
" Set up variables to use and search for MSL to the previous line.
|
||||
let p_lnum = a:lnum
|
||||
let lnum = s:GetMSL(a:lnum, 1)
|
||||
let line = getline(lnum)
|
||||
|
||||
" If the previous line wasn't a MSL and is continuation return its indent.
|
||||
" TODO: the || s:IsInString() thing worries me a bit.
|
||||
if p_lnum != lnum
|
||||
if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line))
|
||||
return a:ind
|
||||
endif
|
||||
endif
|
||||
|
||||
" Set up more variables now that we know we aren't continuation bound.
|
||||
let msl_ind = indent(lnum)
|
||||
|
||||
" If the previous line ended with [*+/.-=], start a continuation that
|
||||
" indents an extra level.
|
||||
if s:Match(lnum, s:continuation_regex)
|
||||
if lnum == p_lnum
|
||||
return msl_ind + a:width
|
||||
else
|
||||
return msl_ind
|
||||
endif
|
||||
endif
|
||||
|
||||
return a:ind
|
||||
endfunction
|
||||
|
||||
function s:InOneLineScope(lnum)
|
||||
let msl = s:GetMSL(a:lnum, 1)
|
||||
if msl > 0 && s:Match(msl, s:one_line_scope_regex)
|
||||
return msl
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function s:ExitingOneLineScope(lnum)
|
||||
let msl = s:GetMSL(a:lnum, 1)
|
||||
if msl > 0
|
||||
" if the current line is in a one line scope ..
|
||||
if s:Match(msl, s:one_line_scope_regex)
|
||||
return 0
|
||||
else
|
||||
let prev_msl = s:GetMSL(msl - 1, 1)
|
||||
if s:Match(prev_msl, s:one_line_scope_regex)
|
||||
return prev_msl
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" 3. GetJavascriptIndent Function {{{1
|
||||
" =========================
|
||||
|
||||
function GetJavascriptIndent()
|
||||
" 3.1. Setup {{{2
|
||||
" ----------
|
||||
|
||||
" Set up variables for restoring position in file. Could use v:lnum here.
|
||||
let vcol = col('.')
|
||||
|
||||
" 3.2. Work on the current line {{{2
|
||||
" -----------------------------
|
||||
|
||||
let ind = -1
|
||||
" Get the current line.
|
||||
let line = getline(v:lnum)
|
||||
" previous nonblank line number
|
||||
let prevline = prevnonblank(v:lnum - 1)
|
||||
|
||||
" If we got a closing bracket on an empty line, find its match and indent
|
||||
" according to it. For parentheses we indent to its column - 1, for the
|
||||
" others we indent to the containing line's MSL's level. Return -1 if fail.
|
||||
let col = matchend(line, '^\s*[],})]')
|
||||
if col > 0 && !s:IsInStringOrComment(v:lnum, col)
|
||||
call cursor(v:lnum, col)
|
||||
|
||||
let lvar = s:InMultiVarStatement(v:lnum)
|
||||
if lvar
|
||||
let prevline_contents = s:RemoveTrailingComments(getline(prevline))
|
||||
|
||||
" check for comma first
|
||||
if (line[col - 1] =~ ',')
|
||||
" if the previous line ends in comma or semicolon don't indent
|
||||
if (prevline_contents =~ '[;,]\s*$')
|
||||
return indent(s:GetMSL(line('.'), 0))
|
||||
" get previous line indent, if it's comma first return prevline indent
|
||||
elseif (prevline_contents =~ s:comma_first)
|
||||
return indent(prevline)
|
||||
" otherwise we indent 1 level
|
||||
else
|
||||
return indent(lvar) + &sw
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2)
|
||||
if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0
|
||||
if line[col-1]==')' && col('.') != col('$') - 1
|
||||
let ind = virtcol('.')-1
|
||||
else
|
||||
let ind = indent(s:GetMSL(line('.'), 0))
|
||||
endif
|
||||
endif
|
||||
return ind
|
||||
endif
|
||||
|
||||
" If the line is comma first, dedent 1 level
|
||||
if (getline(prevline) =~ s:comma_first)
|
||||
return indent(prevline) - &sw
|
||||
endif
|
||||
|
||||
if (line =~ s:ternary)
|
||||
if (getline(prevline) =~ s:ternary_q)
|
||||
return indent(prevline)
|
||||
else
|
||||
return indent(prevline) + &sw
|
||||
endif
|
||||
endif
|
||||
|
||||
" If we are in a multi-line comment, cindent does the right thing.
|
||||
if s:IsInMultilineComment(v:lnum, 1) && !s:IsLineComment(v:lnum, 1)
|
||||
return cindent(v:lnum)
|
||||
endif
|
||||
|
||||
" Check for multiple var assignments
|
||||
" let var_indent = s:GetVarIndent(v:lnum)
|
||||
" if var_indent >= 0
|
||||
" return var_indent
|
||||
" endif
|
||||
|
||||
" 3.3. Work on the previous line. {{{2
|
||||
" -------------------------------
|
||||
|
||||
" 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*$' && s:IsInMultilineComment(prevline, 1)
|
||||
return indent(prevline) - 1
|
||||
endif
|
||||
|
||||
" Find a non-blank, non-multi-line string line above the current line.
|
||||
let lnum = s:PrevNonBlankNonString(v:lnum - 1)
|
||||
|
||||
" If the line is empty and inside a string, use the previous line.
|
||||
if line =~ '^\s*$' && lnum != prevline
|
||||
return indent(prevnonblank(v:lnum))
|
||||
endif
|
||||
|
||||
" At the start of the file use zero indent.
|
||||
if lnum == 0
|
||||
return 0
|
||||
endif
|
||||
|
||||
" Set up variables for current line.
|
||||
let line = getline(lnum)
|
||||
let ind = indent(lnum)
|
||||
|
||||
" If the previous line ended with a block opening, add a level of indent.
|
||||
if s:Match(lnum, s:block_regex)
|
||||
return indent(s:GetMSL(lnum, 0)) + &sw
|
||||
endif
|
||||
|
||||
" If the previous line contained an opening bracket, and we are still in it,
|
||||
" add indent depending on the bracket type.
|
||||
if line =~ '[[({]'
|
||||
let counts = s:LineHasOpeningBrackets(lnum)
|
||||
if counts[0] == '1' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
|
||||
if col('.') + 1 == col('$')
|
||||
return ind + &sw
|
||||
else
|
||||
return virtcol('.')
|
||||
endif
|
||||
elseif counts[1] == '1' || counts[2] == '1'
|
||||
return ind + &sw
|
||||
else
|
||||
call cursor(v:lnum, vcol)
|
||||
end
|
||||
endif
|
||||
|
||||
" 3.4. Work on the MSL line. {{{2
|
||||
" --------------------------
|
||||
|
||||
let ind_con = ind
|
||||
let ind = s:IndentWithContinuation(lnum, ind_con, &sw)
|
||||
|
||||
" }}}2
|
||||
"
|
||||
"
|
||||
let ols = s:InOneLineScope(lnum)
|
||||
if ols > 0
|
||||
let ind = ind + &sw
|
||||
else
|
||||
let ols = s:ExitingOneLineScope(lnum)
|
||||
while ols > 0 && ind > 0
|
||||
let ind = ind - &sw
|
||||
let ols = s:InOneLineScope(ols - 1)
|
||||
endwhile
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
320
sources_non_forked/vim-javascript/syntax/javascript.vim
Normal file
320
sources_non_forked/vim-javascript/syntax/javascript.vim
Normal file
|
@ -0,0 +1,320 @@
|
|||
" Vim syntax file
|
||||
" Language: JavaScript
|
||||
" Maintainer: vim-javascript community
|
||||
" URL: https://github.com/pangloss/vim-javascript
|
||||
|
||||
if !exists("main_syntax")
|
||||
if version < 600
|
||||
syntax clear
|
||||
elseif exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
let main_syntax = 'javascript'
|
||||
endif
|
||||
|
||||
if !exists('g:javascript_conceal')
|
||||
let g:javascript_conceal = 0
|
||||
endif
|
||||
|
||||
"" Drop fold if it is set but VIM doesn't support it.
|
||||
let b:javascript_fold='true'
|
||||
if version < 600 " Don't support the old version
|
||||
unlet! b:javascript_fold
|
||||
endif
|
||||
|
||||
"" dollar sign is permittd anywhere in an identifier
|
||||
setlocal iskeyword+=$
|
||||
|
||||
syntax sync fromstart
|
||||
|
||||
syntax match jsNoise /\%(:\|,\|\;\|\.\)/
|
||||
|
||||
"" Program Keywords
|
||||
syntax keyword jsStorageClass const var let
|
||||
syntax keyword jsOperator delete instanceof typeof void new in
|
||||
syntax match jsOperator /\(!\||\|&\|+\|-\|<\|>\|=\|%\|\/\|*\|\~\|\^\)/
|
||||
syntax keyword jsBooleanTrue true
|
||||
syntax keyword jsBooleanFalse false
|
||||
|
||||
"" JavaScript comments
|
||||
syntax keyword jsCommentTodo TODO FIXME XXX TBD contained
|
||||
syntax region jsLineComment start=+\/\/+ end=+$+ keepend contains=jsCommentTodo,@Spell
|
||||
syntax region jsEnvComment start="\%^#!" end="$" display
|
||||
syntax region jsLineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend contains=jsCommentTodo,@Spell fold
|
||||
syntax region jsCvsTag start="\$\cid:" end="\$" oneline contained
|
||||
syntax region jsComment start="/\*" end="\*/" contains=jsCommentTodo,jsCvsTag,@Spell fold
|
||||
|
||||
"" JSDoc / JSDoc Toolkit
|
||||
if !exists("javascript_ignore_javaScriptdoc")
|
||||
syntax case ignore
|
||||
|
||||
"" syntax coloring for javadoc comments (HTML)
|
||||
"syntax include @javaHtml <sfile>:p:h/html.vim
|
||||
"unlet b:current_syntax
|
||||
|
||||
syntax region jsDocComment matchgroup=jsComment start="/\*\*\s*" end="\*/" contains=jsDocTags,jsCommentTodo,jsCvsTag,@jsHtml,@Spell fold
|
||||
|
||||
" tags containing a param
|
||||
syntax match jsDocTags contained "@\(alias\|augments\|borrows\|class\|constructs\|default\|defaultvalue\|emits\|exception\|exports\|extends\|file\|fires\|kind\|listens\|member\|member[oO]f\|mixes\|module\|name\|namespace\|requires\|throws\|var\|variation\|version\)\>" nextgroup=jsDocParam skipwhite
|
||||
" tags containing type and param
|
||||
syntax match jsDocTags contained "@\(arg\|argument\|param\|property\)\>" nextgroup=jsDocType skipwhite
|
||||
" tags containing type but no param
|
||||
syntax match jsDocTags contained "@\(callback\|enum\|external\|this\|type\|typedef\|return\|returns\)\>" nextgroup=jsDocTypeNoParam skipwhite
|
||||
" tags containing references
|
||||
syntax match jsDocTags contained "@\(lends\|see\|tutorial\)\>" nextgroup=jsDocSeeTag skipwhite
|
||||
" other tags (no extra syntax)
|
||||
syntax match jsDocTags contained "@\(abstract\|access\|author\|classdesc\|constant\|const\|constructor\|copyright\|deprecated\|desc\|description\|event\|example\|file[oO]verview\|function\|global\|ignore\|inner\|instance\|license\|method\|mixin\|overview\|private\|protected\|public\|readonly\|since\|static\|todo\|summary\|undocumented\|virtual\)\>"
|
||||
|
||||
syntax region jsDocType start="{" end="}" oneline contained nextgroup=jsDocParam skipwhite
|
||||
syntax match jsDocType contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+" nextgroup=jsDocParam skipwhite
|
||||
syntax region jsDocTypeNoParam start="{" end="}" oneline contained
|
||||
syntax match jsDocTypeNoParam contained "\%(#\|\"\|\w\|\.\|:\|\/\)\+"
|
||||
syntax match jsDocParam contained "\%(#\|\"\|{\|}\|\w\|\.\|:\|\/\)\+"
|
||||
syntax region jsDocSeeTag contained matchgroup=jsDocSeeTag start="{" end="}" contains=jsDocTags
|
||||
|
||||
syntax case match
|
||||
endif "" JSDoc end
|
||||
|
||||
syntax case match
|
||||
|
||||
"" Syntax in the JavaScript code
|
||||
syntax match jsFuncCall /\k\+\%(\s*(\)\@=/
|
||||
syntax match jsSpecial "\v\\%(0|\\x\x\{2\}\|\\u\x\{4\}\|\c[A-Z]|.)" contained
|
||||
syntax match jsTemplateVar "\${.\{-}}" contained
|
||||
syntax region jsStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=jsSpecial,@htmlPreproc,@Spell
|
||||
syntax region jsStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=jsSpecial,@htmlPreproc,@Spell
|
||||
syntax region jsTemplateString start=+`+ skip=+\\\\\|\\$`+ end=+`+ contains=jsTemplateVar,jsSpecial,@htmlPreproc
|
||||
syntax region jsRegexpCharClass start=+\[+ skip=+\\.+ end=+\]+ contained
|
||||
syntax match jsRegexpBoundary "\v%(\<@![\^$]|\\[bB])" contained
|
||||
syntax match jsRegexpBackRef "\v\\[1-9][0-9]*" contained
|
||||
syntax match jsRegexpQuantifier "\v\\@<!%([?*+]|\{\d+%(,|,\d+)?})\??" contained
|
||||
syntax match jsRegexpOr "\v\<@!\|" contained
|
||||
syntax match jsRegexpMod "\v\(@<=\?[:=!>]" contained
|
||||
syntax cluster jsRegexpSpecial contains=jsSpecial,jsRegexpBoundary,jsRegexpBackRef,jsRegexpQuantifier,jsRegexpOr,jsRegexpMod
|
||||
syntax region jsRegexpGroup start="\\\@<!(" end="\\\@<!)" contained contains=jsRegexpCharClass,@jsRegexpSpecial keepend
|
||||
syntax region jsRegexpString start=+\(\(\(return\|case\)\s\+\)\@<=\|\(\([)\]"']\|\d\|\w\)\s*\)\@<!\)/\(\*\|/\)\@!+ skip=+\\.\|\[\(\\.\|[^]]\)*\]+ end=+/[gimy]\{,4}+ contains=jsRegexpCharClass,jsRegexpGroup,@jsRegexpSpecial,@htmlPreproc oneline keepend
|
||||
syntax match jsNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/
|
||||
syntax keyword jsNumber Infinity
|
||||
syntax match jsFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/
|
||||
syntax match jsObjectKey /\<[a-zA-Z_$][0-9a-zA-Z_$]*\(\s*:\)\@=/ contains=jsFunctionKey contained
|
||||
syntax match jsFunctionKey /\<[a-zA-Z_$][0-9a-zA-Z_$]*\(\s*:\s*function\s*\)\@=/ contained
|
||||
|
||||
if g:javascript_conceal == 1
|
||||
syntax keyword jsNull null conceal cchar=ø
|
||||
syntax keyword jsThis this conceal cchar=@
|
||||
syntax keyword jsReturn return conceal cchar=⇚
|
||||
syntax keyword jsUndefined undefined conceal cchar=¿
|
||||
syntax keyword jsNan NaN conceal cchar=ℕ
|
||||
syntax keyword jsPrototype prototype conceal cchar=¶
|
||||
else
|
||||
syntax keyword jsNull null
|
||||
syntax keyword jsThis this
|
||||
syntax keyword jsReturn return
|
||||
syntax keyword jsUndefined undefined
|
||||
syntax keyword jsNan NaN
|
||||
syntax keyword jsPrototype prototype
|
||||
endif
|
||||
|
||||
"" Statement Keywords
|
||||
syntax keyword jsStatement break continue with
|
||||
syntax keyword jsConditional if else switch
|
||||
syntax keyword jsRepeat do while for
|
||||
syntax keyword jsLabel case default
|
||||
syntax keyword jsKeyword yield
|
||||
syntax keyword jsException try catch throw finally
|
||||
|
||||
syntax keyword jsGlobalObjects Array Boolean Date Function Iterator Number Object RegExp String Proxy ParallelArray ArrayBuffer DataView Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray Intl JSON Math console document window
|
||||
syntax match jsGlobalObjects /\%(Intl\.\)\@<=\(Collator\|DateTimeFormat\|NumberFormat\)/
|
||||
|
||||
syntax keyword jsExceptions Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError
|
||||
|
||||
syntax keyword jsBuiltins decodeURI decodeURIComponent encodeURI encodeURIComponent eval isFinite isNaN parseFloat parseInt uneval
|
||||
|
||||
syntax keyword jsFutureKeys abstract enum int short boolean export interface static byte extends long super char final native synchronized class float package throws goto private transient debugger implements protected volatile double import public
|
||||
|
||||
"" DOM/HTML/CSS specified things
|
||||
|
||||
" DOM2 Objects
|
||||
syntax keyword jsGlobalObjects DOMImplementation DocumentFragment Document Node NodeList NamedNodeMap CharacterData Attr Element Text Comment CDATASection DocumentType Notation Entity EntityReference ProcessingInstruction
|
||||
syntax keyword jsExceptions DOMException
|
||||
|
||||
" DOM2 CONSTANT
|
||||
syntax keyword jsDomErrNo INDEX_SIZE_ERR DOMSTRING_SIZE_ERR HIERARCHY_REQUEST_ERR WRONG_DOCUMENT_ERR INVALID_CHARACTER_ERR NO_DATA_ALLOWED_ERR NO_MODIFICATION_ALLOWED_ERR NOT_FOUND_ERR NOT_SUPPORTED_ERR INUSE_ATTRIBUTE_ERR INVALID_STATE_ERR SYNTAX_ERR INVALID_MODIFICATION_ERR NAMESPACE_ERR INVALID_ACCESS_ERR
|
||||
syntax keyword jsDomNodeConsts ELEMENT_NODE ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE
|
||||
|
||||
" HTML events and internal variables
|
||||
syntax case ignore
|
||||
syntax keyword jsHtmlEvents onblur onclick oncontextmenu ondblclick onfocus onkeydown onkeypress onkeyup onmousedown onmousemove onmouseout onmouseover onmouseup onresize
|
||||
syntax case match
|
||||
|
||||
" Follow stuff should be highligh within a special context
|
||||
" While it can't be handled with context depended with Regex based highlight
|
||||
" So, turn it off by default
|
||||
if exists("javascript_enable_domhtmlcss")
|
||||
|
||||
" DOM2 things
|
||||
syntax match jsDomElemAttrs contained /\%(nodeName\|nodeValue\|nodeType\|parentNode\|childNodes\|firstChild\|lastChild\|previousSibling\|nextSibling\|attributes\|ownerDocument\|namespaceURI\|prefix\|localName\|tagName\)\>/
|
||||
syntax match jsDomElemFuncs contained /\%(insertBefore\|replaceChild\|removeChild\|appendChild\|hasChildNodes\|cloneNode\|normalize\|isSupported\|hasAttributes\|getAttribute\|setAttribute\|removeAttribute\|getAttributeNode\|setAttributeNode\|removeAttributeNode\|getElementsByTagName\|getAttributeNS\|setAttributeNS\|removeAttributeNS\|getAttributeNodeNS\|setAttributeNodeNS\|getElementsByTagNameNS\|hasAttribute\|hasAttributeNS\)\>/ nextgroup=jsParen skipwhite
|
||||
" HTML things
|
||||
syntax match jsHtmlElemAttrs contained /\%(className\|clientHeight\|clientLeft\|clientTop\|clientWidth\|dir\|id\|innerHTML\|lang\|length\|offsetHeight\|offsetLeft\|offsetParent\|offsetTop\|offsetWidth\|scrollHeight\|scrollLeft\|scrollTop\|scrollWidth\|style\|tabIndex\|title\)\>/
|
||||
syntax match jsHtmlElemFuncs contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=jsParen skipwhite
|
||||
|
||||
" CSS Styles in JavaScript
|
||||
syntax keyword jsCssStyles contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition
|
||||
syntax keyword jsCssStyles contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition
|
||||
syntax keyword jsCssStyles contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode
|
||||
syntax keyword jsCssStyles contained bottom height left position right top width zIndex
|
||||
syntax keyword jsCssStyles contained border borderBottom borderLeft borderRight borderTop borderBottomColor borderLeftColor borderTopColor borderBottomStyle borderLeftStyle borderRightStyle borderTopStyle borderBottomWidth borderLeftWidth borderRightWidth borderTopWidth borderColor borderStyle borderWidth borderCollapse borderSpacing captionSide emptyCells tableLayout
|
||||
syntax keyword jsCssStyles contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop
|
||||
syntax keyword jsCssStyles contained listStyle listStyleImage listStylePosition listStyleType
|
||||
syntax keyword jsCssStyles contained background backgroundAttachment backgroundColor backgroundImage gackgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat
|
||||
syntax keyword jsCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType
|
||||
syntax keyword jsCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText
|
||||
syntax keyword jsCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor
|
||||
|
||||
" Highlight ways
|
||||
syntax match jsDotNotation "\." nextgroup=jsPrototype,jsDomElemAttrs,jsDomElemFuncs,jsHtmlElemAttrs,jsHtmlElemFuncs
|
||||
syntax match jsDotNotation "\.style\." nextgroup=jsCssStyles
|
||||
|
||||
endif "DOM/HTML/CSS
|
||||
|
||||
"" end DOM/HTML/CSS specified things
|
||||
|
||||
|
||||
"" Code blocks
|
||||
syntax cluster jsExpression contains=jsComment,jsLineComment,jsDocComment,jsTemplateString,jsStringD,jsStringS,jsRegexpString,jsNumber,jsFloat,jsThis,jsOperator,jsBooleanTrue,jsBooleanFalse,jsNull,jsFunction,jsArrowFunction,jsGlobalObjects,jsExceptions,jsFutureKeys,jsDomErrNo,jsDomNodeConsts,jsHtmlEvents,jsDotNotation,jsBracket,jsParen,jsBlock,jsFuncCall,jsUndefined,jsNan,jsKeyword,jsStorageClass,jsPrototype,jsBuiltins,jsNoise
|
||||
syntax cluster jsAll contains=@jsExpression,jsLabel,jsConditional,jsRepeat,jsReturn,jsStatement,jsTernaryIf,jsException
|
||||
syntax region jsBracket matchgroup=jsBrackets start="\[" end="\]" contains=@jsAll,jsParensErrB,jsParensErrC,jsBracket,jsParen,jsBlock,@htmlPreproc fold
|
||||
syntax region jsParen matchgroup=jsParens start="(" end=")" contains=@jsAll,jsParensErrA,jsParensErrC,jsParen,jsBracket,jsBlock,@htmlPreproc fold
|
||||
syntax region jsBlock matchgroup=jsBraces start="{" end="}" contains=@jsAll,jsParensErrA,jsParensErrB,jsParen,jsBracket,jsBlock,jsObjectKey,@htmlPreproc fold
|
||||
syntax region jsFuncBlock matchgroup=jsFuncBraces start="{" end="}" contains=@jsAll,jsParensErrA,jsParensErrB,jsParen,jsBracket,jsBlock,@htmlPreproc contained fold
|
||||
syntax region jsTernaryIf matchgroup=jsTernaryIfOperator start=+?+ end=+:+ contains=@jsExpression,jsTernaryIf
|
||||
|
||||
"" catch errors caused by wrong parenthesis
|
||||
syntax match jsParensError ")\|}\|\]"
|
||||
syntax match jsParensErrA contained "\]"
|
||||
syntax match jsParensErrB contained ")"
|
||||
syntax match jsParensErrC contained "}"
|
||||
|
||||
if main_syntax == "javascript"
|
||||
syntax sync clear
|
||||
syntax sync ccomment jsComment minlines=200
|
||||
syntax sync match jsHighlight grouphere jsBlock /{/
|
||||
endif
|
||||
|
||||
if g:javascript_conceal == 1
|
||||
syntax match jsFunction /\<function\>/ nextgroup=jsFuncName,jsFuncArgs skipwhite conceal cchar=ƒ
|
||||
else
|
||||
syntax match jsFunction /\<function\>/ nextgroup=jsFuncName,jsFuncArgs skipwhite
|
||||
endif
|
||||
|
||||
syntax match jsFuncName contained /\<[a-zA-Z_$][0-9a-zA-Z_$]*/ nextgroup=jsFuncArgs skipwhite
|
||||
syntax region jsFuncArgs contained matchgroup=jsFuncParens start='(' end=')' contains=jsFuncArgCommas,jsFuncArgRest nextgroup=jsFuncBlock keepend skipwhite skipempty
|
||||
syntax match jsFuncArgCommas contained ','
|
||||
syntax match jsFuncArgRest contained /\%(\.\.\.[a-zA-Z_$][0-9a-zA-Z_$]*\))/
|
||||
syntax keyword jsArgsObj arguments contained containedin=jsFuncBlock
|
||||
|
||||
syntax match jsArrowFunction /=>/
|
||||
|
||||
" Define the default highlighting.
|
||||
" For version 5.7 and earlier: only when not done already
|
||||
" For version 5.8 and later: only when an item doesn't have highlighting yet
|
||||
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 jsFuncArgRest Special
|
||||
HiLink jsComment Comment
|
||||
HiLink jsLineComment Comment
|
||||
HiLink jsEnvComment PreProc
|
||||
HiLink jsDocComment Comment
|
||||
HiLink jsCommentTodo Todo
|
||||
HiLink jsCvsTag Function
|
||||
HiLink jsDocTags Special
|
||||
HiLink jsDocSeeTag Function
|
||||
HiLink jsDocType Type
|
||||
HiLink jsDocTypeNoParam Type
|
||||
HiLink jsDocParam Label
|
||||
HiLink jsStringS String
|
||||
HiLink jsStringD String
|
||||
HiLink jsTemplateString String
|
||||
HiLink jsTernaryIfOperator Conditional
|
||||
HiLink jsRegexpString String
|
||||
HiLink jsRegexpBoundary SpecialChar
|
||||
HiLink jsRegexpQuantifier SpecialChar
|
||||
HiLink jsRegexpOr Conditional
|
||||
HiLink jsRegexpMod SpecialChar
|
||||
HiLink jsRegexpBackRef SpecialChar
|
||||
HiLink jsRegexpGroup jsRegexpString
|
||||
HiLink jsRegexpCharClass Character
|
||||
HiLink jsCharacter Character
|
||||
HiLink jsPrototype Special
|
||||
HiLink jsConditional Conditional
|
||||
HiLink jsBranch Conditional
|
||||
HiLink jsLabel Label
|
||||
HiLink jsReturn Statement
|
||||
HiLink jsRepeat Repeat
|
||||
HiLink jsStatement Statement
|
||||
HiLink jsException Exception
|
||||
HiLink jsKeyword Keyword
|
||||
HiLink jsArrowFunction Type
|
||||
HiLink jsFunction Type
|
||||
HiLink jsFuncName Function
|
||||
HiLink jsArgsObj Special
|
||||
HiLink jsError Error
|
||||
HiLink jsParensError Error
|
||||
HiLink jsParensErrA Error
|
||||
HiLink jsParensErrB Error
|
||||
HiLink jsParensErrC Error
|
||||
HiLink jsOperator Operator
|
||||
HiLink jsStorageClass StorageClass
|
||||
HiLink jsThis Special
|
||||
HiLink jsNan Number
|
||||
HiLink jsNull Type
|
||||
HiLink jsUndefined Type
|
||||
HiLink jsNumber Number
|
||||
HiLink jsFloat Float
|
||||
HiLink jsBooleanTrue Boolean
|
||||
HiLink jsBooleanFalse Boolean
|
||||
HiLink jsNoise Noise
|
||||
HiLink jsBrackets Noise
|
||||
HiLink jsParens Noise
|
||||
HiLink jsBraces Noise
|
||||
HiLink jsFuncBraces Noise
|
||||
HiLink jsFuncParens Noise
|
||||
HiLink jsSpecial Special
|
||||
HiLink jsTemplateVar Special
|
||||
HiLink jsGlobalObjects Special
|
||||
HiLink jsExceptions Special
|
||||
HiLink jsFutureKeys Special
|
||||
HiLink jsBuiltins Special
|
||||
|
||||
HiLink jsDomErrNo Constant
|
||||
HiLink jsDomNodeConsts Constant
|
||||
HiLink jsDomElemAttrs Label
|
||||
HiLink jsDomElemFuncs PreProc
|
||||
|
||||
HiLink jsHtmlEvents Special
|
||||
HiLink jsHtmlElemAttrs Label
|
||||
HiLink jsHtmlElemFuncs PreProc
|
||||
|
||||
HiLink jsCssStyles Label
|
||||
|
||||
delcommand HiLink
|
||||
endif
|
||||
|
||||
" Define the htmlJavaScript for HTML syntax html.vim
|
||||
"syntax clear htmlJavaScript
|
||||
"syntax clear jsExpression
|
||||
syntax cluster htmlJavaScript contains=@jsAll,jsBracket,jsParen,jsBlock
|
||||
syntax cluster javaScriptExpression contains=@jsAll,jsBracket,jsParen,jsBlock,@htmlPreproc
|
||||
" Vim's default html.vim highlights all javascript as 'Special'
|
||||
hi! def link javaScript NONE
|
||||
|
||||
let b:current_syntax = "javascript"
|
||||
if main_syntax == 'javascript'
|
||||
unlet main_syntax
|
||||
endif
|
2
sources_non_forked/vim-node/.gitignore
vendored
Normal file
2
sources_non_forked/vim-node/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/*.zip
|
||||
/node.tar.gz
|
1
sources_non_forked/vim-node/.mailmap
Normal file
1
sources_non_forked/vim-node/.mailmap
Normal file
|
@ -0,0 +1 @@
|
|||
Andri Möll <andri@dot.ee>
|
8
sources_non_forked/vim-node/.packignore
Normal file
8
sources_non_forked/vim-node/.packignore
Normal file
|
@ -0,0 +1,8 @@
|
|||
/Makefile
|
||||
/test/*
|
||||
/Gemfile
|
||||
/Gemfile.lock
|
||||
/Guardfile
|
||||
/*.zip
|
||||
/node.tar.gz
|
||||
tags
|
7
sources_non_forked/vim-node/.travis.yml
Normal file
7
sources_non_forked/vim-node/.travis.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
language: ruby
|
||||
rvm:
|
||||
- 1.9.3
|
||||
|
||||
before_install: sudo apt-get install vim-gtk
|
||||
install: bundle install --deployment --without development
|
||||
script: xvfb-run make test
|
44
sources_non_forked/vim-node/CHANGELOG.md
Normal file
44
sources_non_forked/vim-node/CHANGELOG.md
Normal file
|
@ -0,0 +1,44 @@
|
|||
## 0.8.1 (Apr 15, 2014)
|
||||
- Updates the URL from which Node.vim downloads Node core module source files.
|
||||
Uses <http://rawgit.com> which used to be named <http://rawgithub.com>.
|
||||
Because of Vim Netrw's inability to handle HTTPS, it does so over HTTP. Sorry.
|
||||
|
||||
## 0.8.0 (Sep 6, 2013)
|
||||
- Adds `node` as a core module so you could use `:Nedit node` to open the file Node uses to bootstrap its core.
|
||||
|
||||
## 0.7.0 (Aug 28, 2013)
|
||||
- Adds support for opening core Node.js modules, such as `http`, `util`, etc. with `gf` or `:Nedit`.
|
||||
They're shown straight from Node's online repository without you having to download everything.
|
||||
|
||||
## 0.6.0 (Aug 23, 2013)
|
||||
- Adds `:Nedit` command for editing modules or files relative to the Node project root.
|
||||
For example: `:Nedit any-module/lib` or `:Nedit ./package`.
|
||||
- Adds `:Nopen` command which behaves like `:Nedit`, but also `lcd`s to the module's directory.
|
||||
- Makes `<Plug>NodeGotoFile` available for your mapping in any Node project file, but maps it to `gf` automatically only on JavaScript files.
|
||||
- Maps `gf` also for JSON files for easy jumping to modules.
|
||||
- Makes `:Nedit` and `:Nopen` available immediately when starting Vim in a directory of a Node project.
|
||||
|
||||
## 0.5.1 (Aug 8, 2013)
|
||||
- Adds `Node` autocommand.
|
||||
Use it with `autocmd User Node` to customize settings for files in Node projects.
|
||||
- Adds `<Plug>NodeVSplitGotoFile` for those who want `<C-w>f` to split vertically.
|
||||
|
||||
## 0.5.0 (Aug 5, 2013)
|
||||
- Adds `&include` pattern so Vim can recognize included/required files, e.g. for looking up keywords with `[I`.
|
||||
- Cleans `&path` from `/usr/include` for JavaScript files.
|
||||
- Adds a new superb `gf` handler to handle all relative and module paths, incl. support for `require(".")` to open `./index.js`. This is spot on how Node.js finds your requires.
|
||||
- Adds `<Plug>NodeGotoFile` should you want to remap Node.vim's file opener.
|
||||
- Opens files before directories should both, e.g. `./foo.js` and `./foo`, exist. This matches Node.js's behavior.
|
||||
- Adds a full automated integration test suite to Node.vim which is freaking amazing!
|
||||
|
||||
## 0.2.0 (Jul 28, 2013)
|
||||
- Adds full support for navigating to module files by using `gf` on `require("any-module")`.
|
||||
- Adds `.json` to `&suffixesadd` so you could use `gf` on `require("./package")` to open package.json.
|
||||
|
||||
## 0.1.1 (Jul 28, 2013)
|
||||
- Removes an innocent but forgotten debugging line.
|
||||
|
||||
## 0.1.0 (Jul 28, 2013)
|
||||
- First release to get the nodeballs rolling.
|
||||
- Sets the filetype to JavaScript for files with Node's shebang (`#!`).
|
||||
- Adds `.js` to `&suffixesadd` so you could use `gf` on `require("./foo")` to open `foo.js`.
|
11
sources_non_forked/vim-node/Gemfile
Normal file
11
sources_non_forked/vim-node/Gemfile
Normal file
|
@ -0,0 +1,11 @@
|
|||
source "https://rubygems.org"
|
||||
|
||||
group :development do
|
||||
gem "guard-minitest"
|
||||
gem "minitest-reporters"
|
||||
end
|
||||
|
||||
group :test do
|
||||
gem "minitest", "< 5"
|
||||
gem "vimrunner", :git => "https://github.com/moll/vimrunner.git"
|
||||
end
|
59
sources_non_forked/vim-node/Gemfile.lock
Normal file
59
sources_non_forked/vim-node/Gemfile.lock
Normal file
|
@ -0,0 +1,59 @@
|
|||
GIT
|
||||
remote: https://github.com/moll/vimrunner.git
|
||||
revision: 4b1ee072e52dea871a0c3370f215f54fe596a9dc
|
||||
specs:
|
||||
vimrunner (0.3.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
ansi (1.4.3)
|
||||
builder (3.2.2)
|
||||
coderay (1.0.9)
|
||||
ffi (1.9.0)
|
||||
formatador (0.2.4)
|
||||
guard (1.8.2)
|
||||
formatador (>= 0.2.4)
|
||||
listen (>= 1.0.0)
|
||||
lumberjack (>= 1.0.2)
|
||||
pry (>= 0.9.10)
|
||||
thor (>= 0.14.6)
|
||||
guard-minitest (1.0.1)
|
||||
guard (>= 1.8)
|
||||
minitest (>= 2.1)
|
||||
hashie (2.0.5)
|
||||
listen (1.2.2)
|
||||
rb-fsevent (>= 0.9.3)
|
||||
rb-inotify (>= 0.9)
|
||||
rb-kqueue (>= 0.2)
|
||||
lumberjack (1.0.4)
|
||||
method_source (0.8.2)
|
||||
minitest (4.7.5)
|
||||
minitest-reporters (0.14.20)
|
||||
ansi
|
||||
builder
|
||||
minitest (>= 2.12, < 5.0)
|
||||
powerbar
|
||||
powerbar (1.0.11)
|
||||
ansi (~> 1.4.0)
|
||||
hashie (>= 1.1.0)
|
||||
pry (0.9.12.2)
|
||||
coderay (~> 1.0.5)
|
||||
method_source (~> 0.8)
|
||||
slop (~> 3.4)
|
||||
rb-fsevent (0.9.3)
|
||||
rb-inotify (0.9.0)
|
||||
ffi (>= 0.5.0)
|
||||
rb-kqueue (0.2.0)
|
||||
ffi (>= 0.5.0)
|
||||
slop (3.4.6)
|
||||
thor (0.18.1)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
guard-minitest
|
||||
minitest (< 5)
|
||||
minitest-reporters
|
||||
vimrunner!
|
8
sources_non_forked/vim-node/Guardfile
Normal file
8
sources_non_forked/vim-node/Guardfile
Normal file
|
@ -0,0 +1,8 @@
|
|||
guard :minitest, :all_on_start => false, :cli => ENV["TEST_OPTS"] do
|
||||
watch(%r(^(.*)\.vim$)) {|m| "test/#{m[1]}_test.rb" }
|
||||
watch(%r(^([^/]+)/[^/]+\.vim$)) {|m| "test/#{m[1]}_test.rb" }
|
||||
watch(%r(^([^/]+)/[^/]+/(.*)\.vim$)) {|m| "test/#{m[1]}/#{m[2]}_test.rb" }
|
||||
|
||||
watch(%r(^test/(.*)\/?_test\.rb))
|
||||
watch(%r(^test/helper\.rb)) { "test" }
|
||||
end
|
20
sources_non_forked/vim-node/LICENSE
Normal file
20
sources_non_forked/vim-node/LICENSE
Normal file
|
@ -0,0 +1,20 @@
|
|||
Node.vim
|
||||
Copyright (C) 2013 Andri Möll
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Affero General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or any later version.
|
||||
|
||||
Additional permission under the GNU Affero GPL version 3 section 7:
|
||||
If you modify this Program, or any covered work, by linking or
|
||||
combining it with other code, such other code is not for that reason
|
||||
alone subject to any of the requirements of the GNU Affero GPL version 3.
|
||||
|
||||
In summary:
|
||||
- You can use this program for no cost.
|
||||
- You can use this program for both personal and commercial reasons.
|
||||
- You do not have to share your own program's code which uses this program.
|
||||
- You have to share modifications (e.g bug-fixes) you've made to this program.
|
||||
|
||||
For the full copy of the GNU Affero General Public License see:
|
||||
http://www.gnu.org/licenses.
|
40
sources_non_forked/vim-node/Makefile
Normal file
40
sources_non_forked/vim-node/Makefile
Normal file
|
@ -0,0 +1,40 @@
|
|||
NAME = node
|
||||
TITLE = Node.vim
|
||||
VERSION = 0.8.1
|
||||
ID = 4674
|
||||
TEST_OPTS =
|
||||
|
||||
love:
|
||||
@echo "Feel like makin' love."
|
||||
|
||||
test: spec
|
||||
autotest: autospec
|
||||
|
||||
spec: $(shell find . -name "*_test.rb")
|
||||
@ruby -rbundler/setup $(addprefix -r./,$^) -e "" -- $(TEST_OPTS)
|
||||
|
||||
autospec:
|
||||
@bundle exec guard start --no-interactions
|
||||
|
||||
pack:
|
||||
rm -rf "$(NAME)-$(VERSION).zip"
|
||||
zip -r "$(NAME)-$(VERSION).zip" * -x @.packignore
|
||||
|
||||
publish:
|
||||
open "http://www.vim.org/scripts/add_script_version.php?script_id=$(ID)"
|
||||
|
||||
tag:
|
||||
git tag "v$(VERSION)"
|
||||
|
||||
node.tar.gz:
|
||||
wget -c "https://github.com/joyent/node/archive/master.tar.gz" -O node.tar.gz
|
||||
|
||||
list-core-modules: node.tar.gz
|
||||
tar tf node.tar.gz |\
|
||||
egrep "^node[^/]*/lib/.+" |\
|
||||
xargs -n1 basename -s .js |\
|
||||
{ cat; echo node; } | sort
|
||||
|
||||
.PHONY: love
|
||||
.PHONY: spec autospec
|
||||
.PHONY: pack publish tag
|
104
sources_non_forked/vim-node/README.md
Normal file
104
sources_non_forked/vim-node/README.md
Normal file
|
@ -0,0 +1,104 @@
|
|||
Node.vim
|
||||
========
|
||||
[![Build status](https://travis-ci.org/moll/vim-node.png?branch=master)](https://travis-ci.org/moll/vim-node)
|
||||
|
||||
Tools to make Vim superb for developing with Node.js.
|
||||
It's the Node equivalent of [Rails.vim (vimscript #1567)](https://github.com/tpope/vim-rails) and [Rake.vim (vimscript #3669)](https://github.com/tpope/vim-rake).
|
||||
|
||||
This is just the first release to get the nodes rolling. If you've collected great helpers and shortcuts that help you work with Node, please share them via [email](mailto:andri@dot.ee), [Twitter](https://twitter.com/theml) or [GitHub issues](https://github.com/moll/vim-node/issues) so we could incorporate them here, too! Thanks!
|
||||
|
||||
### Tour
|
||||
|
||||
- Use `gf` on paths or requires to open the same file Node.js would.
|
||||
- Use `gf` on `require(".")` to open `./index.js`
|
||||
- Use `gf` on `require("./dir")` to open `./dir/index.js`
|
||||
- Use `gf` on `require("./foo")` to open `foo.js`.
|
||||
- Use `gf` on `require("./package")` and have it open package.json.
|
||||
- Use `gf` on `require("module")` to open the module's main file (parsed for you from `package.json`).
|
||||
- Use `gf` on `require("module/lib/utils")` and open files inside the module.
|
||||
- Automatically sets the filetype to JavaScript for files with Node's shebang (`#!`).
|
||||
- Use `[I` etc. to look for a keyword in required files (Sets Vim's `&include`).
|
||||
- Use `:Nedit` to quickly edit any module, file in a module or your project file.
|
||||
- Use `:Nopen` to quickly edit any module and `lcd` to its directory.
|
||||
- Lets you even open Node's core modules. They're shown straight from Node's online repository without you having to download everything.
|
||||
- Node.vim itself is tested with a thorough automated integration test suite! No cowboy coding here!
|
||||
|
||||
Expect more to come soon and feel free to let me know what you're after!
|
||||
|
||||
PS. Node.vim is absolutely intended to work on Windows, but not yet tested there at all. If you could help, try it out and report issues, I'd be grateful!
|
||||
|
||||
|
||||
Installing
|
||||
----------
|
||||
The easiest and most modular way is to download this to `~/.vim/bundle`:
|
||||
```
|
||||
mkdir -p ~/.vim/bundle/node
|
||||
```
|
||||
|
||||
Using Git:
|
||||
```
|
||||
git clone https://github.com/moll/vim-node.git ~/.vim/bundle/node
|
||||
```
|
||||
|
||||
Using Wget:
|
||||
```
|
||||
wget https://github.com/moll/vim-node/archive/master.tar.gz -O- | tar -xf- --strip-components 1 -C ~/.vim/bundle/node
|
||||
```
|
||||
|
||||
Then prepend that directory to Vim's `&runtimepath` (or use [Pathogen](https://github.com/tpope/vim-pathogen)):
|
||||
```
|
||||
:set runtimepath^=~/.vim/bundle/node
|
||||
```
|
||||
|
||||
### Vundle
|
||||
|
||||
Or use [Vundle](https://github.com/gmarik/Vundle.vim):
|
||||
```
|
||||
:BundleInstall moll/vim-node
|
||||
```
|
||||
|
||||
|
||||
Using
|
||||
-----
|
||||
Open any JavaScript file inside a Node project and you're all set.
|
||||
|
||||
- Use `gf` inside `require("...")` to jump to source and module files.
|
||||
- Use `[I` on any keyword to look for it in the current and required files.
|
||||
- Use `:Nedit module_name` to edit the main file of a module.
|
||||
- Use `:Nedit module_name/lib/foo` to edit its `lib/foo.js` file.
|
||||
- Use `:Nedit .` to edit your Node projects main (usually `index.js`) file.
|
||||
|
||||
#### Want to customize settings for files inside a Node projects?
|
||||
Use the `Node` autocommand. For example:
|
||||
```vim
|
||||
autocmd User Node if &filetype == "javascript" | setlocal expandtab | endif
|
||||
```
|
||||
|
||||
#### Want `<C-w>f` to open the file under the cursor in a new vertical split?
|
||||
`<C-w>f` by default opens it in a horizontal split. To have it open vertically, drop this in your `vimrc`:
|
||||
```vim
|
||||
autocmd User Node
|
||||
\ if &filetype == "javascript" |
|
||||
\ nmap <buffer> <C-w>f <Plug>NodeVSplitGotoFile |
|
||||
\ nmap <buffer> <C-w><C-f> <Plug>NodeVSplitGotoFile |
|
||||
\ endif
|
||||
```
|
||||
|
||||
License
|
||||
-------
|
||||
Node.vim is released under a *Lesser GNU Affero General Public License*, which in summary means:
|
||||
|
||||
- You **can** use this program for **no cost**.
|
||||
- You **can** use this program for **both personal and commercial reasons**.
|
||||
- You **do not have to share your own program's code** which uses this program.
|
||||
- You **have to share modifications** (e.g bug-fixes) you've made to this program.
|
||||
|
||||
For more convoluted language, see the `LICENSE` file.
|
||||
|
||||
|
||||
About
|
||||
-----
|
||||
**[Andri Möll](http://themoll.com)** authored this in SublemacslipseMate++.
|
||||
[Monday Calendar](https://mondayapp.com) supported the engineering work.
|
||||
|
||||
If you find Node.vim needs improving or you've got a question, please don't hesitate to email me anytime at [andri@dot.ee](mailto:andri@dot.ee), tweet at [@theml](https://twitter.com/theml) or [create an issue online](https://github.com/moll/vim-node/issues).
|
106
sources_non_forked/vim-node/autoload/node.vim
Normal file
106
sources_non_forked/vim-node/autoload/node.vim
Normal file
|
@ -0,0 +1,106 @@
|
|||
let node#suffixesadd = [".js", ".json"]
|
||||
let node#filetypes = ["javascript", "json"]
|
||||
|
||||
set sw=2
|
||||
|
||||
function! node#initialize(root)
|
||||
let b:node_root = a:root
|
||||
call s:initializeCommands()
|
||||
if index(g:node#filetypes, &ft) > -1 | call s:initializeJavaScript() | en
|
||||
silent doautocmd User Node
|
||||
endfunction
|
||||
|
||||
function! s:initializeCommands()
|
||||
command! -bar -bang -nargs=1 -buffer -complete=customlist,s:complete Nedit
|
||||
\ exe s:nedit(<q-args>, bufname("%"), "edit<bang>")
|
||||
command! -bar -bang -nargs=1 -buffer -complete=customlist,s:complete Nopen
|
||||
\ exe s:nopen(<q-args>, bufname("%"), "edit<bang>")
|
||||
|
||||
nnoremap <buffer><silent> <Plug>NodeGotoFile
|
||||
\ :call <SID>edit(expand("<cfile>"), bufname("%"))<CR>
|
||||
nnoremap <buffer><silent> <Plug>NodeSplitGotoFile
|
||||
\ :call <SID>edit(expand("<cfile>"), bufname("%"), "split")<CR>
|
||||
nnoremap <buffer><silent> <Plug>NodeVSplitGotoFile
|
||||
\ :call <SID>edit(expand("<cfile>"), bufname("%"), "vsplit")<CR>
|
||||
nnoremap <buffer><silent> <Plug>NodeTabGotoFile
|
||||
\ :call <SID>edit(expand("<cfile>"), bufname("%"), "tab split")<CR>
|
||||
endfunction
|
||||
|
||||
function! s:initializeJavaScript()
|
||||
setl path-=/usr/include
|
||||
let &l:suffixesadd .= "," . join(g:node#suffixesadd, ",")
|
||||
let &l:include = '\<require(\(["'']\)\zs[^\1]\+\ze\1'
|
||||
let &l:includeexpr = "node#lib#find(v:fname, bufname('%'))"
|
||||
|
||||
if !hasmapto("<Plug>NodeGotoFile")
|
||||
" Split gotofiles don't take a count for the new window's width, but for
|
||||
" opening the nth file. Though Node.vim doesn't support counts atm.
|
||||
nmap <buffer> gf <Plug>NodeGotoFile
|
||||
nmap <buffer> <C-w>f <Plug>NodeSplitGotoFile
|
||||
nmap <buffer> <C-w><C-f> <Plug>NodeSplitGotoFile
|
||||
nmap <buffer> <C-w>gf <Plug>NodeTabGotoFile
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:edit(name, from, ...)
|
||||
if empty(a:name) | return | endif
|
||||
let dir = isdirectory(a:from) ? a:from : fnamemodify(a:from, ":h")
|
||||
let command = a:0 == 1 ? a:1 : "edit"
|
||||
|
||||
" If just a plain filename with no directory part, check if it exists:
|
||||
if a:name !~# '^\v(/|\./|\.\./)' && filereadable(dir . "/" . a:name)
|
||||
let path = dir . "/" . a:name
|
||||
else
|
||||
let path = node#lib#find(a:name, dir)
|
||||
end
|
||||
|
||||
if empty(path)
|
||||
return s:error("E447: Can't find file \"" . a:name . "\" in path")
|
||||
endif
|
||||
|
||||
exe command . " " . fnameescape(path)
|
||||
endfunction
|
||||
|
||||
function! s:nedit(name, from, ...)
|
||||
let command = a:0 == 1 ? a:1 : "edit"
|
||||
call s:edit(a:name, b:node_root, command)
|
||||
endfunction
|
||||
|
||||
function! s:nopen(name, from, ...)
|
||||
let command = a:0 == 1 ? a:1 : "edit"
|
||||
call s:nedit(a:name, a:from, command)
|
||||
if exists("b:node_root") | exe "lcd " . fnameescape(b:node_root) | endif
|
||||
endfunction
|
||||
|
||||
function! s:complete(arg, cmd, cursor)
|
||||
let matches = node#lib#glob(s:dirname(a:arg))
|
||||
|
||||
" Show private modules (_*) only if explicitly asked:
|
||||
if a:arg[0] != "_" | call filter(matches, "v:val[0] != '_'") | endif
|
||||
|
||||
let filter = "stridx(v:val, a:arg) == 0"
|
||||
let ignorecase = 0
|
||||
let ignorecase = ignorecase || exists("&fileignorecase") && &fileignorecase
|
||||
let ignorecase = ignorecase || exists("&wildignorecase") && &wildignorecase
|
||||
if ignorecase | let filter = "stridx(tolower(v:val),tolower(a:arg)) == 0" | en
|
||||
|
||||
return filter(matches, filter)
|
||||
endfunction
|
||||
|
||||
function! s:dirname(path)
|
||||
let dirname = fnamemodify(a:path, ":h")
|
||||
if dirname == "." | return "" | endif
|
||||
|
||||
" To not change the amount of final consecutive slashes, using this
|
||||
" dirname/basename trick:
|
||||
let basename = fnamemodify(a:path, ":t")
|
||||
return a:path[0 : 0 - len(basename) - 1]
|
||||
endfunction
|
||||
|
||||
" Using the built-in :echoerr prints a stacktrace, which isn't that nice.
|
||||
function! s:error(msg)
|
||||
echohl ErrorMsg
|
||||
echomsg a:msg
|
||||
echohl NONE
|
||||
let v:errmsg = a:msg
|
||||
endfunction
|
151
sources_non_forked/vim-node/autoload/node/lib.vim
Normal file
151
sources_non_forked/vim-node/autoload/node/lib.vim
Normal file
|
@ -0,0 +1,151 @@
|
|||
let s:ABSPATH = '^/'
|
||||
let s:RELPATH = '\v^\.\.?(/|$)'
|
||||
let s:MODULE = '\v^(/|\.\.?(/|$))@!'
|
||||
|
||||
" Damn Netrw can't handle HTTPS at all. It's 2013! Insecure bastard!
|
||||
let s:CORE_URL_PREFIX = "http://rawgit.com/joyent/node"
|
||||
let s:CORE_MODULES = ["_debugger", "_http_agent", "_http_client",
|
||||
\ "_http_common", "_http_incoming", "_http_outgoing", "_http_server",
|
||||
\ "_linklist", "_stream_duplex", "_stream_passthrough", "_stream_readable",
|
||||
\ "_stream_transform", "_stream_writable", "_tls_legacy", "_tls_wrap",
|
||||
\ "assert", "buffer", "child_process", "cluster", "console", "constants",
|
||||
\ "crypto", "dgram", "dns", "domain", "events", "freelist", "fs", "http",
|
||||
\ "https", "module", "net", "node", "os", "path", "punycode", "querystring",
|
||||
\ "readline", "repl", "smalloc", "stream", "string_decoder", "sys",
|
||||
\ "timers", "tls", "tty", "url", "util", "vm", "zlib"]
|
||||
|
||||
function! node#lib#find(name, from)
|
||||
if index(s:CORE_MODULES, a:name) != -1
|
||||
let l:version = node#lib#version()
|
||||
let l:version = empty(l:version) ? "master" : "v" . l:version
|
||||
let l:dir = a:name == "node" ? "src" : "lib"
|
||||
return s:CORE_URL_PREFIX ."/". l:version ."/". l:dir ."/". a:name .".js"
|
||||
endif
|
||||
|
||||
return s:resolve(s:absolutize(a:name, a:from))
|
||||
endfunction
|
||||
|
||||
function! node#lib#version()
|
||||
if exists("b:node_version") | return b:node_version | endif
|
||||
if !executable("node") | let b:node_version = "" | return | endif
|
||||
let b:node_version = matchstr(system("node --version"), '^v\?\zs[0-9.]\+')
|
||||
return b:node_version
|
||||
endfunction
|
||||
|
||||
function! s:absolutize(name, from)
|
||||
if a:name =~# s:ABSPATH
|
||||
return a:name
|
||||
elseif a:name =~# s:RELPATH
|
||||
let dir = isdirectory(a:from) ? a:from : fnamemodify(a:from, ":h")
|
||||
return dir . "/" . a:name
|
||||
else
|
||||
return b:node_root . "/node_modules/" . a:name
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:resolve(path)
|
||||
" Node checks for files *before* directories, so see if the path does not
|
||||
" end with a slash or dots and try to match it as a file.
|
||||
if a:path !~# '\v/(\.\.?/?)?$'
|
||||
let path_with_suffix = s:resolveSuffix(a:path)
|
||||
if !empty(path_with_suffix) | return path_with_suffix | endif
|
||||
endif
|
||||
|
||||
if isdirectory(a:path) | return s:resolveFromDirectory(a:path) | endif
|
||||
endfunction
|
||||
|
||||
function! s:resolveFromDirectory(path)
|
||||
" Node.js checks for package.json in every directory, not just the
|
||||
" module's parent. According to:
|
||||
" http://nodejs.org/api/modules.html#modules_all_together
|
||||
if filereadable(a:path . "/package.json")
|
||||
" Turns out, even though Node says it does not support directories in
|
||||
" main, it does.
|
||||
" NOTE: If package.json's main is empty or refers to a non-existent file,
|
||||
" ./index.js is still tried.
|
||||
let main = s:mainFromPackage(a:path . "/package.json")
|
||||
|
||||
if !empty(main) && main != ""
|
||||
let path = s:resolve(a:path . "/" . main)
|
||||
if !empty(path) | return path | endif
|
||||
endif
|
||||
endif
|
||||
|
||||
" We need to check for ./index.js's existence here rather than leave it to
|
||||
" the caller, because otherwise we can't distinguish if this ./index was
|
||||
" from the directory defaulting to ./index.js or it was the package.json
|
||||
" which referred to ./index, which in itself could mean both ./index.js and
|
||||
" ./index/index.js.
|
||||
return s:resolveSuffix(a:path . "/index")
|
||||
endfunction
|
||||
|
||||
function! s:mainFromPackage(path)
|
||||
for line in readfile(a:path)
|
||||
if line !~# '"main"\s*:' | continue | endif
|
||||
return matchstr(line, '"main"\s*:\s*"\zs[^"]\+\ze"')
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:resolveSuffix(path)
|
||||
for suffix in s:uniq([""] + g:node#suffixesadd + split(&l:suffixesadd, ","))
|
||||
let path = a:path . suffix
|
||||
if filereadable(path) | return path | endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
let s:GLOB_WILDIGNORE = 1
|
||||
|
||||
function! node#lib#glob(name)
|
||||
let matches = []
|
||||
|
||||
if empty(a:name)
|
||||
let matches += s:CORE_MODULES
|
||||
endif
|
||||
|
||||
if empty(a:name) || a:name =~# s:MODULE
|
||||
let root = b:node_root . "/node_modules"
|
||||
let matches += s:glob(empty(a:name) ? root : root . "/" . a:name, root)
|
||||
endif
|
||||
|
||||
if a:name =~# s:ABSPATH
|
||||
let matches += s:glob(a:name, 0)
|
||||
endif
|
||||
|
||||
if empty(a:name) || a:name =~# s:RELPATH
|
||||
let root = b:node_root
|
||||
let relatives = s:glob(empty(a:name) ? root : root . "/" . a:name, root)
|
||||
|
||||
"call map(relatives, "substitute(v:val, '^\./\./', './', '')")
|
||||
if empty(a:name) | call map(relatives, "'./' . v:val") | endif
|
||||
call filter(relatives, "v:val !~# '^\\.//*node_modules/$'")
|
||||
|
||||
let matches += relatives
|
||||
endif
|
||||
|
||||
return matches
|
||||
endfunction
|
||||
|
||||
function! s:glob(path, stripPrefix)
|
||||
" Remove a single trailing slash because we're adding one with the glob.
|
||||
let path = substitute(a:path, '/$', "", "")
|
||||
" Glob() got the ability to return a list only in Vim 7.3.465. Using split
|
||||
" for compatibility.
|
||||
let list = split(glob(fnameescape(path)."/*", s:GLOB_WILDIGNORE), "\n")
|
||||
|
||||
" Add slashes to directories, like /bin/ls.
|
||||
call map(list, "v:val . (isdirectory(v:val) ? '/' : '')")
|
||||
|
||||
if !empty(a:stripPrefix)
|
||||
" Counting and removing bytes intentionally as there's no substr function
|
||||
" that takes character count, only bytes.
|
||||
let prefix_length = len(a:stripPrefix) + 1
|
||||
return map(list, "strpart(v:val, prefix_length)")
|
||||
endif
|
||||
|
||||
return list
|
||||
endfunction
|
||||
|
||||
function! s:uniq(list)
|
||||
let list = reverse(copy(a:list))
|
||||
return reverse(filter(list, "index(list, v:val, v:key + 1) == -1"))
|
||||
endfunction
|
8
sources_non_forked/vim-node/ftdetect/node.vim
Normal file
8
sources_non_forked/vim-node/ftdetect/node.vim
Normal file
|
@ -0,0 +1,8 @@
|
|||
function! s:isNode()
|
||||
let shebang = getline(1)
|
||||
if shebang =~# '^#!.*/bin/env\s\+node\>' | return 1 | en
|
||||
if shebang =~# '^#!.*/bin/node\>' | return 1 | en
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
au BufRead,BufNewFile * if !did_filetype() && s:isNode() | setf javascript | en
|
24
sources_non_forked/vim-node/plugin/node.vim
Normal file
24
sources_non_forked/vim-node/plugin/node.vim
Normal file
|
@ -0,0 +1,24 @@
|
|||
if exists("g:loaded_node") || &cp || v:version < 700 | finish | endif
|
||||
let g:loaded_node = 1
|
||||
|
||||
function! s:detect(path)
|
||||
if exists("b:node_root") | return | endif
|
||||
let path = a:path
|
||||
|
||||
while 1
|
||||
let is_node = 0
|
||||
let is_node = is_node || filereadable(path . "/package.json")
|
||||
let is_node = is_node || isdirectory(path . "/node_modules")
|
||||
if is_node | return node#initialize(path) | endif
|
||||
|
||||
let parent = fnamemodify(path, ":h")
|
||||
if parent == path | return | endif
|
||||
let path = parent
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
augroup Node
|
||||
au!
|
||||
au VimEnter * if empty(expand("<amatch>")) | call s:detect(getcwd()) | endif
|
||||
au BufRead,BufNewFile * call s:detect(expand("<amatch>:p"))
|
||||
augroup end
|
447
sources_non_forked/vim-node/test/autoload/lib_test.rb
Normal file
447
sources_non_forked/vim-node/test/autoload/lib_test.rb
Normal file
|
@ -0,0 +1,447 @@
|
|||
require_relative "../helper"
|
||||
require "json"
|
||||
|
||||
describe "Lib" do
|
||||
include WithTemporaryDirectory
|
||||
|
||||
before do
|
||||
Dir.mkdir File.join(@dir, "node_modules")
|
||||
end
|
||||
|
||||
def set_node_version(version)
|
||||
executable = File.join(@dir, "node")
|
||||
touch executable, <<-end.strip
|
||||
#!/bin/sh
|
||||
[ $# != 1 -o "$1" != --version ] && exit 1
|
||||
echo "v#{version}"
|
||||
end
|
||||
File.chmod 0755, executable
|
||||
$vim.command(%(let $PATH = "#@dir:" . $PATH))
|
||||
end
|
||||
|
||||
describe "node#lib#find" do
|
||||
def find(name)
|
||||
path = $vim.echo(%(node#lib#find("#{name}", expand("%"))))
|
||||
File.exists?(path) ? File.realpath(path) : path
|
||||
end
|
||||
|
||||
it "must return ./README before ./README.js" do
|
||||
touch File.join(@dir, "README")
|
||||
touch File.join(@dir, "README.js")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("./README").must_equal File.join(@dir, "README")
|
||||
end
|
||||
|
||||
it "must return ./README.txt relative to file" do
|
||||
touch File.join(@dir, "lib", "README.txt")
|
||||
$vim.edit File.join(@dir, "lib", "index.js")
|
||||
find("./README.txt").must_equal File.join(@dir, "lib", "README.txt")
|
||||
end
|
||||
|
||||
it "must return ../README.txt" do
|
||||
touch File.join(@dir, "README.txt")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "index.js")
|
||||
find("../README.txt").must_equal File.join(@dir, "README.txt")
|
||||
end
|
||||
|
||||
it "must return /.../README.txt" do
|
||||
touch File.join(@dir, "README.txt")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "index.js")
|
||||
find("#@dir/README.txt").must_equal File.join(@dir, "README.txt")
|
||||
end
|
||||
|
||||
it "must return ./other.js given ./other" do
|
||||
touch File.join(@dir, "other.js")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("./other").must_equal File.join(@dir, "other.js")
|
||||
end
|
||||
|
||||
it "must return ./other.js given ./other relative to file" do
|
||||
touch File.join(@dir, "lib", "other.js")
|
||||
$vim.edit File.join(@dir, "lib", "index.js")
|
||||
find("./other").must_equal File.join(@dir, "lib", "other.js")
|
||||
end
|
||||
|
||||
it "must return ./other.js before ./other/index.js given ./other" do
|
||||
touch File.join(@dir, "other.js")
|
||||
touch File.join(@dir, "other", "index.js")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("./other").must_equal File.join(@dir, "other.js")
|
||||
end
|
||||
|
||||
it "must return ../other.js given ../other" do
|
||||
touch File.join(@dir, "other.js")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "index.js")
|
||||
find("../other").must_equal File.join(@dir, "other.js")
|
||||
end
|
||||
|
||||
it "must return /.../other.js given /.../other" do
|
||||
touch File.join(@dir, "other.js")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "index.js")
|
||||
find("#@dir/other").must_equal File.join(@dir, "other.js")
|
||||
end
|
||||
|
||||
it "must return ./package.json given ./package" do
|
||||
touch File.join(@dir, "package.json")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("./package").must_equal File.join(@dir, "package.json")
|
||||
end
|
||||
|
||||
it "must return ./index.js given ." do
|
||||
touch File.join(@dir, "index.js")
|
||||
$vim.edit File.join(@dir, "other.js")
|
||||
find(".").must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must return ./index.js given ./" do
|
||||
touch File.join(@dir, "index.js")
|
||||
$vim.edit File.join(@dir, "other.js")
|
||||
find("./").must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must not find ./index/index.js given ./" do
|
||||
touch File.join(@dir, "index", "index.js")
|
||||
$vim.edit File.join(@dir, "other.js")
|
||||
$vim.echo(%(empty(node#lib#find("./", expand("%"))))).must_equal "1"
|
||||
end
|
||||
|
||||
it "must not find ./.js given ./" do
|
||||
touch File.join(@dir, ".js")
|
||||
$vim.edit File.join(@dir, "other.js")
|
||||
$vim.echo(%(empty(node#lib#find("./", expand("%"))))).must_equal "1"
|
||||
end
|
||||
|
||||
it "must return ../index.js given .." do
|
||||
touch File.join(@dir, "index.js")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "other.js")
|
||||
find("..").must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must return ../index.js given ../" do
|
||||
touch File.join(@dir, "index.js")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "other.js")
|
||||
find("../").must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must return /.../index.js given /..." do
|
||||
touch File.join(@dir, "index.js")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "index.js")
|
||||
find("#@dir").must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must return /.../index.js given /.../" do
|
||||
touch File.join(@dir, "index.js")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "index.js")
|
||||
find("#@dir/").must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must return ./lib/index.js given ./lib" do
|
||||
touch File.join(@dir, "lib", "index.js")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("./lib").must_equal File.join(@dir, "lib", "index.js")
|
||||
end
|
||||
|
||||
it "must return ./lib/other.js given ./lib with main" do
|
||||
touch File.join(@dir, "lib", "other.js")
|
||||
touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "other")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("./lib").must_equal File.join(@dir, "lib", "other.js")
|
||||
end
|
||||
|
||||
it "must return ./lib/index.js given ./lib with empty main" do
|
||||
touch File.join(@dir, "lib", "index.js")
|
||||
touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("./lib").must_equal File.join(@dir, "lib", "index.js")
|
||||
end
|
||||
|
||||
it "must return ./lib/index.js given ./lib with non-existent main" do
|
||||
touch File.join(@dir, "lib", "index.js")
|
||||
touch File.join(@dir, "lib", "package.json"), JSON.dump(:main => "new")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("./lib").must_equal File.join(@dir, "lib", "index.js")
|
||||
end
|
||||
|
||||
it "must return ./other.js before ./other/index.js given . with main" do
|
||||
touch File.join(@dir, "package.json"), JSON.dump(:main => "other")
|
||||
touch File.join(@dir, "other.js")
|
||||
touch File.join(@dir, "other", "index.js")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find(".").must_equal File.join(@dir, "other.js")
|
||||
end
|
||||
|
||||
it "must return node_modules/foo/index.js given foo" do
|
||||
index = File.join(@dir, "node_modules", "foo", "index.js")
|
||||
touch index
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("foo").must_equal index
|
||||
end
|
||||
|
||||
it "must return node_modules/foo/other.js given foo/other" do
|
||||
other = File.join(@dir, "node_modules", "foo", "other.js")
|
||||
touch other
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("foo/other").must_equal other
|
||||
end
|
||||
|
||||
it "must return node_modules/foo/other.js given foo/other.js" do
|
||||
other = File.join(@dir, "node_modules", "foo", "other.js")
|
||||
touch other
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("foo/other.js").must_equal other
|
||||
end
|
||||
|
||||
# When package.json refers to a regular file.
|
||||
it "must return node_modules/foo/other.js given foo with main" do
|
||||
mod = File.join(@dir, "node_modules", "foo")
|
||||
touch File.join(mod, "package.json"), JSON.dump(:main => "./other.js")
|
||||
touch File.join(mod, "other.js")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("foo").must_equal File.join(mod, "other.js")
|
||||
end
|
||||
|
||||
# When package.json refers to a directory.
|
||||
it "must return node_modules/foo/lib/index.js given foo with main as ./lib" do
|
||||
mod = File.join(@dir, "node_modules", "foo")
|
||||
touch File.join(mod, "package.json"), JSON.dump(:main => "./lib")
|
||||
touch File.join(mod, "lib/index.js")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("foo").must_equal File.join(mod, "lib/index.js")
|
||||
end
|
||||
|
||||
it "must return node_modules/foo/lib/index.js given foo with main as lib" do
|
||||
mod = File.join(@dir, "node_modules", "foo")
|
||||
touch File.join(mod, "package.json"), JSON.dump(:main => "lib")
|
||||
touch File.join(mod, "lib/index.js")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
find("foo").must_equal File.join(mod, "lib/index.js")
|
||||
end
|
||||
|
||||
it "must return empty when looking for nothing" do
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.echo(%(empty(node#lib#find("", expand("%"))))).must_equal "1"
|
||||
end
|
||||
|
||||
it "must return empty when nothing found" do
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.echo(%(empty(node#lib#find("new", expand("%"))))).must_equal "1"
|
||||
end
|
||||
|
||||
it "must return URL for core module for current Node version" do
|
||||
set_node_version "0.13.37"
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
url = "http://rawgit.com/joyent/node/v0.13.37/lib/assert.js"
|
||||
find("assert").must_equal url
|
||||
end
|
||||
|
||||
it "must return URL for core module on master if no Node version" do
|
||||
touch File.join(@dir, "node"), "#!/bin/sh\nexit 1"
|
||||
File.chmod 0755, File.join(@dir, "node")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.command(%(let $PATH = "#@dir:" . $PATH))
|
||||
url = "http://rawgit.com/joyent/node/master/lib/assert.js"
|
||||
find("assert").must_equal url
|
||||
end
|
||||
|
||||
it "must return URL for node.js for current Node version" do
|
||||
set_node_version "0.13.37"
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
url = "http://rawgit.com/joyent/node/v0.13.37/src/node.js"
|
||||
find("node").must_equal url
|
||||
end
|
||||
|
||||
it "must return URL for node.js on master if no Node version" do
|
||||
touch File.join(@dir, "node"), "#!/bin/sh\nexit 1"
|
||||
File.chmod 0755, File.join(@dir, "node")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.command(%(let $PATH = "#@dir:" . $PATH))
|
||||
url = "http://rawgit.com/joyent/node/master/src/node.js"
|
||||
find("node").must_equal url
|
||||
end
|
||||
end
|
||||
|
||||
describe "node#lib#glob" do
|
||||
require "json"
|
||||
|
||||
before do
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
def glob(arg = "")
|
||||
# Because of possible locale and filesystem case-sensitiveness
|
||||
# differences, sort the output explicitly to be resistant.
|
||||
JSON.parse($vim.echo(%(node#lib#glob("#{arg}"))).gsub("'", '"')).sort
|
||||
end
|
||||
|
||||
describe "given nothing" do
|
||||
it "must return files and directories" do
|
||||
touch File.join(@dir, "index.js")
|
||||
touch File.join(@dir, "README.txt")
|
||||
Dir.mkdir File.join(@dir, "test")
|
||||
|
||||
files = %w[./README.txt ./index.js ./test/]
|
||||
glob.must_equal (CORE_MODULES + files).sort
|
||||
end
|
||||
|
||||
it "must return modules and core modules" do
|
||||
FileUtils.mkpath File.join(@dir, "node_modules", "require-guard")
|
||||
FileUtils.mkpath File.join(@dir, "node_modules", "export")
|
||||
FileUtils.mkpath File.join(@dir, "node_modules", "soul")
|
||||
glob.must_equal (CORE_MODULES + %w[export/ require-guard/ soul/]).sort
|
||||
end
|
||||
|
||||
it "must return core modules without slashes" do
|
||||
glob.must_equal CORE_MODULES
|
||||
glob.wont_equal /\//
|
||||
end
|
||||
|
||||
# Even though node.js is the bootstrapper file in src/.
|
||||
it "must return \"node\" as one of those core modules" do
|
||||
glob.must_include "node"
|
||||
end
|
||||
|
||||
it "must return files, directories and modules" do
|
||||
FileUtils.mkpath File.join(@dir, "node_modules", "export")
|
||||
FileUtils.mkpath File.join(@dir, "node_modules", "soul")
|
||||
touch File.join(@dir, "index.js")
|
||||
touch File.join(@dir, "README.txt")
|
||||
Dir.mkdir File.join(@dir, "test")
|
||||
|
||||
files = %w[./README.txt ./index.js ./test/ export/ soul/]
|
||||
glob.must_equal (CORE_MODULES + files).sort
|
||||
end
|
||||
|
||||
it "must not return the node_modules directory" do
|
||||
FileUtils.mkpath File.join(@dir, "node_modules")
|
||||
glob.must_equal CORE_MODULES
|
||||
end
|
||||
end
|
||||
|
||||
describe "given absolute path" do
|
||||
it "must return files and directories given /" do
|
||||
files = Dir.entries("/")
|
||||
files.reject! {|f| f =~ /^\./ }
|
||||
files.sort!
|
||||
files.map! {|f| "/" + f }
|
||||
files.map! {|f| File.directory?(f) ? f + "/" : f }
|
||||
|
||||
glob("/").must_equal files
|
||||
end
|
||||
|
||||
it "must return files and directories given /.../" do
|
||||
touch File.join(@dir, "index.js")
|
||||
touch File.join(@dir, "README")
|
||||
Dir.mkdir File.join(@dir, "test")
|
||||
|
||||
files = %W[#@dir/README #@dir/index.js #@dir/node_modules/ #@dir/test/]
|
||||
glob(@dir).must_equal files
|
||||
end
|
||||
|
||||
it "must return files and directories given /.../test" do
|
||||
touch File.join(@dir, "test", "index_test.js")
|
||||
touch File.join(@dir, "test", "helpers.js")
|
||||
files = %W[#@dir/test/helpers.js #@dir/test/index_test.js]
|
||||
glob(File.join(@dir, "test")).must_equal files
|
||||
end
|
||||
|
||||
it "must not return modules along with files" do
|
||||
touch File.join(@dir, "index.js")
|
||||
touch File.join(@dir, "README")
|
||||
Dir.mkdir File.join(@dir, "test")
|
||||
FileUtils.mkpath File.join(@dir, "node_modules", "soul")
|
||||
|
||||
files = %W[#@dir/README #@dir/index.js #@dir/node_modules/ #@dir/test/]
|
||||
glob(@dir).must_equal files
|
||||
end
|
||||
end
|
||||
|
||||
describe "given relative path" do
|
||||
it "must return files and directories given ." do
|
||||
touch File.join(@dir, "index.js")
|
||||
touch File.join(@dir, "README")
|
||||
Dir.mkdir File.join(@dir, "test")
|
||||
glob(".").must_equal %W[./README ./index.js ./test/]
|
||||
end
|
||||
|
||||
it "must return files and directories given ./" do
|
||||
touch File.join(@dir, "index.js")
|
||||
touch File.join(@dir, "README")
|
||||
Dir.mkdir File.join(@dir, "test")
|
||||
glob("./").must_equal %W[./README ./index.js ./test/]
|
||||
end
|
||||
|
||||
it "must return files and directories given .//" do
|
||||
touch File.join(@dir, "index.js")
|
||||
touch File.join(@dir, "README.txt")
|
||||
Dir.mkdir File.join(@dir, "test")
|
||||
glob(".//").must_equal %W[.//README.txt .//index.js .//test/]
|
||||
end
|
||||
|
||||
it "must return files and directories given .///" do
|
||||
touch File.join(@dir, "index.js")
|
||||
touch File.join(@dir, "README.txt")
|
||||
Dir.mkdir File.join(@dir, "test")
|
||||
glob(".///").must_equal %W[.///README.txt .///index.js .///test/]
|
||||
end
|
||||
|
||||
it "must return files and directories given ./test" do
|
||||
touch File.join(@dir, "test", "test.js")
|
||||
touch File.join(@dir, "test", "helpers.js")
|
||||
glob("./test/").must_equal %W[./test/helpers.js ./test/test.js]
|
||||
end
|
||||
end
|
||||
|
||||
describe "given module name" do
|
||||
it "must return files and directories given soul" do
|
||||
touch File.join(@dir, "node_modules", "soul", "index.js")
|
||||
touch File.join(@dir, "node_modules", "soul", "README")
|
||||
FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test")
|
||||
glob("soul").must_equal %w[soul/README soul/index.js soul/test/]
|
||||
end
|
||||
|
||||
it "must return files and directories given soul/" do
|
||||
touch File.join(@dir, "node_modules", "soul", "index.js")
|
||||
FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test")
|
||||
glob("soul/").must_equal %w[soul/index.js soul/test/]
|
||||
end
|
||||
|
||||
it "must return files and directories given soul//" do
|
||||
touch File.join(@dir, "node_modules", "soul", "index.js")
|
||||
FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test")
|
||||
glob("soul//").must_equal %w[soul//index.js soul//test/]
|
||||
end
|
||||
|
||||
it "must return files and directories given soul///" do
|
||||
touch File.join(@dir, "node_modules", "soul", "index.js")
|
||||
FileUtils.mkpath File.join(@dir, "node_modules", "soul", "test")
|
||||
glob("soul///").must_equal %w[soul///index.js soul///test/]
|
||||
end
|
||||
|
||||
it "must return files and directories given soul/test" do
|
||||
touch File.join(@dir, "node_modules", "soul", "test", "test.js")
|
||||
touch File.join(@dir, "node_modules", "soul", "test", "helpers.js")
|
||||
glob("soul/test").must_equal %w[soul/test/helpers.js soul/test/test.js]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "node#lib#version" do
|
||||
it "should return current Node's version" do
|
||||
set_node_version "0.13.37"
|
||||
$vim.echo("node#lib#version()").must_equal "0.13.37"
|
||||
end
|
||||
end
|
||||
end
|
460
sources_non_forked/vim-node/test/autoload_test.rb
Normal file
460
sources_non_forked/vim-node/test/autoload_test.rb
Normal file
|
@ -0,0 +1,460 @@
|
|||
require_relative "./helper"
|
||||
require "json"
|
||||
|
||||
describe "Autoloaded" do
|
||||
include WithTemporaryDirectory
|
||||
|
||||
before do
|
||||
FileUtils.touch File.join(@dir, "package.json")
|
||||
end
|
||||
|
||||
after do
|
||||
$vim.command("windo wincmd c")
|
||||
end
|
||||
|
||||
describe "Autocommand" do
|
||||
it "must fire user autcommand \"Node\"" do
|
||||
$vim.command "au User Node let node_autocommand = 1337"
|
||||
$vim.edit File.join(@dir, "other.js")
|
||||
$vim.echo(%(g:node_autocommand)).must_equal "1337"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Goto file" do
|
||||
it "must define plug mapping in non-JavaScript files" do
|
||||
$vim.edit File.join(@dir, "README")
|
||||
$vim.echo(%(maparg("<Plug>NodeGotoFile", "n"))).wont_equal ""
|
||||
end
|
||||
|
||||
it "must not be available in non-JavaScript files" do
|
||||
$vim.edit File.join(@dir, "README")
|
||||
$vim.echo(%(hasmapto("<Plug>NodeGotoFile"))).must_equal "0"
|
||||
end
|
||||
|
||||
it "must edit README.txt" do
|
||||
touch File.join(@dir, "index.js"), %(// Please read README.txt)
|
||||
touch File.join(@dir, "README.txt")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.feedkeys "$gf"
|
||||
$vim.echo(%(bufname("%"))).must_equal File.join(@dir, "README.txt")
|
||||
end
|
||||
|
||||
it "must edit README before README.js" do
|
||||
touch File.join(@dir, "index.js"), "// Please read README"
|
||||
touch File.join(@dir, "README")
|
||||
touch File.join(@dir, "README.js")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.feedkeys "$gf"
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "README")
|
||||
end
|
||||
|
||||
it "must edit ./README.txt relative to file" do
|
||||
touch File.join(@dir, "foo", "index.js"), %(// Please read ./README.txt)
|
||||
touch File.join(@dir, "foo", "README.txt")
|
||||
|
||||
$vim.edit File.join(@dir, "foo", "index.js")
|
||||
$vim.feedkeys "$gf"
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "foo", "README.txt")
|
||||
end
|
||||
|
||||
it "must edit /.../README.txt" do
|
||||
touch File.join(@dir, "index.js"), %(// Read #@dir/lib/README.txt)
|
||||
touch File.join(@dir, "lib", "README.txt")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.feedkeys "$gf"
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "lib", "README.txt")
|
||||
end
|
||||
|
||||
it "must open ./other.js relative to file" do
|
||||
touch File.join(@dir, "foo", "index.js"), %(require("./other"))
|
||||
touch File.join(@dir, "foo", "other.js")
|
||||
|
||||
$vim.edit File.join(@dir, "foo", "index.js")
|
||||
$vim.feedkeys "f.gf"
|
||||
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "foo", "other.js")
|
||||
end
|
||||
|
||||
it "must edit ./index.js given ." do
|
||||
touch File.join(@dir, "other.js"), %(require("."))
|
||||
touch File.join(@dir, "index.js")
|
||||
|
||||
$vim.edit File.join(@dir, "other.js")
|
||||
$vim.feedkeys "f.gf"
|
||||
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must edit ./index.js given ./" do
|
||||
touch File.join(@dir, "other.js"), %(require("./"))
|
||||
touch File.join(@dir, "index.js")
|
||||
|
||||
$vim.edit File.join(@dir, "other.js")
|
||||
$vim.feedkeys "f.gf"
|
||||
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must edit ../index.js given .." do
|
||||
touch File.join(@dir, "foo", "other.js"), %(require(".."))
|
||||
touch File.join(@dir, "index.js")
|
||||
|
||||
$vim.edit File.join(@dir, "foo", "other.js")
|
||||
$vim.feedkeys "f.gf"
|
||||
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must edit ../index.js given ../" do
|
||||
touch File.join(@dir, "foo", "other.js"), %(require("../"))
|
||||
touch File.join(@dir, "index.js")
|
||||
|
||||
$vim.edit File.join(@dir, "foo", "other.js")
|
||||
$vim.feedkeys "f.gf"
|
||||
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must open ./node_modules/foo/index.js given foo" do
|
||||
touch File.join(@dir, "index.js"), %(require("foo"))
|
||||
index = File.join(@dir, "node_modules", "foo", "index.js")
|
||||
touch index
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.feedkeys "$hhgf"
|
||||
$vim.echo(%(bufname("%"))).must_equal index
|
||||
end
|
||||
|
||||
it "must not show an error when opening nothing" do
|
||||
touch File.join(@dir, "index.js"), %("")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.command(%(let v:errmsg = ""))
|
||||
$vim.feedkeys "gf"
|
||||
|
||||
error = $vim.command("let v:errmsg").sub(/^\S+\s*/, "")
|
||||
error.must_equal ""
|
||||
end
|
||||
|
||||
it "must show error when opening a non-existent file" do
|
||||
touch File.join(@dir, "index.js"), %(require("new"))
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.command(%(let v:errmsg = ""))
|
||||
$vim.feedkeys "$hhgf"
|
||||
|
||||
error = $vim.command("let v:errmsg").sub(/^\S+\s*/, "")
|
||||
error.must_equal %(E447: Can't find file "new" in path)
|
||||
end
|
||||
|
||||
it "must find also when filetype is JSON" do
|
||||
$vim.command("au BufReadPre package set ft=json")
|
||||
touch File.join(@dir, "package"), %({"dependencies": {"foo": "1.x"}})
|
||||
index = File.join(@dir, "node_modules", "foo", "index.js")
|
||||
touch index
|
||||
|
||||
$vim.edit File.join(@dir, "package")
|
||||
$vim.echo("&filetype").must_equal "json"
|
||||
$vim.command("au! BufReadPre package set ft=json")
|
||||
|
||||
$vim.feedkeys "/foo\\<CR>gf"
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal index
|
||||
end
|
||||
end
|
||||
|
||||
describe "Goto file with split" do
|
||||
it "must edit file in a new split" do
|
||||
touch File.join(@dir, "index.js"), %(require("./other"))
|
||||
touch File.join(@dir, "other.js")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.feedkeys "f.\\<C-w>f"
|
||||
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "other.js")
|
||||
$vim.echo(%(winnr("$"))).must_equal "2"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Goto file with tab" do
|
||||
it "must edit file in a new tab" do
|
||||
touch File.join(@dir, "index.js"), %(require("./other"))
|
||||
touch File.join(@dir, "other.js")
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.feedkeys "f.\\<C-w>gf"
|
||||
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "other.js")
|
||||
$vim.echo(%(tabpagenr("$"))).must_equal "2"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Include file search pattern" do
|
||||
it "must find matches given a require" do
|
||||
touch File.join(@dir, "index.js"), <<-end.gsub(/^\s+/, "")
|
||||
var awesome = require("foo")
|
||||
awesome()
|
||||
end
|
||||
|
||||
definition = %(module.exports = function awesome() { return 1337 })
|
||||
touch File.join(@dir, "node_modules", "foo", "index.js"), definition
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.command("normal G[i").must_equal definition
|
||||
end
|
||||
|
||||
it "must find matches given a relative require" do
|
||||
touch File.join(@dir, "index.js"), <<-end.gsub(/^\s+/, "")
|
||||
var awesome = require("./other")
|
||||
awesome()
|
||||
end
|
||||
|
||||
definition = %(module.exports = function awesome() { return 1337 })
|
||||
touch File.join(@dir, "other.js"), definition
|
||||
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.command("normal G[i").must_equal definition
|
||||
end
|
||||
|
||||
it "must find matches given a relative require in another directory" do
|
||||
touch File.join(@dir, "foo", "index.js"), <<-end.gsub(/^\s+/, "")
|
||||
var awesome = require("./other")
|
||||
awesome()
|
||||
end
|
||||
|
||||
definition = %(module.exports = function awesome() { return 1337 })
|
||||
touch File.join(@dir, "foo", "other.js"), definition
|
||||
|
||||
$vim.edit File.join(@dir, "foo", "index.js")
|
||||
$vim.command("normal G[i").must_equal definition
|
||||
end
|
||||
end
|
||||
|
||||
describe ":Nedit" do
|
||||
# NOTE: Test from a non-JavaScript file everywhere to make sure there are
|
||||
# no dependencies on JavaScript specific settings.
|
||||
FULL_COMMAND_MATCH = "2"
|
||||
|
||||
it "must be available in non-JavaScript files" do
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
$vim.echo("exists(':Nedit')").must_equal FULL_COMMAND_MATCH
|
||||
end
|
||||
|
||||
it "must be available in JavaScript files" do
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.echo("exists(':Nedit')").must_equal FULL_COMMAND_MATCH
|
||||
end
|
||||
|
||||
it "must edit ./README.txt" do
|
||||
touch File.join(@dir, "README.txt")
|
||||
$vim.edit File.join(@dir, "CHANGELOG.txt")
|
||||
$vim.command "Nedit ./README.txt"
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "README.txt")
|
||||
end
|
||||
|
||||
it "must edit ./README.txt relative to node_root" do
|
||||
touch File.join(@dir, "README.txt")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "CHANGELOG.txt")
|
||||
$vim.command "Nedit ./README.txt"
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "README.txt")
|
||||
end
|
||||
|
||||
it "must edit /.../README.txt" do
|
||||
touch File.join(@dir, "lib", "README.txt")
|
||||
$vim.edit File.join(@dir, "CHANGELOG.txt")
|
||||
$vim.command "Nedit #@dir/lib/README.txt"
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "lib", "README.txt")
|
||||
end
|
||||
|
||||
it "must edit ./other.js relative to node_root" do
|
||||
touch File.join(@dir, "other.js")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "CHANGELOG.txt")
|
||||
$vim.command "Nedit ./other"
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "other.js")
|
||||
end
|
||||
|
||||
it "must edit ./index.js given ." do
|
||||
touch File.join(@dir, "index.js")
|
||||
$vim.edit File.join(@dir, "CHANGELOG.txt")
|
||||
$vim.command "Nedit ."
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must edit ./index.js given . relative to node_root" do
|
||||
touch File.join(@dir, "index.js")
|
||||
Dir.mkdir File.join(@dir, "lib")
|
||||
$vim.edit File.join(@dir, "lib", "CHANGELOG.txt")
|
||||
$vim.command "Nedit ."
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must edit ./index.js given ./" do
|
||||
touch File.join(@dir, "index.js")
|
||||
$vim.edit File.join(@dir, "CHANGELOG.txt")
|
||||
$vim.command "Nedit ./"
|
||||
bufname = File.realpath($vim.echo(%(bufname("%"))))
|
||||
bufname.must_equal File.join(@dir, "index.js")
|
||||
end
|
||||
|
||||
it "must edit /node_modules/foo/index.js given foo" do
|
||||
index = File.join(@dir, "node_modules", "foo", "index.js")
|
||||
touch index
|
||||
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
$vim.command("Nedit foo")
|
||||
$vim.echo(%(bufname("%"))).must_equal index
|
||||
end
|
||||
|
||||
describe "completion" do
|
||||
after do
|
||||
$vim.command("set wildignorecase&")
|
||||
$vim.command("set fileignorecase&")
|
||||
end
|
||||
|
||||
def complete(cmd)
|
||||
cmdline = $vim.command(%(silent! normal! :#{cmd}e))
|
||||
cmdline.sub(/^:\w+\s+/, "")
|
||||
end
|
||||
|
||||
public_core_modules = CORE_MODULES.select {|m| m[0] != "_" }
|
||||
private_core_modules = CORE_MODULES.select {|m| m[0] == "_" }
|
||||
|
||||
it "must return files, directories, modules" do
|
||||
Dir.mkdir File.join(@dir, "node_modules")
|
||||
Dir.mkdir File.join(@dir, "node_modules", "require-guard")
|
||||
Dir.mkdir File.join(@dir, "node_modules", "export")
|
||||
Dir.mkdir File.join(@dir, "node_modules", "soul")
|
||||
touch File.join(@dir, "index.js")
|
||||
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
files = %w[export/ require-guard/ soul/ ./index.js ./package.json]
|
||||
all = public_core_modules + files
|
||||
complete("Nedit ").split.sort.must_equal all.sort
|
||||
end
|
||||
|
||||
it "must return only public core modules" do
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
modules = public_core_modules + ["./package.json"]
|
||||
complete("Nedit ").must_equal modules.join(" ")
|
||||
end
|
||||
|
||||
it "must return private core modules if explicitly asked" do
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
complete("Nedit _").must_equal private_core_modules.join(" ")
|
||||
end
|
||||
|
||||
it "must return only matching modules" do
|
||||
Dir.mkdir File.join(@dir, "node_modules")
|
||||
Dir.mkdir File.join(@dir, "node_modules", "export")
|
||||
Dir.mkdir File.join(@dir, "node_modules", "soul")
|
||||
Dir.mkdir File.join(@dir, "node_modules", "soulstash")
|
||||
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
modules = "smalloc stream string_decoder sys soul/ soulstash/"
|
||||
complete("Nedit s").must_equal modules
|
||||
end
|
||||
|
||||
it "must not return modules with matching bit in the middle" do
|
||||
Dir.mkdir File.join(@dir, "node_modules")
|
||||
Dir.mkdir File.join(@dir, "node_modules", "soul")
|
||||
Dir.mkdir File.join(@dir, "node_modules", "soulstash")
|
||||
Dir.mkdir File.join(@dir, "node_modules", "asoul")
|
||||
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
complete("Nedit sou").must_equal "soul/ soulstash/"
|
||||
end
|
||||
|
||||
it "must return files and directories in module's directory" do
|
||||
touch File.join(@dir, "node_modules", "soul", "index.js")
|
||||
touch File.join(@dir, "node_modules", "soul", "test", "test.js")
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
complete("Nedit soul/").must_equal "soul/index.js soul/test/"
|
||||
end
|
||||
|
||||
it "must return files and directories given a double slash" do
|
||||
touch File.join(@dir, "node_modules", "soul", "index.js")
|
||||
touch File.join(@dir, "node_modules", "soul", "test", "test.js")
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
complete("Nedit soul//").must_equal "soul//index.js soul//test/"
|
||||
end
|
||||
|
||||
it "must return files case-insensitively given &fileignorecase" do
|
||||
skip if $vim.echo(%(exists("&fileignorecase"))) != "1"
|
||||
|
||||
$vim.command("set fileignorecase")
|
||||
$vim.command("set nowildignorecase")
|
||||
|
||||
touch File.join(@dir, "node_modules", "soul", "index.js")
|
||||
touch File.join(@dir, "node_modules", "soul", "CHANGELOG")
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
complete("Nedit soul/chan").must_equal "soul/CHANGELOG"
|
||||
end
|
||||
|
||||
it "must return files case-insensitively given only &wildignorecase" do
|
||||
skip if $vim.echo(%(exists("&wildignorecase"))) != "1"
|
||||
|
||||
$vim.command("set nofileignorecase")
|
||||
$vim.command("set wildignorecase")
|
||||
|
||||
touch File.join(@dir, "node_modules", "soul", "index.js")
|
||||
touch File.join(@dir, "node_modules", "soul", "CHANGELOG")
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
complete("Nedit soul/chan").must_equal "soul/CHANGELOG"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ":Nopen" do
|
||||
it "must edit and lcd to module's directory" do
|
||||
touch File.join(@dir, "node_modules", "foo", "package.json")
|
||||
touch File.join(@dir, "node_modules", "foo", "index.js")
|
||||
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
$vim.command("vsplit")
|
||||
|
||||
$vim.command("Nopen foo")
|
||||
$vim.echo(%(bufname("%"))).must_equal "index.js"
|
||||
$vim.command("pwd").must_equal File.join(@dir, "node_modules", "foo")
|
||||
|
||||
$vim.command("wincmd p")
|
||||
$vim.command("pwd").must_equal Dir.pwd
|
||||
end
|
||||
|
||||
it "must edit and lcd to module's root directory" do
|
||||
touch File.join(@dir, "node_modules", "foo", "package.json")
|
||||
utils = File.join(@dir, "node_modules", "foo", "lib", "utils.js")
|
||||
touch utils
|
||||
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
$vim.command("vsplit")
|
||||
|
||||
$vim.command("Nopen foo/lib/utils")
|
||||
$vim.echo(%(bufname("%"))).must_equal "lib/utils.js"
|
||||
$vim.command("pwd").must_equal File.join(@dir, "node_modules", "foo")
|
||||
|
||||
$vim.command("wincmd p")
|
||||
$vim.command("pwd").must_equal Dir.pwd
|
||||
end
|
||||
end
|
||||
end
|
45
sources_non_forked/vim-node/test/ftdetect_test.rb
Normal file
45
sources_non_forked/vim-node/test/ftdetect_test.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
require_relative "./helper"
|
||||
|
||||
describe "Ftdetect" do
|
||||
[
|
||||
"#!/usr/bin/env node",
|
||||
"#!/usr/bin/env node --harmony-generators",
|
||||
"#!/usr/local/bin/env node",
|
||||
"#!/usr/local/bin/env node --harmony-generators",
|
||||
"#!/usr/bin/node",
|
||||
"#!/usr/bin/node --harmony-generators",
|
||||
"#!/usr/local/bin/node",
|
||||
"#!/usr/local/bin/node --harmony-generators",
|
||||
|
||||
].each do |shebang|
|
||||
it %(must detect a file with "#{shebang}" shebang as JavaScript) do
|
||||
file = Tempfile.new("bang")
|
||||
file.write shebang + $/
|
||||
file.close
|
||||
$vim.edit file.path
|
||||
$vim.echo("&ft").must_equal "javascript"
|
||||
end
|
||||
end
|
||||
|
||||
[
|
||||
"#!/usr/bin/env noder",
|
||||
"#!/usr/bin/noder",
|
||||
|
||||
].each do |shebang|
|
||||
it %(must not detect a file with "#{shebang}" shebang as JavaScript) do
|
||||
file = Tempfile.new("bang")
|
||||
file.write shebang + $/
|
||||
file.close
|
||||
$vim.edit file.path
|
||||
$vim.echo("&ft").wont_equal "javascript"
|
||||
end
|
||||
end
|
||||
|
||||
it "must not detect a .c file as JavaScript even with Node's shebang" do
|
||||
file = Tempfile.new(%w[tea .c])
|
||||
file.write "#!/usr/bin/node" + $/
|
||||
file.close
|
||||
$vim.edit file.path
|
||||
$vim.echo("&ft").wont_equal "javascript"
|
||||
end
|
||||
end
|
48
sources_non_forked/vim-node/test/helper.rb
Normal file
48
sources_non_forked/vim-node/test/helper.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
require "minitest/autorun"
|
||||
require "vimrunner"
|
||||
require "fileutils"
|
||||
require "tempfile"
|
||||
|
||||
MiniTest::Unit::TestCase.define_singleton_method(:test_order) do :alpha end
|
||||
|
||||
begin
|
||||
require "minitest/reporters"
|
||||
MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
$vimrc = File.expand_path("../vimrc", __FILE__)
|
||||
$vim = Vimrunner::Server.new(:vimrc => $vimrc).start
|
||||
Minitest::Unit.after_tests { $vim.kill }
|
||||
|
||||
module WithTemporaryDirectory
|
||||
def self.included(base)
|
||||
require "tmpdir"
|
||||
end
|
||||
|
||||
def setup
|
||||
super
|
||||
# Mac has the temporary directory symlinked, so need File.realpath to
|
||||
# match the paths that Vim returns.
|
||||
@dir = File.realpath(Dir.mktmpdir)
|
||||
end
|
||||
|
||||
def teardown
|
||||
FileUtils.remove_entry_secure @dir
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def touch(path, contents = nil)
|
||||
FileUtils.mkpath File.dirname(path)
|
||||
return FileUtils.touch(path) if contents.nil? || contents.empty?
|
||||
File.open(path, "w") {|f| f.write contents }
|
||||
end
|
||||
|
||||
CORE_MODULES = %w[_debugger _http_agent _http_client _http_common
|
||||
_http_incoming _http_outgoing _http_server _linklist _stream_duplex
|
||||
_stream_passthrough _stream_readable _stream_transform _stream_writable
|
||||
_tls_legacy _tls_wrap assert buffer child_process cluster console
|
||||
constants crypto dgram dns domain events freelist fs http https module
|
||||
net node os path punycode querystring readline repl smalloc stream
|
||||
string_decoder sys timers tls tty url util vm zlib]
|
85
sources_non_forked/vim-node/test/plugin_test.rb
Normal file
85
sources_non_forked/vim-node/test/plugin_test.rb
Normal file
|
@ -0,0 +1,85 @@
|
|||
require_relative "./helper"
|
||||
|
||||
describe "Plugin" do
|
||||
include WithTemporaryDirectory
|
||||
|
||||
describe "b:node_root" do
|
||||
it "must be set when in same directory with package.json" do
|
||||
FileUtils.touch File.join(@dir, "package.json")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.echo("b:node_root").must_equal @dir
|
||||
end
|
||||
|
||||
it "must be set when in same directory with node_modules" do
|
||||
Dir.mkdir File.join(@dir, "node_modules")
|
||||
$vim.edit File.join(@dir, "index.js")
|
||||
$vim.echo("b:node_root").must_equal @dir
|
||||
end
|
||||
|
||||
it "must be set when ancestor directory has package.json" do
|
||||
FileUtils.touch File.join(@dir, "package.json")
|
||||
|
||||
nested = File.join(@dir, "lib", "awesomeness")
|
||||
FileUtils.mkdir_p nested
|
||||
$vim.edit File.join(nested, "index.js")
|
||||
$vim.echo("b:node_root").must_equal @dir
|
||||
end
|
||||
|
||||
it "must be set when ancestor directory has node_modules" do
|
||||
Dir.mkdir File.join(@dir, "node_modules")
|
||||
|
||||
nested = File.join(@dir, "lib", "awesomeness")
|
||||
FileUtils.mkdir_p nested
|
||||
$vim.edit File.join(nested, "index.js")
|
||||
$vim.echo("b:node_root").must_equal @dir
|
||||
end
|
||||
|
||||
it "must be set also for other filetypes" do
|
||||
FileUtils.touch File.join(@dir, "package.json")
|
||||
|
||||
$vim.edit File.join(@dir, "README.txt")
|
||||
$vim.echo("b:node_root").must_equal @dir
|
||||
end
|
||||
|
||||
it "must be set in nested Node projects" do
|
||||
nested = File.join(@dir, "node_modules", "require-guard")
|
||||
FileUtils.mkdir_p nested
|
||||
FileUtils.touch File.join(nested, "package.json")
|
||||
|
||||
test = File.join(nested, "test")
|
||||
FileUtils.mkdir_p test
|
||||
$vim.edit File.join(test, "index_test.js")
|
||||
$vim.echo("b:node_root").must_equal nested
|
||||
end
|
||||
|
||||
it "must not be set when no ancestor has one" do
|
||||
$vim.edit File.join(@dir, "index_test.js")
|
||||
$vim.echo(%(exists("b:node_root"))).must_equal "0"
|
||||
end
|
||||
|
||||
it "must be set from file, not working directory" do
|
||||
$vim.command "cd #{@dir}"
|
||||
FileUtils.touch File.join(@dir, "package.json")
|
||||
|
||||
nested = File.join(@dir, "node_modules", "require-guard")
|
||||
FileUtils.mkdir_p nested
|
||||
FileUtils.touch File.join(nested, "package.json")
|
||||
|
||||
$vim.edit File.join(nested, "index_test.js")
|
||||
$vim.echo("b:node_root").must_equal nested
|
||||
end
|
||||
|
||||
it "must detect directory as Node's when opening Vim" do
|
||||
begin
|
||||
Dir.chdir @dir
|
||||
FileUtils.touch File.join(@dir, "package.json")
|
||||
|
||||
vim = Vimrunner::Server.new(:vimrc => $vimrc).start
|
||||
vim.command("pwd").must_equal @dir
|
||||
vim.echo("b:node_root").must_equal @dir
|
||||
ensure
|
||||
vim.kill if vim
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
13
sources_non_forked/vim-node/test/vimrc
Normal file
13
sources_non_forked/vim-node/test/vimrc
Normal file
|
@ -0,0 +1,13 @@
|
|||
set nocompatible
|
||||
set noswapfile
|
||||
set nobackup
|
||||
|
||||
set runtimepath-=~/.vim
|
||||
set runtimepath-=~/.vim/after
|
||||
let &runtimepath = expand("<sfile>:p:h:h") . "," . &runtimepath
|
||||
|
||||
filetype plugin indent on
|
||||
syntax on
|
||||
|
||||
set columns=80 lines=24
|
||||
winpos 1337 0
|
|
@ -103,7 +103,7 @@ set backspace=eol,start,indent
|
|||
set whichwrap+=<,>,h,l
|
||||
|
||||
" Ignore case when searching
|
||||
set ignorecase
|
||||
" set ignorecase
|
||||
|
||||
" When searching try to be smart about cases
|
||||
set smartcase
|
||||
|
|
Loading…
Reference in a new issue