-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lsp mode awkwardness #25
Comments
@cwhatley I've been trying to set up a config like this too. I think I have ;; lsp Python
(use-package lsp-python-ms
:after lsp-mode poetry
:ensure t
:init
(setq lsp-python-ms-auto-install-server t)
:config
(put 'lsp-python-ms-python-executable 'safe-local-variable 'stringp)
:hook
(hack-local-variables-hook . (lambda ()
(when ('stringp (poetry-find-project-root))
(poetry-venv-workon)
(print "hello")
)
(when (derived-mode-p 'python-mode)
(require 'lsp-python-ms)
(lsp-deferred))
))
) |
@cwhatley I figured it out 🎉 ! Here are the relevant use-package snippets: ;; poetry
(use-package poetry
:ensure t
:hook
;; activate poetry-tracking-mode when python-mode is active
(python-mode . poetry-tracking-mode)
)
;; ....
;; lsp-mode configs
(use-package lsp-mode
:ensure t
:init
(setq lsp-keymap-prefix "C-c l")
:custom
(lsp-auto-guess-root +1)
:config
(lsp-enable-imenu)
;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
:hook (;; replace XXX-mode with concrete major-mode(e. g. python-mode)
(python-mode . lsp-deferred)
;; if you want which-key integration
(lsp-mode . lsp-enable-which-key-integration)
(lsp-after-open . 'lsp-enable-imenu)
)
:commands (lsp lsp-deferred))
;; lsp Python
(use-package lsp-python-ms
:after poetry
:ensure t
:init
(setq lsp-python-ms-auto-install-server t)
:config
(put 'lsp-python-ms-python-executable 'safe-local-variable 'stringp)
;; attempt to activate Poetry env first
(when (stringp (poetry-find-project-root))
(poetry-venv-workon)
)
:hook
(
(python-mode . (lambda ()
(require 'lsp-python-ms)
(lsp-deferred)
))
;; if .dir-locals exists, read it first, then activate mspyls
(hack-local-variables . (lambda ()
(when (derived-mode-p 'python-mode)
(require 'lsp-python-ms)
(lsp-deferred))
))
)
) It seems awfully hacky to me, but importantly it works automatically with Poetry projects and projects where I manually define a Python (and mypy) path in a |
Thanks for the snippet. What's the Sounds like the moral of the story is to not have poetry.el automatically track. |
The
Fully agree – it runs far too slowly and runs the virtualenv activation too late. If it provided a minor mode and a mode-hook, I could use that instead in my package declaration. |
I actually use pyls (I should try the MS one, I think) and inspired by your snippet, I tried the following and found this seems to work pretty well so far:
|
Very cool! I only just started using LSP and opted for mspyls since some threads on Reddit suggested it has better performance and is more actively developed. |
a better config based on @cwhatley 's
|
Do you use lsp-mode in conjunction with poetry.el? I'm using lsp-deferred, but the connection to the language server is still to early to pick up the right env and run pyls from within the venv. I've tried all three tracking strategies.
The text was updated successfully, but these errors were encountered: