Skip to content

Commit

Permalink
minor: rewrite/expand show_documentation (davidhalter#980)
Browse files Browse the repository at this point in the history
* minor: rewrite/expand show_documentation

* tests: improve 'documentation docstrings'
  • Loading branch information
blueyed committed Jan 17, 2020
1 parent e2abec2 commit e8790b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 11 additions & 3 deletions pythonx/jedi_vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,9 +726,17 @@ def show_documentation():
if not definitions:
echo_highlight('No documentation found for that.')
vim.command('return')
else:
docs = ['Docstring for %s\n%s\n%s' % (d.desc_with_module, '=' * 40, d.docstring())
if d.docstring() else '|No Docstring for %s|' % d for d in definitions]
return

docs = []
for d in definitions:
doc = d.docstring()
if doc:
title = 'Docstring for %s' % d.desc_with_module
underline = '=' * len(title)
docs.append('%s\n%s\n%s' % (title, underline, doc))
else:
docs.append('|No Docstring for %s|' % d)
text = ('\n' + '-' * 79 + '\n').join(docs)
vim.command('let l:doc = %s' % repr(PythonToVimStr(text)))
vim.command('let l:doc_lines = %s' % len(text.split('\n')))
Expand Down
11 changes: 10 additions & 1 deletion test/vspec/documentation.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ describe 'documentation docstrings'
normal GK
Expect bufname('%') == "__doc__"
Expect &filetype == 'rst'
let content = join(getline(1,'$'), "\n")
let header = getline(1, 2)
PythonJedi vim.vars["is_py2"] = sys.version_info[0] == 2
if g:is_py2
Expect header[0] == "Docstring for __builtin__:class ImportError"
Expect header[1] == "==========================================="
else
Expect header[0] == "Docstring for builtins:class ImportError"
Expect header[1] == "========================================"
endif
let content = join(getline(3, '$'), "\n")
Expect stridx(content, "Import can't find module") > 0
normal K
Expect bufname('%') == ''
Expand Down

0 comments on commit e8790b1

Please sign in to comment.