emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.72k stars 860 forks source link

Detect if LSP_USE_PLIST is not set before loading lsp-mode (server starting...) #4455

Open alanpearce opened 1 month ago

alanpearce commented 1 month ago

I appeared to have LSP_USE_PLISTS correctly set both for the installation and initialisation of lsp-mode, but it stopped working when I switched to running Emacs as a daemon and was harder to track down than it needed to be.

When opening a buffer that would call lsp, the server(s) would be stuck starting indefinitely. I couldn't work out what the issue was easily; *lsp-log* showed that the path was correct but none of the other buffers showed anything that would hint to problems with LSP_USE_PLISTS. Fortunately I decided to run lsp-doctor and saw that the plist feature was marked as optional and not OK as I expected.

It would be nice if lsp-mode would detect being run without plists when installed as such and perhaps show an error in the echo area and perhaps highlight the issue when lsp-doctor is called by making the plists item red instead of orange (after a longer time, I could easily have forgotten that I had set this up). An FAQ item could also be reasonable: "server stuck starting with plists enabled?...". If you don't agree with any this, feel free to close the issue; if someone searches for it in the future, hopefully they'll find it anyway.

The cause of the issue was in my own config, namely that I defer loading lsp-mode in a standalone Emacs session, but not when run as a daemon, roughly as below:

(setq use-package-always-demand (daemonp))
(use-package lsp-mode
  :defer 3)
;; ...
(setenv "LSP_USE_PLISTS" "true")

The setenv call was in a different file and it wasn't obvious which file would be loaded first. Once I called it in early-init.el the issue went away