Created
December 6, 2024 21:41
-
-
Save vkjr/0e585c7f8ef2ea918bb0faaba5ba5334 to your computer and use it in GitHub Desktop.
Command to show all project errors from LSP in a convenient xref buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun vk/show-lsp-diagnostics-xref () | |
| "Display LSP diagnostics in a persistent `xref`-style buffer." | |
| (interactive) | |
| (let ((diagnostics (lsp-diagnostics)) | |
| (xref-items '())) ;; Initialize xref items list | |
| ;; Collect diagnostics as `xref-item` structures | |
| (maphash | |
| (lambda (file errors) | |
| (dolist (error errors) | |
| (let* ((range (gethash "range" error)) | |
| (start (gethash "start" range)) | |
| (line (1+ (gethash "line" start))) | |
| (character (gethash "character" start)) | |
| (message (gethash "message" error)) | |
| (location (xref-make-file-location file line character))) | |
| (push (xref-make message location) xref-items)))) | |
| diagnostics) | |
| ;; Create a custom xref group for diagnostics | |
| (let ((xref-buffer-name "*LSP Diagnostics Xref*")) | |
| (with-current-buffer (get-buffer-create xref-buffer-name) | |
| ;; Use `xref` display machinery with custom buffer | |
| (let ((xref-backend-functions | |
| (list (lambda () (lambda () xref-items))))) | |
| (xref--show-xrefs (lambda () xref-items) nil))) | |
| ;; Display the custom xref buffer | |
| (pop-to-buffer xref-buffer-name)))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ilmotta, thanks for pointing to embark-export, looks very convenient!