Squashed 'vim/bundle/jsx/' content from commit aa35d7afe

git-subtree-dir: vim/bundle/jsx
git-subtree-split: aa35d7afe901d3c85225733e2afbf5e534ef2854
main
Buddy Sandidge 10 years ago
commit 3e035ca065

2
.gitignore vendored

@ -0,0 +1,2 @@
*~
*.swp

@ -0,0 +1,59 @@
# NAME
jsx.vim - VIM support for JSX
# USAGE
Set the following command in your `.vimrc`:
```VimL
" add the repository path
set rtp+=/path/to/jsx.vim
" when you use a plugin manager (vundle or NeoBundle),
" just declare the repository path in your .vimrc
" for vundle
Bundle 'git://github.com/jsx/jsx.vim.git'
" for NeoBundle
NeoBundle 'git://github.com/jsx/jsx.vim.git'
```
# KEY BINDINGS
* `<Leader>t` (i.e. `\t` by default) in normal mode executes the current test method
* `g:jsx_no_default_key_mappings` prevents default key mappings
# CODE COMPLETION
There is an experimental code completion invoked by omni function (<code>^x^o</code>) as an interface to <code>jsx --complete</code>.
![screenshot](https://raw.github.com/jsx/jsx.vim/master/screenshot.png)
# AUTHOR
Fuji Goro (gfx) <fuji.goro@dena.jp>
# COPYRIGHT AND LICENSE
Copyright (c) 2012 DeNA, Co., Ltd (http://dena.jp/intl/).
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

@ -0,0 +1,217 @@
" Language: JSX
" Maintainer: Fuji, Goro (gfx) <fuji.goro@dena.jp>
" URL: http://github.com/jsx/jsx.vim
" License: MIT License
"
" JSX omni-complition function
let s:save_cpo = &cpo
set cpo&vim
let s:jsx_complete_ignore_syntax_type = {
\ "jsxComment" : 1,
\ "jsxLineComment" : 1,
\ "jsxStringD" : 1,
\ "jsxStringS" : 1,
\ "jsxRegExp" : 1
\ }
function! s:abbr(word, maxlen) abort
if strdisplaywidth(a:word) > a:maxlen
return a:word[0 : a:maxlen]. " ..."
else
return a:word
endif
endfunction
" borrowed from html.vim in https://github.com/mattn/webapi-vim
function! s:nr2byte(nr)
if a:nr < 0x80
return nr2char(a:nr)
elseif a:nr < 0x800
return nr2char(a:nr/64+192).nr2char(a:nr%64+128)
else
return nr2char(a:nr/4096%16+224).nr2char(a:nr/64%64+128).nr2char(a:nr%64+128)
endif
endfunction
function! s:nr2enc_char(charcode)
if &encoding == 'utf-8'
return nr2char(a:charcode)
endif
let char = s:nr2byte(a:charcode)
if strlen(char) > 1
let char = strtrans(iconv(char, 'utf-8', &encoding))
endif
return char
endfunction
function! s:format_doc(str) abort
let str = a:str
let str = substitute(str, '[ \t\r\n]*</p>[ \t\r\n]*', "\n", 'g')
let str = substitute(str, '<[^>]*>', '', 'g')
let str = substitute(str, '&gt;', '>', 'g')
let str = substitute(str, '&lt;', '<', 'g')
let str = substitute(str, '&quot;', '"', 'g')
let str = substitute(str, '&apos;', "'", 'g')
let str = substitute(str, '&nbsp;', ' ', 'g')
let str = substitute(str, '&#\(\d\+\);', '\=s:nr2enc_char(submatch(1))', 'g')
let str = substitute(str, '&amp;', '&', 'g')
return str
endfunction
function! s:add_to_info(candidate, sep, message)
if strlen(a:candidate.info) > 0
let a:candidate.info = a:candidate.info . a:sep . a:message
else
let a:candidate.info = a:message
endif
endfunction
function! s:current_word_starting_pos() abort
let line = getline('.')
let pos = col('.')
if pos == col('$')
let pos -= 1
endif
if pos > 0 && line[pos - 1] =~ '\w'
while pos > 0 && line[pos - 1] =~ '\w'
let pos -= 1
endwhile
endif
return pos
endfunction
function! s:get_data_source()
let input_content = join(getline(1, '$'), "\n")
let command = printf('%s --input-filename %s --complete %d:%d -- -',
\ get(g:, 'jsx_command', 'jsx-with-server'),
\ shellescape(bufname('%')),
\ line('.'), col('.')
\)
try
let ret = system(command, input_content)
sandbox let data_source = eval(ret)
catch
let data_source = []
endtry
return data_source
endfunction
function! s:is_completion_for_this(base)
let this_pos = col('.') - len(a:base) - len("this.") - 1
if this_pos >= 0
return stridx(getline(".")[this_pos : ], "this.") == 0
else
return 0
endif
endfunction
function! jsx#complete(findstart, base) abort
if a:findstart
" see :help complete-functions
if has_key(s:jsx_complete_ignore_syntax_type, synIDattr(synID(line('.'), col('.')-1, 0), "name"))
return -2
endif
return s:current_word_starting_pos()
endif
let data_source = s:get_data_source()
let is_completion_for_this = s:is_completion_for_this(a:base)
let max_menu_width = winwidth(winnr())
\ - wincol()
\ - get(g:, 'jsx_complete_max_menu_width', 22)
let show_private = (len(a:base) > 0 && a:base[0] == "_") || is_completion_for_this
let output = []
for candidate in data_source
if stridx(candidate.word, a:base) != 0
continue
endif
if candidate.word[0] == "_" && !show_private
continue
endif
" show overloaded functions
let candidate.dup = 1
" show mis-cased candidates
let candidate.icase = 1
let candidate.info = ""
" menu (extra information)
if has_key(candidate, "args")
" function type
let w = candidate.word . "(" . join(map(candidate.args, 'v:val.name . " : " . v:val.type'), ", ") . ")"
let candidate.abbr = s:abbr(w, max_menu_width)
let candidate.menu = ": " . candidate.returnType
let candidate.info = w . " : " . candidate.returnType
elseif has_key(candidate, "type")
" variable type
let candidate.abbr = s:abbr(candidate.word, max_menu_width)
let candidate.menu = ": " . candidate.type
let candidate.info = "var " . candidate.word . " : " . candidate.type
endif
if has_key(candidate, "doc") && strlen(candidate.doc) > 0
call s:add_to_info(candidate, "\n", s:format_doc(candidate.doc))
endif
if has_key(candidate, "definedClass")
call s:add_to_info(candidate, "\n", "[" . candidate.definedClass . "]")
endif
if strlen(candidate.info) == 0
let candidate.info = candidate.word
endif
call add(output, candidate)
endfor
return output
endfunction
function! jsx#test_it() abort
let l = line('.')
let c = col('.')
let pattern = '\(\C\<test\w\+\).*'
if search(pattern, 'bcW') == 0
echo "no test method found"
return
endif
let test_name = substitute(getline('.')[col('.')-1 : ], pattern, '\1', '')
call cursor(l, c)
let command = printf('%s --input-filename %s --test -- - %s',
\ get(g:, 'jsx_command', 'jsx'),
\ shellescape(bufname('%')),
\ test_name
\)
let input_content = join(getline(1, '$'), "\n")
echo system(command, input_content)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set tabstop=2:
" vim: set shiftwidth=2:
" vim: set et:

@ -0,0 +1,21 @@
" Vim compiler file
" Language: JSX
" Maintainer:
if exists("current_compiler")
finish
endif
let current_compiler = "jsx"
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
command -nargs=* CompilerSet setlocal <args>
endif
let s:cpo_save = &cpo
set cpo&vim
CompilerSet makeprg=jsx\ --test\ %
CompilerSet errorformat=[%f:%l:%c]\ %m
let &cpo = s:cpo_save
unlet s:cpo_save

@ -0,0 +1,7 @@
--langdef=JSX
--langmap=jsx:.jsx
--regex-jsx=/^[ \t]*import[ \t]+([^;]+)/\1/r,import,imports/
--regex-jsx=/^[ \t]*([a-z]+[ \t]+)*function[ \t]+([A-Za-z0-9_]+[ \t]*[^{;]*)/\2/f,function,functions/
--regex-jsx=/^[ \t]*([a-z]+[ \t]+)*class[ \t]+([A-Za-z0-9_]+)[ \t]*([^)])/\2/c,class,classes/
--regex-jsx=/^[ \t]*([a-z]+[ \t]+)*interface[ \t]+([A-Za-z0-9_]+)[ \t]*([^)])/\2/i,interface,interfaces/
--regex-jsx=/^[ \t]*([a-z]+[ \t]+)*mixin[ \t]+([A-Za-z0-9_]+)[ \t]*([^)])/\2/m,mixin,mixins/

