Skip to content
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
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 0.1.1
-------------
Released on Feb 12th 2017

- Fix bug
If none typed arg, lack of last `:`.
see https://github.com/heavenshell/vim-pydocstring/issues/17

Version 0.1.0
-------------
Released on Dec 25th 2016
Expand Down
24 changes: 20 additions & 4 deletions autoload/pydocstring.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" Insert Docstring.
" Author: Shinya Ohyanagi <sohyanagi@gmail.com>
" Version: 0.1.0
" Version: 0.1.1
" License: This file is placed in the public domain.
" WebPage: http://github.com/heavenshell/vim-pydocstriong/
" Description: Generate Python docstring to your Python script file.
Expand Down Expand Up @@ -163,22 +163,38 @@ function! s:builddocstring(strs, indent, nested_indent)
continue
endif
let template = line

let typed = 0
if match(arg, ':') != -1
let argTemplate = s:readtmpl('arg')
let argTemplate = join(s:readtmpl('arg'), '')
let argParts = split(arg, ':')
let argTemplate = substitute(argTemplate, '{{_name_}}', argParts[0], 'g')
let arg = substitute(argTemplate, '{{_type_}}', argParts[1], 'g')
let typed = 1
endif

let template = substitute(template, '{{_args_}}', arg, 'g')
if typed == 1
" Fix following bugs.
" `def foo(arg: str):` generates like followings
" ```
" :param arg:
" :type arg: str:
" ```
" Template file describes as followings
" ```
" '''
" {{_header_}}
" :param {{_args_}}:
" :rtype: {{_returnType_}}
" '''
let template = substitute(template, ':$', '', 'g')
endif
let template = substitute(template, '{{_lf_}}', '\n', 'g')
let template = substitute(template, '{{_indent_}}', a:indent, 'g')
let template = substitute(template, '{{_nested_indent_}}', a:nested_indent, 'g')
call add(docstrings, a:indent . template)
endfor
call add(docstrings, '' )
call add(docstrings, '')
endif
elseif line =~ '{{_indent_}}'
let arg = substitute(line, '{{_indent_}}', a:indent, 'g')
Expand Down
2 changes: 1 addition & 1 deletion doc/pydocstring.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*pydocstring.txt* Generate Python docstring to your Python code.

Version: 0.1.0
Version: 0.1.1
Author: Shinya Ohynagi <sohyanagi@gmail.com>
Repository: http://github.com/heavenshell/vim-pydocstring/
License: BSD, see LICENSE for more details.
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/python/pydocstring.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" File: pydocstring.vim
" Author: Shinya Ohyanagi <sohyanagi@gmail.com>
" Version: 0.1.0
" Version: 0.1.1
" WebPage: http://github.com/heavenshell/vim-pydocstriong/
" Description: Generate Python docstring to your Python script file.
" License: BSD, see LICENSE for more details.
Expand Down
2 changes: 1 addition & 1 deletion template/pydocstring/multi.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""{{_header_}}
:param {{_args_}}
:param {{_args_}}:
:rtype: {{_returnType_}}
"""
8 changes: 4 additions & 4 deletions test/type-hint.vader
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Expect python:
def foo(sample_var) -> str:
"""foo

:param sample_var
:param sample_var:

:rtype: str
"""
Expand All @@ -41,8 +41,8 @@ Expect python:
def foo(arg1, arg2) -> str:
"""foo

:param arg1
:param arg2
:param arg1:
:param arg2:

:rtype: str
"""
Expand Down Expand Up @@ -100,7 +100,7 @@ Expect python:

:param n:
:type n: int
:param arg
:param arg:

:rtype: int
"""
Expand Down