Skip to content
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

pydoc support popup or float window? #1088

Open
Freed-Wu opened this issue May 9, 2020 · 11 comments
Open

pydoc support popup or float window? #1088

Freed-Wu opened this issue May 9, 2020 · 11 comments
Labels

Comments

@Freed-Wu
Copy link

@Freed-Wu Freed-Wu commented May 9, 2020

image

thanks!

@blayz3r
Copy link

@blayz3r blayz3r commented May 10, 2020

In the mean time I am using this hack:

image

autocmd FileType python nnoremap <buffer> K :call PyDocVim()<CR>

function! PyDocVim()
python3 << EOF
import jedi

curfile = vim.current.buffer.name
row = vim.current.window.cursor[0]
col= vim.current.window.cursor[1]

script = jedi.Script(
    source=None,
    path=curfile,
    line=row,
    column=col)

try:
    definitions = script.goto_definitions()
except Exception:
    # print to stdout, will be in :messages
    definitions = []
    print("Exception, this shouldn't happen.")
    print(traceback.format_exc())

    if not definitions:
        echo_highlight("No documentation found for that.")
        vim.command("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 docWidth = %s" % len(title))
vim.command("let doc_lines = %s" % len(text.split("\n")))
EOF
    "Scroll
    function! s:popup_filter(winid, key)
        if a:key ==# "\<c-k>"
            call win_execute(a:winid, "normal! \<c-y>")
            return v:true
        elseif a:key ==# "\<c-j>"
            call win_execute(a:winid, "normal! \<c-e>")
            return v:true
        elseif a:key ==# 'q' || a:key ==# 'x'
            return popup_filter_menu(a:winid, 'x')
        endif
        return v:false
    endfunction

    let lines = py3eval('text')
    let winid = popup_create(lines->split('\n'), #{
            \ filter: function('s:popup_filter'),
            \ pos: 'botleft',
            \ line: 'cursor-1',
            \ col: 'cursor',
            \ moved: 'any',
            \ border: [1,1,1,1,1,1,1,1],
            \ borderchars: ['', '', '', '', '', '', '', ''],
            \ borderhighlight: ['Todo'],    
            \ padding: [0,1,0,1],
            \ firstline: 1,
            \ scrollbar: 1,
            \ minwidth: docWidth,
            \ maxwidth: 74,
            \ minheight: doc_lines,
            \ maxheight: 20,
            \ mapping: 0,
            \ })

    call setbufvar(winbufnr(winid), '&syntax','rst')
    call setwinvar(winid, '&wincolor', 'Normal')
endfunction
@Freed-Wu
Copy link
Author

@Freed-Wu Freed-Wu commented May 11, 2020

looks so cooool!
although i met some error

|| Error detected while processing function
|| PyDocVim[38]
|| Traceback (most recent call last):
||   File "<string>", line 11, in <module>
||   File "/usr/lib64/python3.6/site-packages/jedi/api/__init__.py", line 95, in __init__
||     with open(path, 'rb') as f:
|| FileNotFoundError: [Errno 2] No such file or directory: ''
|| line   53:
|| Traceback (most recent call last):
||   File "<string>", line 1, in <module>
|| NameError: name 'text' is not defined
|| E858: Eval did not return a valid python object
|| line   54:
|| E121: Undefined variable: docWidth
|| E116: Invalid arguments for function popup_create(lines->split('\n'), #{ filter: function('s:popup_filter'), pos: 'botleft', line: 'cursor-1', col: 'cursor', moved: 'any', border: [1,1,1,1,1,1,1,1], borderchars: ['─', '│', '─', '│', '┌', '┐', '┘', '└'], borderhighlight: ['Todo'],     padding: [0,1,0,1], firstline: 1, scrollbar: 1, minwidth: docWidth, maxwidth: 74, minheight: doc_lines, maxheight: 20, mapping: 0, })
|| line   73:
|| E121: Undefined variable: winid
|| E116: Invalid arguments for function winbufnr(winid), '&syntax','rst')
|| E116: Invalid arguments for function setbufvar
|| line   74:
|| E121: Undefined variable: winid
|| E116: Invalid arguments for function setwinvar

it looks like related to jedi.

OS: Gentoo Linux 5.4
vi: vim 8.2.0114
py: cpython 3.6.10

@blayz3r
Copy link

@blayz3r blayz3r commented May 12, 2020

What does your code look like? does it work on other words?

@qazip
Copy link

@qazip qazip commented May 12, 2020

This is the error I get. I tried K on the "print" word. I also tried on other words and the same thing happens. Should I have any additional plugin for this to work?

floating_doc

@blayz3r
Copy link

@blayz3r blayz3r commented May 12, 2020

You could try updating jedi, why is vim calling pynvim? Are you using Neovim(I don't expect the hack to work there)

@diraol
Copy link
Contributor

@diraol diraol commented May 12, 2020

To be honest, I don't know exactly what I did in my personal setup but I do have floating documentation for python codes... not sure if provided by python-mode or some mix of python-mode with other plugins though.

screenshot_2020-05-12_11h38m57s

My vim setup is here, and I haven't added any special "patch". But again, I don't know which plugin is exactly providing that... 😂
https://gitlab.com/diraol/my_vim

@qazip
Copy link

@qazip qazip commented May 12, 2020

You could try updating jedi, why is vim calling pynvim? Are you using Neovim(I don't expect the hack to work there)

Oh. Yes, indeed I am using NeoVim.

@qazip
Copy link

@qazip qazip commented May 12, 2020

To be honest, I don't know exactly what I did in my personal setup but I do have floating documentation for python codes... not sure if provided by python-mode or some mix of python-mode with other plugins though.

screenshot_2020-05-12_11h38m57s

My vim setup is here, and I haven't added any special "patch". But again, I don't know which plugin is exactly providing that... joy
https://gitlab.com/diraol/my_vim

Do you use vim or nvim?

@blayz3r
Copy link

@blayz3r blayz3r commented May 13, 2020

To be honest, I don't know exactly what I did in my personal setup but I do have floating documentation for python codes... not sure if provided by python-mode or some mix of python-mode with other plugins though.

screenshot_2020-05-12_11h38m57s

My vim setup is here, and I haven't added any special "patch". But again, I don't know which plugin is exactly providing that... 😂
https://gitlab.com/diraol/my_vim

Looks like YCM

@diraol
Copy link
Contributor

@diraol diraol commented May 13, 2020

Do you use vim or nvim?

vim

Looks like YCM

Hum.... good catch, could be indeed.

@stale
Copy link

@stale stale bot commented Oct 11, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the inactive label Oct 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.