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?

0

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

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

Alternatively, you may use define .dir-local lsp-pyls-server-command in each project(refere to lsp-mode FAQ for example).

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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