Skip to content

Fix PydocstringFormat deletes file contents if docstrings already present #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 12, 2020
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: 7 additions & 1 deletion autoload/pydocstring.vim
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ endfunction

function! s:exit_callback(msg) abort
unlet s:job " Needed for Neovim
if len(s:results)
let length = len(s:results)
if length
if length == 1 && s:results[0] == ''
let s:results = []
return
endif
let view = winsaveview()
silent execute '% delete'
call setline(1, s:results)
Expand All @@ -94,6 +99,7 @@ function! s:execute(cmd, lines, indent, start_lineno, cb, ex_cb) abort
return
endif

let s:results = []
if has('nvim')
if exists('s:job')
call jobstop(s:job)
Expand Down
37 changes: 37 additions & 0 deletions tests/format.vader
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,40 @@ Expect python:
:param arg2:
"""
pass


Given python (Format all twice):
class Foo:
def foo(arg1):
pass


def bar(arg1, arg2):
pass


Execute:
:PydocstringFormat
:sleep 1
:PydocstringFormat
:sleep 1

Expect python:
class Foo:
"""Foo."""

def foo(arg1):
"""foo.

:param arg1:
"""
pass


def bar(arg1, arg2):
"""bar.

:param arg1:
:param arg2:
"""
pass