Closed hongyi-zhao closed 3 years ago
make sure that your project root is the correct one. Use M-x lsp-describe-session
How to know whether the project root directory is correct or not? For example, the following one:
Project root is the folder that contains the files that you want to work on. It is usually git repository. In your case you have selected your home folder which is wrong. As a result the language server is scanning all files in your home folder and that's why it is crashing.
Use M-x lsp-workspace-folders-add/remove to fix the project root.
Can I only add a new workspace-folder without removing the old one, as shown below?
Can I only add a new workspace-folder without removing the old one, as shown below?
Is there anything preventing you from testing this on your side?
Thank you, I reinstalled pyrigt
as follows, according to the commented here:
$ yarn global add pyright
$ export PATH=$HOME/.yarn/bin:$PATH
Then I use pyvenv to automatically set the current workspace-folder as follows:
(use-package pyvenv
:init
(setenv "WORKON_HOME" "~/.pyenv/versions")
;;https://lists.gnu.org/archive/html/help-gnu-emacs/2021-09/msg00535.html
(defun try/pyvenv-workon ()
(when (buffer-file-name)
(let* ((python-version ".python-version")
(project-dir (locate-dominating-file (buffer-file-name) python-version)))
(when project-dir
(progn
;; https://github.com/emacs-lsp/lsp-pyright/issues/62#issuecomment-942845406
(lsp-workspace-folders-add project-dir)
(pyvenv-workon
(with-temp-buffer
(insert-file-contents (expand-file-name python-version project-dir))
(car (split-string (buffer-string))))))
))))
:config
(pyvenv-mode 1)
(setq pyvenv-post-activate-hooks
(list (lambda ()
(when (executable-find "ipython3")
(setq python-shell-interpreter "ipython3"
python-shell-interpreter-args "-i --matplotlib=inline --automagic --simple-prompt --pprint"
;; https://gitlab.com/python-mode-devs/python-mode/-/issues/112#note_699461188
py-ipython-command "ipython3"
py-ipython-command-args '("-i" "--matplotlib=inline" "--automagic" "--simple-prompt" "--pprint")
)))))
(setq pyvenv-post-deactivate-hooks
(list (lambda ()
(setq python-shell-interpreter "python3"))))
)
The above method will fix the problem discussed here. See the info given by M-x lsp-describe-session
:
When using Emacs for python development, I use the following configuration:
But when I open a python file with Emacs, I always noticed a very long initialization time with the above configuration, and furthermore, Emacs often loses response even during use. Any hints for this problem?
Also see the relevant issue here.
Regards, HZ