Function: eglot--xref-make-match
eglot--xref-make-match is a byte-compiled function defined in
eglot.el.gz.
Signature
(eglot--xref-make-match NAME URI RANGE)
Documentation
Like xref-make-match but with LSP's NAME, URI and RANGE.
Try to visit the target file for a richer summary line.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/eglot.el.gz
(defun eglot--xref-make-match (name uri range)
"Like `xref-make-match' but with LSP's NAME, URI and RANGE.
Try to visit the target file for a richer summary line."
(pcase-let*
((file (eglot-uri-to-path uri))
(visiting (or (find-buffer-visiting file)
(gethash uri eglot--temp-location-buffers)))
(collect (lambda ()
(eglot--widening
(pcase-let* ((`(,beg . ,end) (eglot-range-region range))
(bol (progn (goto-char beg) (eglot--bol)))
(substring (buffer-substring bol (line-end-position)))
(hi-beg (- beg bol))
(hi-end (- (min (line-end-position) end) bol)))
(add-face-text-property hi-beg hi-end 'xref-match
t substring)
(list substring (line-number-at-pos (point) t)
(eglot-utf-32-linepos) (- end beg))))))
(`(,summary ,line ,column ,length)
(cond
(visiting (with-current-buffer visiting (funcall collect)))
((file-readable-p file) (with-current-buffer
(puthash uri (generate-new-buffer " *temp*")
eglot--temp-location-buffers)
(insert-file-contents file)
(funcall collect)))
(t ;; fall back to the "dumb strategy"
(let* ((start (cl-getf range :start))
(line (1+ (cl-getf start :line)))
(start-pos (cl-getf start :character))
(end-pos (cl-getf (cl-getf range :end) :character)))
(list name line start-pos (- end-pos start-pos)))))))
(setf (gethash (expand-file-name file) eglot--servers-by-xrefed-file)
(eglot--current-server-or-lose))
(xref-make-match summary (xref-make-file-location file line column) length)))