]> git.eshelyaron.com Git - emacs.git/commitdiff
Experimental diagnostic overlays
authorJoão Távora <joaotavora@gmail.com>
Wed, 16 Aug 2017 12:49:31 +0000 (13:49 +0100)
committerJoão Távora <joaotavora@gmail.com>
Wed, 16 Aug 2017 13:02:22 +0000 (14:02 +0100)
lisp/progmodes/eglot.el

index 479e87ae565a0ae02985bc659083d5d9dbc6ba18..cd91d7821cea49f9f2c7a457d426f772d63e3139 100644 (file)
 \f
 ;;; Notifications
 ;;;
+(defvar-local eglot--diagnostic-overlays nil)
+
 (cl-defun eglot--textDocument/publishDiagnostics
     (_process &key uri diagnostics)
   "Handle notification publishDiagnostics"
-  (eglot--message "So yeah I got %s for %s"
-                  diagnostics uri))
+  (let* ((obj (url-generic-parse-url uri))
+        (filename (car (url-path-and-query obj)))
+         (buffer (find-buffer-visiting filename)))
+    (cond
+     (buffer
+      (with-current-buffer buffer
+        (eglot--message "OK so add some %s diags" (length diagnostics))
+        (mapc #'delete-overlay eglot--diagnostic-overlays)
+        (setq eglot--diagnostic-overlays nil)
+        (cl-flet ((pos-at (pos-plist)
+                          (save-excursion
+                            (goto-char (point-min))
+                            (forward-line (plist-get pos-plist :line))
+                            (forward-char (plist-get pos-plist :character))
+                            (point))))
+          (loop for diag across diagnostics
+                do (cl-destructuring-bind (&key range severity
+                                                _code _source message)
+                       diag
+                     (cl-destructuring-bind (&key start end)
+                         range
+                       (let* ((begin-pos (pos-at start))
+                              (end-pos (pos-at end))
+                              (ov (make-overlay begin-pos
+                                                end-pos
+                                                buffer)))
+                         (push ov eglot--diagnostic-overlays)
+                         (overlay-put ov 'face
+                                      (case severity
+                                        (1 'flymake-errline)
+                                        (2 'flymake-warnline)))
+                         (overlay-put ov 'help-echo
+                                      message)
+                         (overlay-put ov 'eglot--diagnostic diag))))))))
+     (t
+      (eglot--message "OK so %s isn't visited" filename)))))
 
 \f
 ;;; Helpers