lsp-treemacs-references shows stale results unless invoked twice
- Dominant language
- Emacs Lisp
- Stars
- 22.7k
- Forks
- 3.1k
- Avg merge
- 10h 46m
- Merged PRs (30d)
- 4
Description
### I confirm that...
- [x] I searched the issue tracker and found no similar issues.
- [x] I searched the [documentation](https://docs.doomemacs.org), [FAQ](https://docs.doomemacs.org/-/faq), [discussion board](https://doomemacs.org/discuss), and [Google](https://google.com) for solutions to my issue.
- [x] I read [the debugging guide](https://doomemacs.org/d/how2debug) and researched the issue to the best of my ability.
- [x] My issue can be observed on the latest available commit of Doom.
- [x] My issue can be observed on a stable release of Emacs (i.e. doesn't end in `.50`, `.60`, or `.90`–`.99`)
### Describe your issue
When invoking `lsp-treemacs-references` (`SPC c R`), the first invocation after switching symbols always displays the previous symbol’s references. A second invocation updates the view correctly.
The behavior appears only when Doom’s modules are active.
Both Vanilla Emacs 30.2 and Doom’s vanilla sandbox (core only) worked fine with a minimal testing configuration.
It doesn't seem to be backend related, as it happened with clojure-lsp, clangd-lsp, ts-ls and coffeesense.
### Steps to reproduce
Given:
**test.c**
```c
int f(int x) { return x + 1; }
int main(void) {
int value = 41;
int answer = f(value);
return answer;
}
```
1. Visit file
LSP should auto-start on doom with modules. On minimal config you may have to start it and install the server.
2. Move the cursor over `value`
It should be highlighted
3. Invoke `lsp-treemacs-references` (`SPC c R`)
Both lines 4 and 5 should show up on the treemacs pane, highlighting `value`
4. Move the cursor over `answer`
5. Invoke `lsp-treemacs-references`
The treemacs pane shows the previous results.
6. Invoke `lsp-treemacs-references` again
Now lines 5 and 6 show up, highlighting `answer`
Example of the above running on the Doom Sandbox without a private config:
https://github.com/user-attachments/assets/3941fe94-af7e-4851-bb96-4e1c701f7917
This issue was once reported on https://github.com/emacs-lsp/lsp-treemacs/issues/155, but it indeed seems to be doom-related
The following is the minimal config I've used to test on doom sandboxes:
```emacs-lisp
;;; lsp-test-clangd.el --- Minimal LSP test with clangd -*- lexical-binding: t; -*-
;; --- package bootstrap ---
(require 'package)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(setq package-enable-at-startup nil)
(package-initialize)
(unless (package-installed-p 'use-package)
(package-refresh-contents) (package-install 'use-package))
(eval-when-compile (require 'use-package))
(setq use-package-always-ensure t)
;; --- quiet UI ---
(menu-bar-mode -1) (tool-bar-mode -1) (scroll-bar-mode -1)
(setq inhibit-startup-message t)
(global-display-line-numbers-mode 1)
;; --- envrc (direnv/nix) ---
(use-package exec-path-from-shell
:if (memq system-type '(darwin))
:init (setq exec-path-from-shell-variables '("PATH" "MANPATH" "NIX_PATH"))
:config (exec-path-from-shell-initialize))
(use-package envrc :init (envrc-global-mode))
;; --- LSP: restrict to clangd only ---
(setq lsp-client-packages '(lsp-clangd)) ;; only register the C/C++ client
(setq lsp-disabled-clients '(rust-analyzer gopls pylsp pyright ts-ls lua-language-server
html-ls css-ls json-ls yaml-language-server bash-ls))
(use-package lsp-mode
:commands (lsp lsp-deferred)
:hook ((c-mode . lsp-deferred)
(c++-mode . lsp-deferred))
:init
(setq lsp-keymap-prefix "C-c l"
lsp-log-io nil
lsp-idle-delay 0.2
lsp-auto-install-servers t)
:config
;; Make sure clangd is available; lsp-mode can install it for you.
(with-demoted-errors "lsp-install: %S"
(unless (executable-find "clangd")
(lsp-install-server 'clangd))))
;; --- Treemacs references ---
(use-package treemacs :defer t)
(use-package lsp-treemacs
:after (lsp-mode treemacs)
:commands (lsp-treemacs-references))
(global-set-key (kbd "C-c r") #'lsp-treemacs-references)
(provide 'lsp-test-clangd)
;;; lsp-test-clangd.el ends here
```
### System information
https://pastebin.com/7F6QmGaD
Contributor guide
Assessment
This issue has not been assessed yet.