lsp-mode
lsp-mode copied to clipboard
eldoc with lsp-mode no longer works in Emacs 27.2
Thank you for the bug report
- [X] I am using the latest version of
lsp-mode
related packages. - [X] I checked FAQ and Troubleshooting sections
- [X] You may also try reproduce the issue using clean environment using the following command:
M-x lsp-start-plain
Bug description
It seems like with the latest changes ElDoc has stopped working. I see the PR merged https://github.com/emacs-lsp/lsp-mode/pull/3275 that is suspect. There is no ElDoc showing, and when I try to run eldoc-mode
in the LSP buffer, it tells me that it is not supported in that buffer.
Steps to reproduce
- Use emacs 27.2
- Use lsp-mode and typescript-mode
- Ensure eldoc is turned on for lsp-mode
- Nothing shows
There are no errors, diagnostic messages, or anything else really abnormal.
Expected behavior
Expect to see ElDoc for things hovered over at point.
Which Language Server did you use?
ts-ls
OS
MacOS
Error callstack
No response
Anything else?
My LSP config
(defun lsp-js-config ()
"Setup lsp javascript flycheck checking."
(flycheck-add-next-checker 'lsp 'javascript-eslint)
(setq-local lsp-diagnostics-provider :none)
(setq-local lsp-ui-sideline-show-code-actions nil))
(defun lsp-rust-config ()
"Setup lsp rust specific configs."
(setq lsp-rust-analyzer-cargo-watch-command "clippy")
(setq-local lsp-eldoc-render-all t)
(setq-local lsp-idle-delay 0.6)
(setq lsp-rust-analyzer-server-display-inlay-hints t))
(defun lsp-ui-rust-config ()
"Setup lsp ui rust specific configs."
(setq-local lsp-ui-peek-always-show t)
(setq-local lsp-ui-sideline-show-hover t)
(setq-local lsp-ui-doc-enable nil)
(setq-local lsp-enable-file-watchers t)
(setq-local lsp-modeline-diagnostics-enable t))
(defun lsp-typescript-config ()
"Setup lsp typescript config"
(flycheck-add-next-checker 'lsp 'javascript-eslint))
(use-package lsp-mode
:ensure t
:diminish
:after (flycheck)
:hook ((c++-mode python-mode lua-mode typescript-mode js-mode) . lsp)
:commands lsp
:config
(progn
(setq lsp-enable-snippet nil)
(setq lsp-auto-guess-root t)
(setq lsp-enable-file-watchers nil)
(setq lsp-headerline-breadcrumb-enable nil)
(setq lsp-enable-text-document-color nil)
(setq lsp-semantic-tokens-enable nil)
(setq lsp-modeline-code-actions-enable nil)
(setq lsp-modeline-diagnostics-enable nil)
(add-hook 'js-mode-hook #'lsp-js-config)
(add-hook 'rustic-mode-hook #'lsp-rust-config)
(add-hook 'typescript-mode-hook #'lsp-typescript-config)))
(use-package lsp-ui
:ensure t
:after (lsp-mode)
:commands lsp-ui-mode)
(use-package lsp-treemacs
:ensure t
:after (treemacs)
:commands lsp-treemacs-errors-list)
(use-package lsp-ivy
:ensure t
:after (counsel)
:commands lsp-ivy-workspace-symbol)
I also deleted the lsp and eldoc folders from ~/emacs.d/elpa
and restarted.
I am guessing that the eldoc
being pulled from elpa (1.11) is not being used. I might be able to do similar workarounds as what I have to do with org-mode
now, so I can try that later .. but I wanted to report this.
I confirm that
I am guessing that the eldoc being pulled from elpa (1.11) is not being used.
Seems correct.
Eglot is doing that, most likely this will fix the issue.
;; ElDoc is preloaded in Emacs, so `require'-ing won't guarantee we are
;; using the latest version from GNU Elpa when we load eglot.el. Use an
;; heuristic to see if we need to `load' it in Emacs < 28.
(if (and (< emacs-major-version 28)
(not (boundp 'eldoc-documentation-strategy)))
(load "eldoc")
(require 'eldoc))
```
I can observe the same behavior with my Emacs setup (27.1) and lsp-mode/typescript-mode. It stopped showing information of the symbol at point in minibuffer the last time I updated my packages (i have now eldoc 1.11.0, lsp-mode 20220102.1756 and typescript-mode 20211130.1332).
When trying to enable eldoc-mode I also get the There is no ElDoc support in this buffer
error.
Apparently, the above "heuristic" does not fix it for me...
I reverted #3275 until we find a working solution.
Emacs 28.1 was out and bundled with Eldoc 1.11.0.
Are there plans for new Eldoc support?
For example, opt-in only when there are eldoc-documentation-functions
.
The new Eldoc eldoc-documentation-strategy
is useful for me. I would be very happy if this feature would be available in lsp as well.
For now, in Emacs 28.1, I use the new Eldoc by writing the following in the configuration file:
(defun my/lsp-tweak-eldoc ()
"Tweak eldoc for lsp."
(if lsp-managed-mode
(when (advice-function-member-p #'lsp-eldoc-function eldoc-documentation-function)
(remove-function (local 'eldoc-documentation-function) #'lsp-eldoc-function)
(add-hook 'eldoc-documentation-functions #'my/lsp--eldoc-function nil t))
(remove-hook 'eldoc-documentation-functions #'my/lsp--eldoc-function t)))
(add-hook 'lsp-managed-mode-hook #'my/lsp-tweak-eldoc)
(defun my/lsp--eldoc-function (callback &rest _ignore)
...)
Figured out the workaround (after a painful process):
Luckily I have set eldoc-documentation-strategy
in my config, and after loading eldoc on Emacs 27, it gives me this warning:
Warning (defvaralias): Overwriting value of ‘eldoc-documentation-strategy’ by aliasing to ‘eldoc-documentation-function’
Something is off there, then I found out that eldoc-documentation-strategy
was set to ignore
.
Summary: loading "eldoc"
just wasn't enough, we have to set eldoc-documentation-function
/eldoc-documentation-strategy
AFTER that.
Concrete workaround (on top of https://github.com/emacs-lsp/lsp-mode/pull/3275 / https://github.com/emacs-lsp/lsp-mode/commit/2736652be86f7e83f1fe08e7158a3d1d8f1bb965, assuming that Eldoc 1.13+ is already installed): https://github.com/emacs-lsp/lsp-mode/commit/f3d6961929784880092466c979ddd1631675fb7a
Edit: eglot
also sets eldoc-documentation-strategy
locally, but unconditionally https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/progmodes/eglot.el?id=43db0e2784bfafdb8b08a2f5f075e2d432df132f#n1716 so it isn't affected by the variable being ignore
globally, but I think that's rude for overriding user's choice (if any).
Edit: the check to find out if new eldoc has been loaded or not can be simplified to (not (boundp 'eldoc-documentation-functions))
as what python-mode does (but still more correct compared to eglot's check).
Same issue, not works in Emacs 28.2