frymye · 2022-10-25 16:29
Yesterday I was trying lsp-mode. After getting a bit annoyed with my laptop's fan always getting activated, I decided to try eglot. So far it feels much more lightweight.
I'm having trouble getting it to do some things though.
For context, I use pyvenv to manage my virtual environments:
`(use-package pyvenv:ensure t:config(pyvenv-mode 1)(pyvenv-activate "~/miniconda3/envs/myenv/"))`
I have done both `conda install python-lsp-server[all] -c conda-forge` and `conda install pyright` in this environment.
If I use pyright-langserver, then a lot of imports are "unknown".
If I use pylsp, then those imports seem to work, but I get some funny autocompletion behaviour.
`import numpy as np`
`np.lin`
This says "no completion found". But
`from numpy import linalg`
`linalg.`
This works as expected, and I get reasonable suggestions for completions.
​
Can someone tell me what's going on here and I to get this working? I was hoping things would work right out of the box, but...
JDRiverRun · 2022-10-25 22:29
Sounds like a venv issue, assuming you install your packages that way. With pyright, look in your eglot events buffer and search for :venvPath "something".
If nothing is there, you may need to configure eglot to send the correct venv info. I don't use pyvenv, but it's not hard to set with eglot-workspace-configuration. Something like (for whatever venv and interpreter):
(list (cons :python (list :venvPath venv-path :venv ".venv" :pythonPath venv-interp)))
You could also set this in pyright's global or per-workspace configs.
frymye · 2022-10-26 00:16
Thanks for the help. I don't see "venv" anywhere in eglot's event buffer. I used conda to install my virtualenv. I do see
`(:message "Running language server: /home/me/miniconda3/envs/myenv/bin/pyright-langserver --stdio")`
in the event buffer, which looks ok to me... I also tried added the env path and name to pyrightconfig.json, but that doesn't seem to help.
Walheimat · 2022-10-26 19:22
Does completion work for other packages or is it only `numpy`?
frymye · 2022-10-26 20:03
As far as I can tell, with pylsp completion is working for everything except numpy. In fact, completion for \`np.linalg.\` is working. But \`np.\` will show "No completion found".
aminevsaziz · 2022-10-28 23:10
Can you elaborate a simple example on setting pyright global or per-workspace config.
P.s: I'm very new emac and eglot!
aminevsaziz · 2022-10-28 23:16
How did you manage to setup eglot with pyright I always get "server tried to register unsported capability 'workspace/didchangeworkspacefolder' and server exist.
BTW in the eglot-server-programs I set it to (python-mode . ("pyright-langserver" "stdio"))
JDRiverRun · 2022-10-29 01:25
Here's what I do. This uses a custom package I've not yet released called *simple-venv*, but you ought to be able to modify it for whatever you use.
(defun my/eglot-workspace-config (server)
(if-let ((venv (simple-venv-find))
((not (eq venv 'none)))
(vp (file-name-directory venv))
(vn (file-name-nondirectory venv)))
(list (cons :python
(list :venvPath vp :venv vn
:pythonPath (simple-venv-interpreter venv))))))
(setq-default eglot-workspace-configuration #'my/eglot-workspace-config)
aminevsaziz · 2022-10-29 02:05
BTW the eglot +pyright-langserver does not start and state that server tried to register unspported capability workspace/didchangeworkspacefolder
JDRiverRun · 2022-10-29 02:38
I get that message too, but it is harmless AFAIK.