[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/eglot2emacs 5b62d0071e 040/120: Enable lsp project-wide diagnost
From: |
João Távora |
Subject: |
feature/eglot2emacs 5b62d0071e 040/120: Enable lsp project-wide diagnostics via flymake |
Date: |
Thu, 20 Oct 2022 07:16:49 -0400 (EDT) |
branch: feature/eglot2emacs
commit 5b62d0071ec55ab8a38a0ee8f7fbd491f5731e22
Author: Theodor Thornhill <theo@thornhill.no>
Commit: GitHub <noreply@github.com>
Enable lsp project-wide diagnostics via flymake
* eglot.el (eglot-handle-notification): Pass on diagnostics from
unvisited files to flymake. Enables project-wide-diagnostics, so that
we can view all diagnostics in a given workspace. Uses new
functionality from flymake 1.2.1, hence the version bump.
* eglot-tests.el (project-wide-diagnostics-typescript): New tests
showcasing the possibility to see all related diagnostics in a
workspace.
* eglot-tests.el (project-wide-diagnostics-rust-analyzer): New tests
showcasing the possibility to see all related diagnostics in a
workspace.
* NEWS.md: Mention the new functionality
* README.md: Mention the new functionality
---
lisp/progmodes/eglot.el | 105 ++++++++++++++++++++++++++++--------------------
1 file changed, 61 insertions(+), 44 deletions(-)
diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 10e1616274..e27ddd7f94 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -7,7 +7,7 @@
;; Maintainer: João Távora <joaotavora@gmail.com>
;; URL: https://github.com/joaotavora/eglot
;; Keywords: convenience, languages
-;; Package-Requires: ((emacs "26.1") (jsonrpc "1.0.14") (flymake "1.0.9")
(project "0.3.0") (xref "1.0.1") (eldoc "1.11.0"))
+;; Package-Requires: ((emacs "26.1") (jsonrpc "1.0.14") (flymake "1.2.1")
(project "0.3.0") (xref "1.0.1") (eldoc "1.11.0"))
;; This file is part of GNU Emacs.
@@ -1825,49 +1825,66 @@ COMMAND is a symbol naming the command."
(server (_method (eql textDocument/publishDiagnostics)) &key uri diagnostics
&allow-other-keys) ; FIXME: doesn't respect `eglot-strict-mode'
"Handle notification publishDiagnostics."
- (if-let ((buffer (find-buffer-visiting (eglot--uri-to-path uri))))
- (with-current-buffer buffer
- (cl-loop
- for diag-spec across diagnostics
- collect (eglot--dbind ((Diagnostic) range message severity source
tags)
- diag-spec
- (setq message (concat source ": " message))
- (pcase-let
- ((sev severity)
- (`(,beg . ,end) (eglot--range-region range)))
- ;; Fallback to `flymake-diag-region' if server
- ;; botched the range
- (when (= beg end)
- (if-let* ((st (plist-get range :start))
- (diag-region
- (flymake-diag-region
- (current-buffer) (1+ (plist-get st :line))
- (plist-get st :character))))
- (setq beg (car diag-region) end (cdr diag-region))
- (eglot--widening
- (goto-char (point-min))
- (setq beg
- (point-at-bol
- (1+ (plist-get (plist-get range :start)
:line))))
- (setq end
- (point-at-eol
- (1+ (plist-get (plist-get range :end)
:line)))))))
- (eglot--make-diag (current-buffer) beg end
- (cond ((null sev) 'eglot-error)
- ((<= sev 1) 'eglot-error)
- ((= sev 2) 'eglot-warning)
- (t 'eglot-note))
- message `((eglot-lsp-diag . ,diag-spec))
- (and tags
- `((face . ,(mapcar (lambda (tag)
- (alist-get
tag eglot--tag-faces))
- tags)))))))
- into diags
- finally (cond (eglot--current-flymake-report-fn
- (eglot--report-to-flymake diags))
- (t
- (setq eglot--unreported-diagnostics (cons t diags))))))
- (jsonrpc--debug server "Diagnostics received for unvisited %s" uri)))
+ (cl-flet ((eglot--diag-type (sev)
+ (cond ((null sev) 'eglot-error)
+ ((<= sev 1) 'eglot-error)
+ ((= sev 2) 'eglot-warning)
+ (t 'eglot-note))))
+ (if-let ((buffer (find-buffer-visiting (eglot--uri-to-path uri))))
+ (with-current-buffer buffer
+ (cl-loop
+ for diag-spec across diagnostics
+ collect (eglot--dbind ((Diagnostic) range message severity source
tags)
+ diag-spec
+ (setq message (concat source ": " message))
+ (pcase-let
+ ((`(,beg . ,end) (eglot--range-region range)))
+ ;; Fallback to `flymake-diag-region' if server
+ ;; botched the range
+ (when (= beg end)
+ (if-let* ((st (plist-get range :start))
+ (diag-region
+ (flymake-diag-region
+ (current-buffer) (1+ (plist-get st :line))
+ (plist-get st :character))))
+ (setq beg (car diag-region) end (cdr diag-region))
+ (eglot--widening
+ (goto-char (point-min))
+ (setq beg
+ (point-at-bol
+ (1+ (plist-get (plist-get range :start)
:line))))
+ (setq end
+ (point-at-eol
+ (1+ (plist-get (plist-get range :end)
:line)))))))
+ (eglot--make-diag
+ (current-buffer) beg end
+ (eglot--diag-type severity)
+ message `((eglot-lsp-diag . ,diag-spec))
+ (and tags
+ `((face
+ . ,(mapcar (lambda (tag)
+ (alist-get tag eglot--tag-faces))
+ tags)))))))
+ into diags
+ finally (cond (eglot--current-flymake-report-fn
+ (eglot--report-to-flymake diags))
+ (t
+ (setq eglot--unreported-diagnostics (cons t
diags))))))
+ (cl-loop
+ with path = (expand-file-name (eglot--uri-to-path uri))
+ for diag-spec across diagnostics
+ collect (eglot--dbind ((Diagnostic) range message severity source)
diag-spec
+ (setq message (concat source ": " message))
+ (let* ((start (plist-get range :start))
+ (line (1+ (plist-get start :line)))
+ (char (1+ (plist-get start :character))))
+ (eglot--make-diag
+ path (cons line char) nil (eglot--diag-type severity)
message)))
+ into diags
+ finally
+ (setq flymake-list-only-diagnostics
+ (assoc-delete-all path flymake-list-only-diagnostics #'string=))
+ (push (cons path diags) flymake-list-only-diagnostics)))))
(cl-defun eglot--register-unregister (server things how)
"Helper for `registerCapability'.
- feature/eglot2emacs b1c7aa1d17 003/120: Add yaml-language-server for yaml-mode, (continued)
- feature/eglot2emacs b1c7aa1d17 003/120: Add yaml-language-server for yaml-mode, João Távora, 2022/10/20
- feature/eglot2emacs 51fc8fc3d2 002/120: Use `locate-user-emacs-file` instead of `concat`, João Távora, 2022/10/20
- feature/eglot2emacs 06f1cd6365 008/120: Add lua-lsp support for lua-mode, João Távora, 2022/10/20
- feature/eglot2emacs 7c712abf8f 009/120: Minor checkdoc fixes, João Távora, 2022/10/20
- feature/eglot2emacs 8a9959e054 039/120: Add clojure-lsp support for clojure, João Távora, 2022/10/20
- feature/eglot2emacs bc05805887 036/120: ; unbreak tests on emacs 26, João Távora, 2022/10/20
- feature/eglot2emacs 8b31247f1c 044/120: Properly check the completionitem.deprecated property, João Távora, 2022/10/20
- feature/eglot2emacs 5b88ec259c 026/120: Change from symbol-at-point to thing-at-point, João Távora, 2022/10/20
- feature/eglot2emacs 3aeebe8186 037/120: Change rust language server to rust-analyzer, João Távora, 2022/10/20
- feature/eglot2emacs ed4fd33223 043/120: * eglot.el (eglot-handle-notification): silence byte-compiler., João Távora, 2022/10/20
- feature/eglot2emacs 5b62d0071e 040/120: Enable lsp project-wide diagnostics via flymake,
João Távora <=
- feature/eglot2emacs 5d2f6bc667 055/120: Map more emacs variables to lsp formattingoptions fields, João Távora, 2022/10/20
- feature/eglot2emacs c06860b0f4 022/120: Bump eglot version to 1.8, João Távora, 2022/10/20
- feature/eglot2emacs 97ded82277 033/120: ; * eglot.el: move obsolete definition to new section., João Távora, 2022/10/20
- feature/eglot2emacs a905bad633 024/120: * eglot.el: improve commentary section., João Távora, 2022/10/20
- feature/eglot2emacs f550342059 069/120: Add out-of-box support for purescript lsp server, João Távora, 2022/10/20
- feature/eglot2emacs f8344871a0 075/120: Update docstring of eglot-events-buffer-size, João Távora, 2022/10/20
- feature/eglot2emacs e72fa6d867 082/120: Experiment with grouping in xref-backend-identifier-completion-table, João Távora, 2022/10/20
- feature/eglot2emacs fd5a5f16d7 081/120: Make c-u m-. work half decently, João Távora, 2022/10/20
- feature/eglot2emacs 6c8aee268d 079/120: Prevent desktop.el from saving/restoring eglot--managed-mode, João Távora, 2022/10/20
- feature/eglot2emacs 41a42e631b 096/120: Don't return poorly supported "special elements" in eglot-imenu, João Távora, 2022/10/20