Skip to content

Add typescriptreact and javascriptreact to ftplugin #117

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions ftplugin/javascriptreact/jsdoc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
" File: jsdoc.vim
" Author: NAKAMURA, Hisashi <https://github.com/sunvisor>
" Author: Shinya Ohyanagi <[email protected]>
" Version: 2.1.4
" WebPage: http://github.com/heavenshell/vim-jsdoc/
" Description: Generate JSDoc to your JavaScript, TypeScript file.
" License: BSD, see LICENSE for more details.
let s:save_cpo = &cpo
set cpo&vim

" version check
if !has('nvim') && (!has('channel') || !has('job'))
echoerr '+channel and +job are required for jsdoc.vim'
finish
endif

command! -range=0 JsDoc call jsdoc#insert(<q-args>, <count>, <line1>, <line2>)
command! JsDocFormat call jsdoc#format()
nnoremap <silent> <buffer> <Plug>(jsdoc) :call jsdoc#insert()<CR>

let &cpo = s:save_cpo
unlet s:save_cpo
22 changes: 22 additions & 0 deletions ftplugin/typescriptreact/jsdoc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
" File: jsdoc.vim
" Author: NAKAMURA, Hisashi <https://github.com/sunvisor>
" Author: Shinya Ohyanagi <[email protected]>
" Version: 2.1.4
" WebPage: http://github.com/heavenshell/vim-jsdoc/
" Description: Generate JSDoc to your JavaScript, TypeScript file.
" License: BSD, see LICENSE for more details.
let s:save_cpo = &cpo
set cpo&vim

" version check
if !has('nvim') && (!has('channel') || !has('job'))
echoerr '+channel and +job are required for jsdoc.vim'
finish
endif

command! -range=0 JsDoc call jsdoc#insert(<q-args>, <count>, <line1>, <line2>)
command! JsDocFormat call jsdoc#format()
nnoremap <silent> <buffer> <Plug>(jsdoc) :call jsdoc#insert()<CR>

let &cpo = s:save_cpo
unlet s:save_cpo
13 changes: 13 additions & 0 deletions tests/js.vader
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,16 @@ Expect javascript:
console.log('foo')
}
}

Given javascriptreact (named function with no arg):
function foo() { }

Execute:
JsDoc
:sleep 1

Expect javascript:
/**
* foo.
*/
function foo() { }
33 changes: 27 additions & 6 deletions tests/ts.vader
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Execute:
:JsDoc
:sleep 1

Expect javascript:
Expect typescript:
/**
* foo.
*
Expand All @@ -33,7 +33,7 @@ Execute:
:JsDoc
:sleep 1

Expect javascript:
Expect typescript:
/**
* foo.
*
Expand All @@ -52,7 +52,7 @@ Execute:
:JsDoc
:sleep 1

Expect javascript:
Expect typescript:
/**
* IFoo.
*/
Expand All @@ -68,7 +68,7 @@ Execute:
:JsDoc
:sleep 1

Expect javascript:
Expect typescript:
/**
* Bar.
*
Expand All @@ -90,7 +90,7 @@ Execute:
:JsDoc
:sleep 1

Expect javascript:
Expect typescript:
class Bar extends Foo implements IFoo {
/**
* constructor.
Expand All @@ -114,7 +114,7 @@ Execute:
:JsDoc
:sleep 1

Expect javascript:
Expect typescript:
class Bar extends Foo implements IFoo {
/**
* foo.
Expand All @@ -126,3 +126,24 @@ Expect javascript:
private foo(arg1: string, arg2: number = 0): void {
}
}

Given typescript (typescriptreact):
function foo(foo: string = 'foo', bar: number = 1): string {
return 'foo'
}

Execute:
:JsDoc
:sleep 1

Expect typescript:
/**
* foo.
*
* @param {string} foo
* @param {number} bar
* @returns {string}
*/
function foo(foo: string = 'foo', bar: number = 1): string {
return 'foo'
}