11" Insert Docstring.
22" Author: Shinya Ohyanagi <sohyanagi@gmail.com>
3- " Version: 0.1.6
3+ " Version: 0.2.0
44" WebPage: http://github.com/heavenshell/vim-pydocstriong/
55" Description: Generate Python docstring to your Python script file.
66" License: BSD, see LICENSE for more details.
@@ -149,10 +149,6 @@ function! s:builddocstring(strs, indent, nested_indent)
149149 let tmpl = ' '
150150 let docstrings = []
151151 let lines = s: readtmpl (' multi' )
152- let has_return_type = 0
153- if match (lines , ' \c{{_returnType_}}\|\c{{_return_type_}}' ) != -1
154- let has_return_type = 1
155- endif
156152 for line in lines
157153 if line = ~ ' {{_header_}}'
158154 let header = substitute (line , ' {{_header_}}' , prefix, ' ' )
@@ -167,10 +163,10 @@ function! s:builddocstring(strs, indent, nested_indent)
167163 let template = line
168164 let typed = 0
169165 if match (arg, ' :' ) != -1
170- let argTemplate = join (s: readtmpl (' arg' ), ' ' )
171- let argParts = split (arg, ' :' )
172- let argTemplate = substitute (argTemplate , ' {{_name_}}' , argParts [0 ], ' g' )
173- let arg = substitute (argTemplate , ' {{_type_}}' , argParts [1 ], ' g' )
166+ let arg_template = join (s: readtmpl (' arg' ), ' ' )
167+ let arg_parts = split (arg, ' :' )
168+ let arg_template = substitute (arg_template , ' {{_name_}}' , arg_parts [0 ], ' g' )
169+ let arg = substitute (arg_template , ' {{_type_}}' , arg_parts [1 ], ' g' )
174170 let typed = 1
175171 endif
176172 let template = substitute (template, ' {{_args_}}' , arg, ' g' )
@@ -196,9 +192,6 @@ function! s:builddocstring(strs, indent, nested_indent)
196192 let template = substitute (template, ' \s$' , ' ' , ' ' )
197193 call add (docstrings, a: indent . template)
198194 endfor
199- if has_return_type == 1
200- call add (docstrings, ' ' )
201- endif
202195 endif
203196 elseif line = ~ ' {{_indent_}}'
204197 let arg = substitute (line , ' {{_indent_}}' , a: indent , ' g' )
@@ -208,7 +201,9 @@ function! s:builddocstring(strs, indent, nested_indent)
208201 let rt = substitute (line , ' {{_returnType_}}\|{{_return_type_}}' , return_type, ' ' )
209202 call add (docstrings, a: indent . rt)
210203 else
211- call remove (docstrings, -1 )
204+ if docstrings[-1 ] == ' '
205+ call remove (docstrings, -1 )
206+ endif
212207 endif
213208 elseif line == ' """' || line == " '''"
214209 call add (docstrings, a: indent . line )
0 commit comments