Skip to content

Commit 827f1d6

Browse files
authored
Add typescriptreact and javascriptreact to ftplugin (#117)
1 parent 85c2488 commit 827f1d6

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

ftplugin/javascriptreact/jsdoc.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
" File: jsdoc.vim
2+
" Author: NAKAMURA, Hisashi <https://github.com/sunvisor>
3+
" Author: Shinya Ohyanagi <[email protected]>
4+
" Version: 2.1.4
5+
" WebPage: http://github.com/heavenshell/vim-jsdoc/
6+
" Description: Generate JSDoc to your JavaScript, TypeScript file.
7+
" License: BSD, see LICENSE for more details.
8+
let s:save_cpo = &cpo
9+
set cpo&vim
10+
11+
" version check
12+
if !has('nvim') && (!has('channel') || !has('job'))
13+
echoerr '+channel and +job are required for jsdoc.vim'
14+
finish
15+
endif
16+
17+
command! -range=0 JsDoc call jsdoc#insert(<q-args>, <count>, <line1>, <line2>)
18+
command! JsDocFormat call jsdoc#format()
19+
nnoremap <silent> <buffer> <Plug>(jsdoc) :call jsdoc#insert()<CR>
20+
21+
let &cpo = s:save_cpo
22+
unlet s:save_cpo

ftplugin/typescriptreact/jsdoc.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
" File: jsdoc.vim
2+
" Author: NAKAMURA, Hisashi <https://github.com/sunvisor>
3+
" Author: Shinya Ohyanagi <[email protected]>
4+
" Version: 2.1.4
5+
" WebPage: http://github.com/heavenshell/vim-jsdoc/
6+
" Description: Generate JSDoc to your JavaScript, TypeScript file.
7+
" License: BSD, see LICENSE for more details.
8+
let s:save_cpo = &cpo
9+
set cpo&vim
10+
11+
" version check
12+
if !has('nvim') && (!has('channel') || !has('job'))
13+
echoerr '+channel and +job are required for jsdoc.vim'
14+
finish
15+
endif
16+
17+
command! -range=0 JsDoc call jsdoc#insert(<q-args>, <count>, <line1>, <line2>)
18+
command! JsDocFormat call jsdoc#format()
19+
nnoremap <silent> <buffer> <Plug>(jsdoc) :call jsdoc#insert()<CR>
20+
21+
let &cpo = s:save_cpo
22+
unlet s:save_cpo

tests/js.vader

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,16 @@ Expect javascript:
321321
console.log('foo')
322322
}
323323
}
324+
325+
Given javascriptreact (named function with no arg):
326+
function foo() { }
327+
328+
Execute:
329+
JsDoc
330+
:sleep 1
331+
332+
Expect javascript:
333+
/**
334+
* foo.
335+
*/
336+
function foo() { }

tests/ts.vader

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Execute:
1212
:JsDoc
1313
:sleep 1
1414

15-
Expect javascript:
15+
Expect typescript:
1616
/**
1717
* foo.
1818
*
@@ -33,7 +33,7 @@ Execute:
3333
:JsDoc
3434
:sleep 1
3535

36-
Expect javascript:
36+
Expect typescript:
3737
/**
3838
* foo.
3939
*
@@ -52,7 +52,7 @@ Execute:
5252
:JsDoc
5353
:sleep 1
5454

55-
Expect javascript:
55+
Expect typescript:
5656
/**
5757
* IFoo.
5858
*/
@@ -68,7 +68,7 @@ Execute:
6868
:JsDoc
6969
:sleep 1
7070

71-
Expect javascript:
71+
Expect typescript:
7272
/**
7373
* Bar.
7474
*
@@ -90,7 +90,7 @@ Execute:
9090
:JsDoc
9191
:sleep 1
9292

93-
Expect javascript:
93+
Expect typescript:
9494
class Bar extends Foo implements IFoo {
9595
/**
9696
* constructor.
@@ -114,7 +114,7 @@ Execute:
114114
:JsDoc
115115
:sleep 1
116116

117-
Expect javascript:
117+
Expect typescript:
118118
class Bar extends Foo implements IFoo {
119119
/**
120120
* foo.
@@ -126,3 +126,24 @@ Expect javascript:
126126
private foo(arg1: string, arg2: number = 0): void {
127127
}
128128
}
129+
130+
Given typescript (typescriptreact):
131+
function foo(foo: string = 'foo', bar: number = 1): string {
132+
return 'foo'
133+
}
134+
135+
Execute:
136+
:JsDoc
137+
:sleep 1
138+
139+
Expect typescript:
140+
/**
141+
* foo.
142+
*
143+
* @param {string} foo
144+
* @param {number} bar
145+
* @returns {string}
146+
*/
147+
function foo(foo: string = 'foo', bar: number = 1): string {
148+
return 'foo'
149+
}

0 commit comments

Comments
 (0)