lsp icon indicating copy to clipboard operation
lsp copied to clipboard

Python module docstring not shown on autocomplete

Open Moult opened this issue 1 year ago • 4 comments

I'm not sure if this is the right channel, but I'll try :) Here's my .vimrc:

let lspServers = [#{name: 'pylsp',
                 \   filetype: 'python',
                 \   path: '/home/dion/Projects/env/bin/pylsp',
                 \   args: []
                 \ }]
autocmd User LspSetup call LspAddServer(lspServers)

If I start typing import ifcop, then press C-n, I see this (notice no docstring):

2024-05-08-102400_336x83_scrot

Then if I press backspace to remove one letter...

2024-05-08-102410_228x56_scrot

... then I press C-n again, I see this (with a docstring):

2024-05-08-102419_871x697_scrot

Why?

Note that If I do :LspHover I always see the docstring (desired). However during autocomplete, I only sometimes see the docstring.

Moult avatar May 08 '24 00:05 Moult

I can reproduce this (I don't have ifcopenshell installed, but the same thing can be reproduced when autocompleting import argparse).

When debugging this with :LspServer debug on and then later :LspServer debug messages, we can see that the server never sent the complete documentation (until hitting backspace):

05/09/24 13:38:23: Received {'id': 5, 'jsonrpc': '2.0', 'result': {'label': 'argparse', 'data': {'doc_uri': 'file:///tmp/test.py'}, 'documentation': {'kind': 'markdown', 'value': '```��```�'}, 'sortText': 'aargparse', 'kind': 9, 'insertText': 'argparse', 'detail': 'argparse'}}

Notice the effictively empty markdown documentation field, whereas if you hit backspace, and autocomplete again, the server sends the documentation.

Is this maybe a bug in pylsp instead, or do we know that this actually works with other editors (e.g. VSCode) and maybe we need to set some slightly different parameters for our requests?

vimpostor avatar May 09 '24 11:05 vimpostor

I did some asking around.

02:03:59 <Carlos Villagrasa Silanes> In PyCharm it doesn't work with any of the available options
02:04:07 <Carlos Villagrasa Silanes> image.png: https://matrix-client.matrix.org/_matrix/media/v3/download/matrix.org/MopQyzdTlvATlzSQYOindbzi
02:05:36 <Carlos Villagrasa Silanes> And if it worked, the docstring appearing while you type is opt-in and not activated by default
08:27:04 <Moult> Carlos Villagrasa Silanes: so in pycharm, as-you-type completion only shows the keyword? and only if you explicitly later on request docs on a fully typed keyword you see the docs?
16:01:56 <Carlos Villagrasa Silanes> Yes and yes. When it's fully typed you see the documentation on hover, or if you have the cursor at the end.

Moult avatar May 10 '24 07:05 Moult

I think there's more to it, this plugin also does no explicit documentation hover request, yet sometimes the documentation is returned by pylsp in the answer for completionItem/resolve and sometimes not.

Looking at https://github.com/spyder-ide/spyder/pull/16057 and https://github.com/python-lsp/python-lsp-server/pull/25 it almost looks to me, like it's supposed to work.

I also tried setting the eager variable in the config, but that was equally buggy:

#{ name: 'python', filetype: ['python'], path: 'pylsp', initializationOptions: #{ pylsp: #{plugins: #{jedi_completion: #{eager: v:true}}}} },

Looks like we may need to debug pylsp for this.

vimpostor avatar May 10 '24 19:05 vimpostor

Thanks so much for your detective work! Let me know if there is any way I can help!

On Fri, May 10, 2024 at 12:26:41PM -0700, Magnus Groß wrote:

I think there's more to it, this plugin also does no explicit documentation hover request, yet sometimes the documentation is returned by pylsp in the answer for completionItem/resolve and sometimes not.

Looking at [1]spyder-ide/spyder#16057 and [2]python-lsp/python-lsp-server#25 it almost looks to me, like it's supposed to work.

I also tried setting the eager variable in the config, but that was equally buggy: #{ name: 'python', filetype: ['python'], path: 'pylsp', initializationOptions: # { pylsp: #{plugins: #{jedi_completion: #{eager: v:true}}}} },

Looks like we may need to debug pylsp for this.

— Reply to this email directly, [3]view it on GitHub, or [4]unsubscribe. You are receiving this because you authored the thread. Message ID: @.***>

References

  1. https://github.com/spyder-ide/spyder/pull/16057
  2. https://github.com/python-lsp/python-lsp-server/pull/25
  3. https://github.com/yegappan/lsp/issues/509#issuecomment-2105155078
  4. https://github.com/notifications/unsubscribe-auth/AAAVR3X2OT3X6W62UGHQPLLZBUNPDAVCNFSM6AAAAABHL6RIU6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBVGE2TKMBXHA

Moult avatar May 11 '24 03:05 Moult