Skip to content

Make lsp-headerline--check-breadcrumb public so that it can be added to after-*-jump-hooks by external code #4803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* Improve the lsp-ocaml client (see [[https://github.com/emacs-lsp/lsp-mode/issues/4731][#4731]] for the follow-up issue. MRs: [[https://github.com/emacs-lsp/lsp-mode/pull/4741][#4741]], [[https://github.com/emacs-lsp/lsp-mode/pull/4732][#4732]])
* Add support for ~source.removeUnusedImports~ for lsp-javascript
* Add Python(ty) support
* Make lsp-headerline--check-breadcrumb public

** 9.0.0
* Add language server config for QML (Qt Modeling Language) using qmlls.
Expand Down
15 changes: 15 additions & 0 deletions docs/page/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,18 @@ You can use `lsp-clients-clangd-args` to configure your clangd. Add the followin
For more flags, see clangd --help.

(Thanks to [Martingale on Emacs StackExchange](https://emacs.stackexchange.com/questions/58015/how-to-stop-lsp-mode-including-headers-automatically-for-c-c-code) for this answer!)

---
### :grey_question: I have lsp-headerline-breadcrumb-mode enabled but the breadcrumb isn't always updating, for example when previewing results in consult-xref.

The function that updates the breadcrumb is `lsp-headerline-check-breadcrumb`. By default, this is added to `xref-after-jump-hook`, so that the breadcrumb will update immediately after jumping to a new location. Some packages, such as consult during previews, do jumps without calling `xref-after-jump-hook`, so the breadcrumb never updates.

The solution is to add `lsp-headerline-check-breadcrumb` to the appropriate hook. For consult, add the following to your user configuration:

```elisp
(add-hook 'lsp-headerline-breadcrumb-mode-hook
(lambda ()
(if lsp-headerline-breadcrumb-mode
(add-hook 'consult-after-jump-hook #'lsp-headerline-check-breadcrumb nil t)
(remove-hook 'consult-after-jump-hook #'lsp-headerline-check-breadcrumb t))))
```
10 changes: 5 additions & 5 deletions lsp-headerline.el
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ PATH is the current folder to be checked."
lsp-headerline-breadcrumb-segments
"")))

(defun lsp-headerline--check-breadcrumb (&rest _)
(defun lsp-headerline-check-breadcrumb (&rest _)
"Request for document symbols to build the breadcrumb."
(set-window-parameter (selected-window) 'lsp-headerline--string (lsp-headerline--build-string))
(force-mode-line-update))
Expand Down Expand Up @@ -440,17 +440,17 @@ PATH is the current folder to be checked."
(setq header-line-format (list header-line-format)))
(add-to-list 'header-line-format '(t (:eval (window-parameter nil 'lsp-headerline--string) )))

(add-hook 'xref-after-jump-hook #'lsp-headerline--check-breadcrumb nil t)
(add-hook 'xref-after-jump-hook #'lsp-headerline-check-breadcrumb nil t)

(add-hook 'lsp-on-idle-hook #'lsp-headerline--check-breadcrumb nil t)
(add-hook 'lsp-on-idle-hook #'lsp-headerline-check-breadcrumb nil t)
(add-hook 'lsp-configure-hook #'lsp-headerline--enable-breadcrumb nil t)
(add-hook 'lsp-unconfigure-hook #'lsp-headerline--disable-breadcrumb nil t))
(t
(remove-hook 'lsp-on-idle-hook #'lsp-headerline--check-breadcrumb t)
(remove-hook 'lsp-on-idle-hook #'lsp-headerline-check-breadcrumb t)
(remove-hook 'lsp-configure-hook #'lsp-headerline--enable-breadcrumb t)
(remove-hook 'lsp-unconfigure-hook #'lsp-headerline--disable-breadcrumb t)

(remove-hook 'xref-after-jump-hook #'lsp-headerline--check-breadcrumb t)
(remove-hook 'xref-after-jump-hook #'lsp-headerline-check-breadcrumb t)

(setq lsp-headerline--path-up-to-project-segments nil)
(setq header-line-format (remove '(t (:eval (window-parameter nil 'lsp-headerline--string) )) header-line-format)))))
Expand Down