Skip to content

Commit f4cc30c

Browse files
authored
Merge pull request #21 from heavenshell/fix/issue_19
Fix/issue 19
2 parents 91832bf + a3f9870 commit f4cc30c

File tree

12 files changed

+73
-10
lines changed

12 files changed

+73
-10
lines changed

CHANGES.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Version 0.1.2
2+
-------------
3+
Released on Mar 25th 2017
4+
5+
- Fix bug
6+
Ignored indent when docstring start with `'''`.
7+
Delete blank line if `{{_returnType_}}` not exists.
8+
see https://github.com/heavenshell/vim-pydocstring/issues/19
9+
Thx @brainscience
10+
111
Version 0.1.1
212
-------------
313
Released on Feb 12th 2017

autoload/pydocstring.vim

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
" Insert Docstring.
22
" Author: Shinya Ohyanagi <[email protected]>
3-
" Version: 0.1.1
4-
" License: This file is placed in the public domain.
3+
" Version: 0.1.2
54
" WebPage: http://github.com/heavenshell/vim-pydocstriong/
65
" Description: Generate Python docstring to your Python script file.
76
" License: BSD, see LICENSE for more details.
@@ -61,7 +60,7 @@ function! s:parseFunc(type, line)
6160

6261
let arrowIndex = match(a:line, "->")
6362
if arrowIndex != -1
64-
let substring = strpart(a:line, arrowIndex+2)
63+
let substring = strpart(a:line, arrowIndex + 2)
6564
let returnType = substitute(substring, '\W*', '', 'g')
6665
else
6766
let returnType = ''
@@ -150,11 +149,15 @@ function! s:builddocstring(strs, indent, nested_indent)
150149
let tmpl = ''
151150
let docstrings = []
152151
let lines = s:readtmpl('multi')
152+
let has_return_type = 0
153+
if match(lines, '\c{{_returnType_}}') != -1
154+
let has_return_type = 1
155+
endif
153156
for line in lines
154157
if line =~ '{{_header_}}'
155158
let header = substitute(line, '{{_header_}}', prefix, '')
156159
call add(docstrings, a:indent . header)
157-
call add(docstrings, '' )
160+
call add(docstrings, '')
158161
elseif line =~ '{{_args_}}'
159162
if len(args) != 0
160163
for arg in args
@@ -194,7 +197,9 @@ function! s:builddocstring(strs, indent, nested_indent)
194197
let template = substitute(template, '{{_nested_indent_}}', a:nested_indent, 'g')
195198
call add(docstrings, a:indent . template)
196199
endfor
197-
call add(docstrings, '')
200+
if has_return_type == 1
201+
call add(docstrings, '')
202+
endif
198203
endif
199204
elseif line =~ '{{_indent_}}'
200205
let arg = substitute(line, '{{_indent_}}', a:indent, 'g')
@@ -206,7 +211,7 @@ function! s:builddocstring(strs, indent, nested_indent)
206211
else
207212
call remove(docstrings, -1)
208213
endif
209-
elseif line == '"""'
214+
elseif line == '"""' || line == "'''"
210215
call add(docstrings, a:indent . line)
211216
else
212217
call add(docstrings, line)

doc/pydocstring.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
*pydocstring.txt* Generate Python docstring to your Python code.
22

3-
Version: 0.1.1
3+
Version: 0.1.2
44
Author: Shinya Ohynagi <[email protected]>
55
Repository: http://github.com/heavenshell/vim-pydocstring/
66
License: BSD, see LICENSE for more details.

ftplugin/python/pydocstring.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" File: pydocstring.vim
22
" Author: Shinya Ohyanagi <[email protected]>
3-
" Version: 0.1.1
3+
" Version: 0.1.2
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.

test/custom-template.vader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# vim:set et sw=4 ts=4 tw=79:
22
Execute (Setup template dir):
33
Save g:pydocstring_templates_dir
4-
let g:pydocstring_templates_dir = './test-template/'
4+
let g:pydocstring_templates_dir = './templates/custom-templates/'
55

66
Given python (def foo):
77
def foo():

test/issue19.vader

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# vim:set et sw=4 ts=4 tw=79:
2+
Execute (Setup template dir):
3+
Save g:pydocstring_templates_dir
4+
let g:pydocstring_templates_dir = './templates/issue19/'
5+
6+
Given python (def foo with 1 params):
7+
def foo(arg1):
8+
pass
9+
10+
Execute:
11+
Pydocstring
12+
13+
Expect python:
14+
def foo(arg1):
15+
'''
16+
foo
17+
18+
Args:
19+
arg1:
20+
'''
21+
pass
22+
23+
24+
Given python (def foo with 2 params):
25+
def foo(arg1, arg2):
26+
pass
27+
28+
Execute:
29+
Pydocstring
30+
31+
Expect python:
32+
def foo(arg1, arg2):
33+
'''
34+
foo
35+
36+
Args:
37+
arg1:
38+
arg2:
39+
'''
40+
pass
41+
42+
Execute (Clear pydocstring_templates_dir):
43+
Restore
File renamed without changes.

0 commit comments

Comments
 (0)