Skip to content

Commit

Permalink
Fix #479: correctly place diagnostics in narrowed buffers
Browse files Browse the repository at this point in the history
* eglot.el (eglot--lsp-position-to-point)
(eglot-handle-notification): save-restriction and widen

#479: joaotavora/eglot#479
  • Loading branch information
joaotavora committed May 18, 2020
1 parent 9d9db5b commit f7fa4c0
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions lisp/progmodes/eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -1118,19 +1118,21 @@ be set to `eglot-move-to-lsp-abiding-column' (the default), and
"Convert LSP position POS-PLIST to Emacs point.
If optional MARKER, return a marker instead"
(save-excursion
(goto-char (point-min))
(forward-line (min most-positive-fixnum
(plist-get pos-plist :line)))
(unless (eobp) ;; if line was excessive leave point at eob
(let ((tab-width 1)
(col (plist-get pos-plist :character)))
(unless (wholenump col)
(eglot--warn
"Caution: LSP server sent invalid character position %s. Using 0 instead."
col)
(setq col 0))
(funcall eglot-move-to-column-function col)))
(if marker (copy-marker (point-marker)) (point))))
(save-restriction
(widen)
(goto-char (point-min))
(forward-line (min most-positive-fixnum
(plist-get pos-plist :line)))
(unless (eobp) ;; if line was excessive leave point at eob
(let ((tab-width 1)
(col (plist-get pos-plist :character)))
(unless (wholenump col)
(eglot--warn
"Caution: LSP server sent invalid character position %s. Using 0 instead."
col)
(setq col 0))
(funcall eglot-move-to-column-function col)))
(if marker (copy-marker (point-marker)) (point)))))

(defun eglot--path-to-uri (path)
"URIfy PATH."
Expand Down Expand Up @@ -1585,13 +1587,15 @@ COMMAND is a symbol naming the command."
message `((eglot-lsp-diag . ,diag-spec)))))
into diags
finally (cond ((and flymake-mode eglot--current-flymake-report-fn)
(funcall eglot--current-flymake-report-fn diags
;; If the buffer hasn't changed since last
;; call to the report function, flymake won't
;; delete old diagnostics. Using :region
;; keyword forces flymake to delete
;; them (github#159).
:region (cons (point-min) (point-max)))
(save-restriction
(widen)
(funcall eglot--current-flymake-report-fn diags
;; If the buffer hasn't changed since last
;; call to the report function, flymake won't
;; delete old diagnostics. Using :region
;; keyword forces flymake to delete
;; them (github#159).
:region (cons (point-min) (point-max))))
(setq eglot--unreported-diagnostics nil))
(t
(setq eglot--unreported-diagnostics (cons t diags))))))
Expand Down

0 comments on commit f7fa4c0

Please sign in to comment.