]> git.eshelyaron.com Git - emacs.git/commitdiff
Empty ranges are valid in lsp
authorJoão Távora <joaotavora@gmail.com>
Thu, 21 Jun 2018 22:32:14 +0000 (23:32 +0100)
committerJoão Távora <joaotavora@gmail.com>
Thu, 21 Jun 2018 22:32:14 +0000 (23:32 +0100)
The previous hack in eglot--range-region, designed to appease cquery's
occasional practice of publishing diagnostics with empty regions, was
moved to the proper notification handler.

Reported by mkcms <k.michal@zoho.com>.

* eglot.el (eglot--range-region): Allow empty ranges, which are
allowed in LSP.
(eglot-handle-notification :textDocument/publishDiagnostics): Maybe
fallback to flymake-diag-region here.

GitHub-reference: close https://github.com/joaotavora/eglot/issues/27

lisp/progmodes/eglot.el

index 2fdf433c55a7a9a52385c9fe767fe8006898acdc..f4a03da7e6c9ab966203d21071d140170c6dfcce 100644 (file)
@@ -896,10 +896,7 @@ If optional MARKERS, make markers."
   (let* ((st (plist-get range :start))
          (beg (eglot--lsp-position-to-point st markers))
          (end (eglot--lsp-position-to-point (plist-get range :end) markers)))
-    ;; Fallback to `flymake-diag-region' if server botched the range
-    (if (/= beg end) (cons beg end) (flymake-diag-region
-                                     (current-buffer) (plist-get st :line)
-                                     (1- (plist-get st :character))))))
+    (cons beg end)))
 
 \f
 ;;; Minor modes
@@ -1125,7 +1122,18 @@ Don't leave this function with the server still running."
                                               _code source message)
                      diag-spec
                    (setq message (concat source ": " message))
-                   (pcase-let ((`(,beg . ,end) (eglot--range-region range)))
+                   (pcase-let
+                       ((`(,beg . ,end) (eglot--range-region range)))
+                     ;; Fallback to `flymake-diag-region' if server
+                     ;; botched the range
+                     (if (= beg end)
+                         (let* ((st (plist-get range :start))
+                                (diag-region
+                                 (flymake-diag-region
+                                  (current-buffer) (plist-get st :line)
+                                  (1- (plist-get st :character)))))
+                           (setq beg (car diag-region)
+                                 end (cdr diag-region))))
                      (eglot--make-diag (current-buffer) beg end
                                        (cond ((<= sev 1) 'eglot-error)
                                              ((= sev 2)  'eglot-warning)