@ -0,0 +1,54 @@
interface I {
abstract function foo(a : int) : void;
}
mixin M implements I {
override function foo(a : int) : void {
log a;
}
}
class _Main {
static function main(args : string[]) : void {
var i0 = 0xabcdef;
var i0 = 0XABCDEF;
var n0 = 3.14;
var n1 = 1e100;
var n2 = 1e+10;
var n3 = 1e-10;
var r0 = /foo/;
var r1 = /foo/m;
var r2 = /foo/i;
var r3 = /foo/g;
var r4 = /foo/gim;
var r5 = /\bfoo\b/;
var a0xff = -0;
var a1e10 = +0;
var s0 = "\x0a\x0d";
var s1 = "\u000d";
var ms = """
foo
bar
""";
log true;
log false;
log null;
log Infinity;
log NaN;
try {
throw new Error();
}
catch (e : Error) {
}
finally {
log "finally";
}
}
}

@ -0,0 +1,43 @@
" Language: JSX
" Maintainer: Fuji, Goro (gfx) <fuji.goro@dena.jp>
" URL: http://github.com/jsx/jsx.vim
" License: MIT License
"
setlocal omnifunc=jsx#complete
nnoremap <silent> <plug>(jsx-test) :<c-u>call jsx#test_it()<CR>
if !get(g:, 'jsx_no_default_key_mappings', 0)
nmap <buffer> <leader>t <plug>(jsx-test)
endif
compiler jsx
" Tagbar http://majutsushi.github.com/tagbar/
let g:tagbar_type_jsx = {}
let g:tagbar_type_jsx.ctagstype = "jsx"
let g:tagbar_type_jsx.kinds = [
\ 'r:imports',
\ 'i:interfaces',
\ 'm:mixins',
\ 'c:classes',
\ 'f:functions'
\ ]
let g:tagbar_type_jsx.sro = '.'
"let g:tagbar_type_jsx.kind2scope = {
" \ 'i' : 'interface',
" \ 'm' : 'mixin',
" \ 'c' : 'class'
"\ }
"let g:tagbar_type_jsx.scope2kind = {
" \ 'interface' : 'i',
" \ 'mixin' : 'm',
" \ 'class' : 'c'
"\ }
let g:tagbar_type_jsx.sort = 0
let g:tagbar_type_jsx.deffile = expand('<sfile>:p:h:h') . '/ctags/jsx.conf'
" End of Tagbar setting

