Skip to content

Commit b74a932

Browse files
authored
Topic/async (#101)
* Fix async
1 parent 5bbe872 commit b74a932

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

autoload/jsdoc.vim

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ let g:jsdoc_lehre_path = get(
1616
\ )
1717

1818
let s:is_method_regex = '^.\{-}\s*\([a-zA-Z_$][a-zA-Z0-9_$]*\)\s*(\s*\([^)]*\)\s*).*$'
19+
let s:is_declarelation = '^.\{-}=\s*\(\([a-zA-Z_$][a-zA-Z0-9_$]*\)\s*(\s*\([^)]*\)\s*)\|(\s*\([^)]*\)\s*\).*$'
1920
let s:registered_callback = ''
2021
let s:results = []
2122
let s:vim = {}
@@ -73,7 +74,7 @@ function! s:callback(msg, start_lineno, is_method) abort
7374
let i = 0
7475
let length = len(docs)
7576
for d in docs
76-
" If generate methods's signature, jsdoc.vim would add dummy Class
77+
" If generate methods's signature, jsdoc.vim would add dummy Class
7778
" signature. So ignore it.
7879
if i == 0 && a:is_method
7980
call s:insert_doc(d, a:start_lineno)
@@ -169,7 +170,7 @@ function! jsdoc#insert(...) abort
169170
if is_not_range
170171
let line = getline('.')
171172
let is_method = line =~ s:is_method_regex && line !~ 'function(.*)\|function [A-z0-9_]\+(.*)\|function [A-z0-9_]\+\s\+(.*)'
172-
if is_method
173+
if is_method && line !~ s:is_declarelation
173174
let lines = printf("%s\n%s", 'class ForJsDocDummyClass {', lines)
174175
endif
175176
endif

tests/js.vader

+18
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,24 @@ Expect javascript:
172172
*/
173173
function foo(arg, arg1 = 'foo', arg2 = 100) {}
174174

175+
176+
Given javascript (async):
177+
const foo = async foo(arg, arg1, arg2) => {}
178+
179+
Execute:
180+
:JsDoc
181+
:sleep 1
182+
183+
Expect javascript:
184+
/**
185+
* foo.
186+
*
187+
* @param {} arg
188+
* @param {} arg1
189+
* @param {} arg2
190+
*/
191+
const foo = async foo(arg, arg1, arg2) => {}
192+
175193
Given javascript (export default function):
176194
export default function (arg1, arg2) {}
177195

0 commit comments

Comments
 (0)