doomemacs / doomemacs/core

restart lsp workspace when virtualenv updated

Open
#5,680 2 comments 2 reactions 0 assignees View on GitHub
is:bug needs-triage
Dominant language
Emacs Lisp
Stars
22.7k
Forks
3.1k
Avg merge
10h 46m
Merged PRs (30d)
4

Description

### What did you expect to happen?

When I enable `(python +lsp +poetry)`, use [poetry](https://github.com/python-poetry/poetry) to create a project with python virtualenv and open a python file of the project, Emacs should enable LSP mode and use current Python virtualenv.

### What actually happened?

When I enable `(python +lsp +poetry)`, use [poetry](https://github.com/python-poetry/poetry) to create a project with python virtualenv and open a python file of the project, Emacs do enable LSP mode, but won't detect current virtualenv. I need invoke `lsp-workspace-restart` manually to make it right.

### Describe your attempts to resolve the issue

When use `(python +lsp +poetry)`, I found I have to invoke `lsp-workspace-restart` manually to make LSP detect current Python virtualenv. So I have the config below in my `config.el`:

```elisp
(defun my-restart-python-lsp ()
(when (bound-and-true-p lsp-mode)
(call-interactively #'lsp-workspace-restart)))
(after! pyvenv
(add-hook 'pyvenv-post-activate-hooks #'my-restart-python-lsp))
```
I'm not sure whether it's just Python or other languages also have this issue, maybe it's also related to the implementation of LSP language server?

### Steps to reproduce

1. enable `(python +lsp +poetry)`
2. `poetry new demo`
3. `poetry add xxxx`
4. use Doom Emacs create a python file in demo project
5. try to import xxxx lib, and you won't get lsp completion or find-definition work, flycheck complains `unresolve xxxx`
6. invoke `lsp-workspace-restart`, then you can get xxxx completion works and flycheck error gone

### System Information

https://pastebin.com/DNjNcsyG

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.