@ -0,0 +1,13 @@
" Vim indent file
" Language: JSX
" Maintainer:
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal cindent
setlocal cinoptions+=j1,J1
let b:undo_indent = "setl cin<"

@ -0,0 +1,10 @@
" Language: JSX
" Maintainer: Fuji, Goro (gfx) <fuji.goro@dena.jp>
" URL: http://github.com/jsx/jsx.vim
" License: MIT License
autocmd! BufRead,BufNewFile *.{jsx,jx} setlocal filetype=jsx
autocmd! BufNewFile *.jsx 0r <sfile>:h/../template/jsx-app.jsx
autocmd! BufNewFile lib/*.jsx 0r <sfile>:h/../template/jsx-module.jsx
autocmd! BufNewFile t/*.jsx 0r <sfile>:h/../template/jsx-test.jsx

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

@ -0,0 +1,152 @@
" Vim syntax file
" Language: JSX
" Maintainer: Fuji, Goro (gfx) <fuji.goro@dena.jp>
" URL: http://github.com/jsx/jsx.vim
" License: MIT License
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
" tuning parameters:
if !exists("main_syntax")
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
let main_syntax = 'jsx'
endif
" Drop fold if it set but vim doesn't support it.
if version < 600 && exists("jsx_fold")
unlet jsx_fold
endif
" jsx
syn keyword jsxCommentTodo contained TODO FIXME XXX TBD
syn match jsxLineComment "\/\/.*" contains=@Spell,jsxCommentTodo
syn match jsxCommentSkip "^[ \t]*\*\($\|[ \t]\+\)"
syn region jsxComment start="/\*" end="\*/" contains=@Spell,jsxCommentTodo
syn match jsxEscape /\\x\x\{2\}\|\\u\x\{4\}\|\\./
syn region jsxString start=+"+ skip=+\\\\\|\\"+ end=+"\|$+ contains=jsxEscape,@Special
syn region jsxString start=+'+ skip=+\\\\\|\\'+ end=+'\|$+ contains=jsxEscape,@htmlPreproc
syn region jsxString start=+"""+ end=+"""+ keepend contains=jsxEscape,@htmlPreproc
syn region jsxString start=+'''+ end=+'''+ keepend contains=jsxEscape,@htmlPreproc
" 15.10.1 Patterns (ECMA 262 5th)
syn match jsxRegExpMeta /\\[\\bwWsSdD]/
syn region jsxRegExp start=+/[^/*]+me=e-1 skip=+\\\\\|\\/+ end=+/[gim]*\s*$+ end=+/[gim]*\s*[;.,)\]}]+me=e-1 contains=@htmlPreproc,jsxRegExpMeta,jsxEscape oneline
" see the JSX parser
syn match jsxInteger /\<\d\+\>\|\<0[xX][0-9a-fA-F]\+\>/
syn match jsxFloat /\<\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/
syn match jsxFloatX /\<\d\+\%([eE][+-]\=\d\+\)\>/
syn keyword jsxSpecialNumbers NaN Infinity
syn keyword jsxConditional if else switch
syn keyword jsxRepeat while for do
syn keyword jsxBranch break continue
syn keyword jsxOperator new delete in instanceof typeof as __noconvert__
syn keyword jsxType Array boolean Boolean Date number Number Map int Object string String RegExp JSON Nullable variant void JSX Transferable ArrayBuffer ArrayBufferView Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array DataView
syn keyword jsxException Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
syn keyword jsxStatement return var const yield
syn keyword jsxBoolean true false
syn keyword jsxNull null
syn keyword jsxIdentifier this super __FILE__ __LINE__
syn keyword jsxLabel case default
syn keyword jsxException try catch finally throw
syn keyword jsxClass class interface mixin
syn keyword jsxModifiers final override native __fake__ extends abstract static implements __readonly__ __pure__
syn keyword jsxImport import from into
syn keyword jsxEntryPoint _Main _Test
" reserved by ECMA-262 but not used in JSX
syn keyword jsxReserved enum export let private public protected arguments with
" reserved by Google Closure Compiler
" defined in src/com/google/javascript/rhino/TokenStream.java
syn keyword jsxGCCReserved byte char double float long short goto synchronized throws transient volatile
syn keyword jsxDebug debugger assert log
" jsxdoc
syn region jsxDocComment start="/\*\*" end="\*/" contains=@Spell,jsxDocTags,jsxCommentTodo
syn match jsxDocTags contained /@\(param\|return\)\>/
syn match jsxDocTags contained /@\(see\|deprecated\|since\)\>/
syn match jsxDocTags contained /@\(author\|version\)\>/
if exists("jsx_fold")
syn match jsxFunction "\<function\>"
syn region jsxFunctionFold start="\<function\>.*[^};]$" end="^\z1}.*$" transparent fold keepend
syn sync match jsxSync grouphere jsxFunctionFold "\<function\>"
syn sync match jsxSync grouphere NONE "^}"
setlocal foldmethod=syntax
setlocal foldtext=getline(v:foldstart)
else
syn keyword jsxFunction function
syn match jsxBraces "[{}\[\]]"
syn match jsxParens "[()]"
endif
syn sync fromstart
syn sync maxlines=100
if main_syntax == "jsx"
syn sync ccomment jsxComment
endif
" 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_jsx_syn_inits")
if version < 508
let did_jsx_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink jsxDocComment Comment
HiLink jsxDocTags Special
HiLink jsxComment Comment
HiLink jsxLineComment Comment
HiLink jsxCommentTodo Todo
HiLink jsxEscape Special
HiLink jsxString String
HiLink jsxInteger Number
HiLink jsxFloat Number
HiLink jsxFloatX Number
HiLink jsxSpecialNumbers Number
HiLink jsxConditional Conditional
HiLink jsxRepeat Repeat
HiLink jsxBranch Conditional
HiLink jsxOperator Operator
HiLink jsxType Type
HiLink jsxStatement Statement
HiLink jsxFunction Function
HiLink jsxBraces Function
HiLink jsxNull Constant
HiLink jsxBoolean Boolean
HiLink jsxRegExp String
HiLink jsxIdentifier Identifier
HiLink jsxLabel Label
HiLink jsxException Exception
HiLink jsxClass Structure
HiLink jsxModifiers Structure
HiLink jsxImport Special
HiLink jsxEntryPoint Keyword
HiLink jsxReserved Error
HiLink jsxGCCReserved Error
HiLink jsxDebug Debug
delcommand HiLink
endif
let b:current_syntax = 'jsx'
if main_syntax == 'jsx'
unlet main_syntax
endif
" vim: ts=8
" vim: noexpandtab

@ -0,0 +1,11 @@
/***
* A JSX application.
*/
class _Main {
static function main(args : string[]) : void {
log "Hello, world!";
}
}
// vim: set tabstop=2 shiftwidth=2 expandtab:

@ -0,0 +1,25 @@
/***
* A JSX module.
*/
/**
* The class of this module.
*/
class Foo {
/**
* The constructor.
*/
function constructor() {
}
/**
* Do nothing.
*/
function method() : void {
}
}
// vim: set tabstop=2 shiftwidth=2 expandtab:

@ -0,0 +1,11 @@
import "test-case.jsx";
class _Test extends TestCase {
function testHello() : void {
var got = "foo bar";
this.expect(got).toBe("Hello, world!");
}
}
// vim: set tabstop=2 shiftwidth=2 expandtab:
Loading…
Cancel
Save