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
Lazily create markers in helm-xref-candidates and change helm-xref-source accordingly #6
Comments
I currently use the following snippet (only for ;; Adapted from helm-xref-goto-location
(defun my-xref/helm-xref-goto-location (candidate func)
(-when-let ((_ . xref) (assoc candidate my-helm-xref-alist))
(with-slots (summary location) xref
(let ((marker (xref-location-marker location)))
(helm-xref-goto-location marker func)))))
;; Adapted from helm-xref-source
(defun my-xref/helm-xref-source ()
(helm-build-sync-source "no-find-file Helm Xref"
:candidates (lambda () (reverse my-helm-xref-alist))
:persistent-action (lambda (candidate)
(my-xref/helm-xref-goto-location candidate 'display-buffer))
:action (lambda (candidate)
(my-xref/helm-xref-goto-location candidate 'switch-to-buffer))
:candidate-transformer
(lambda (candidates)
(mapcar #'car candidates))
:candidate-number-limit 999))
(defvar my-helm-xref-alist nil)
;; Adapted from helm-xref-show-xrefs
(defun my-xref/helm-show-symbols (xrefs)
(setq my-helm-xref-alist nil)
(dolist (xref xrefs)
(with-slots (summary location) xref
(let* ((line (xref-location-line location))
(file (xref-location-group location))
candidate)
(setq candidate
(concat
(propertize (car (reverse (split-string file "\\/")))
'font-lock-face 'helm-xref-file-name)
(when (string= "integer" (type-of line))
(concat
":"
(propertize (int-to-string line)
'font-lock-face 'helm-xref-line-number)))
":"
summary))
(push (cons candidate xref) my-helm-xref-alist))))
(helm :sources (my-xref/helm-xref-source)
:truncate-lines t
:buffer "*helm-workspace-symbol*"))
(defun my-xref/find-apropos (pattern)
(interactive (list (read-string
"Search for workspace/symbol: "
nil 'xref--read-pattern-history)))
(let ((symbols (xref-backend-apropos (lsp--xref-backend) pattern)))
(unless symbols
(user-error "No symbol found for: %s" pattern))
(my-xref//with-evil-jumps (evil-set-jump))
(my-xref/helm-show-symbols symbols))) |
Yeah, that's really annoying! I would gladly merge a PR, that solves this issue. If you have a working solution just open a PR with the complete code you are using. |
Expected behavior
xref-find-definitions xref-find-references xref-find-apropos
do not create new buffers for non-visiting files.Actual behavior (from
emacs-helm.sh
if possible, see note at the bottom)xref-find-definitions xref-find-references xref-find-apropos
create new buffers for non-visiting files.These three functions transitively call
xref-location-marker
for each candidate, which in turn callsfind-file-noselect
(may create undesired buffers for non-visiting files).When using the C++ language server https://github.com/jacobdufault/cquery with lsp-mode or others, if there are say 100 different files corresponding to all the candidates, the 100 files will all be visited, which may be very slow.
Steps to reproduce (recipe)
Call any of
xref-find-definitions xref-find-references xref-find-apropos
Backtraces if any (
M-x toggle-debug-on-error
)The text was updated successfully, but these errors were encountered: