From 584ae9e0b5cfa5f438bd4fa84d191963a33a38bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Wed, 16 Aug 2017 13:49:31 +0100 Subject: [PATCH] Experimental diagnostic overlays --- lisp/progmodes/eglot.el | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 479e87ae565..cd91d7821ce 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -414,11 +414,47 @@ ;;; 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))))) ;;; Helpers -- 2.39.2