From: João Távora Date: Thu, 21 Jun 2018 22:32:14 +0000 (+0100) Subject: Empty ranges are valid in lsp X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~491 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7826b265a0ecd9357719b2fb9491c9bcb517d4cc;p=emacs.git Empty ranges are valid in lsp 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 . * 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 --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 2fdf433c55a..f4a03da7e6c 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -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))) ;;; 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)