lsp
lsp copied to clipboard
Python module docstring not shown on autocomplete
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):
Then if I press backspace to remove one letter...
... then I press C-n again, I see this (with a docstring):
Why?
Note that If I do :LspHover I always see the docstring (desired). However during autocomplete, I only sometimes see the docstring.
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?
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.
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.
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
- https://github.com/spyder-ide/spyder/pull/16057
- https://github.com/python-lsp/python-lsp-server/pull/25
- https://github.com/yegappan/lsp/issues/509#issuecomment-2105155078
- https://github.com/notifications/unsubscribe-auth/AAAVR3X2OT3X6W62UGHQPLLZBUNPDAVCNFSM6AAAAABHL6RIU6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBVGE2TKMBXHA