|
1 | 1 | " Insert Docstring. |
2 | 2 | " Author: Shinya Ohyanagi <sohyanagi@gmail.com> |
3 | | -" Version: 0.1.0 |
| 3 | +" Version: 0.1.1 |
4 | 4 | " License: This file is placed in the public domain. |
5 | 5 | " WebPage: http://github.com/heavenshell/vim-pydocstriong/ |
6 | 6 | " Description: Generate Python docstring to your Python script file. |
@@ -163,22 +163,38 @@ function! s:builddocstring(strs, indent, nested_indent) |
163 | 163 | continue |
164 | 164 | endif |
165 | 165 | let template = line |
166 | | - |
| 166 | + let typed = 0 |
167 | 167 | if match(arg, ':') != -1 |
168 | 168 | let argTemplate = s:readtmpl('arg') |
169 | 169 | let argTemplate = join(s:readtmpl('arg'), '') |
170 | 170 | let argParts = split(arg, ':') |
171 | 171 | let argTemplate = substitute(argTemplate, '{{_name_}}', argParts[0], 'g') |
172 | 172 | let arg = substitute(argTemplate, '{{_type_}}', argParts[1], 'g') |
| 173 | + let typed = 1 |
173 | 174 | endif |
174 | | - |
175 | 175 | let template = substitute(template, '{{_args_}}', arg, 'g') |
| 176 | + if typed == 1 |
| 177 | + " Fix following bugs. |
| 178 | + " `def foo(arg: str):` generates like followings |
| 179 | + " ``` |
| 180 | + " :param arg: |
| 181 | + " :type arg: str: |
| 182 | + " ``` |
| 183 | + " Template file describes as followings |
| 184 | + " ``` |
| 185 | + " ''' |
| 186 | + " {{_header_}} |
| 187 | + " :param {{_args_}}: |
| 188 | + " :rtype: {{_returnType_}} |
| 189 | + " ''' |
| 190 | + let template = substitute(template, ':$', '', 'g') |
| 191 | + endif |
176 | 192 | let template = substitute(template, '{{_lf_}}', '\n', 'g') |
177 | 193 | let template = substitute(template, '{{_indent_}}', a:indent, 'g') |
178 | 194 | let template = substitute(template, '{{_nested_indent_}}', a:nested_indent, 'g') |
179 | 195 | call add(docstrings, a:indent . template) |
180 | 196 | endfor |
181 | | - call add(docstrings, '' ) |
| 197 | + call add(docstrings, '') |
182 | 198 | endif |
183 | 199 | elseif line =~ '{{_indent_}}' |
184 | 200 | let arg = substitute(line, '{{_indent_}}', a:indent, 'g') |
|
0 commit comments