0

I wish to run LSP using the pyls from the virtualenv of my project.

I don't have pyls installed globally (only in the local virtualenv).

I found this snippet online:

  (lsp-define-stdio-client lsp-python "python"
                           #'projectile-project-root
                           '("pyls"))

However the function lsp-define-stdio-client has been deprecated.

I can enable lsp with python-mode, and when opening a python file, I get a message saying LSP :: No LSP server running for python-mode (which is expected), then run:

(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection "/path/to/my/project/bin/pyls")
          :major-modes '(python-mode)
          :server-id 'pyls))

And finally run lsp from the buffer containing the python file.

However I would like this to be done automatically (when I open a python file, emacs finds the corresponding pyls and runs it).

Is there a way to do this?

1 Answer 1

1

lsp-stdio-connection accepths also a function so you may replace (lsp-stdio-connection "/path/to/my/project/bin/pyls") with

 (lsp-stdio-connection 
   (lambda () 
     ;; implementation of the function that returns the proper 
     ;; pyls for the current directory/project/file.
     ))

Alternatively, you may use define .dir-locals.el lsp-pyls-server-command in each project(refer to lsp-mode FAQ for an example).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.