Skip to content

Commit

Permalink
Fix eglot-move-to-lsp-abiding-column (#361)
Browse files Browse the repository at this point in the history
Ensure conformance with the this part of the specification: "if the
character value is greater than the line length it defaults back to
the line length."

* eglot.el: (eglot-move-to-lsp-abiding-column): Don't move beyond
line-end.

(#361: joaotavora/eglot#361
  • Loading branch information
joaotavora committed Apr 16, 2020
1 parent e1e662f commit 911f816
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lisp/progmodes/eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -1050,15 +1050,20 @@ be set to `eglot-move-to-lsp-abiding-column', and

(defun eglot-move-to-lsp-abiding-column (column)
"Move to COLUMN abiding by the LSP spec."
(cl-loop
initially (move-to-column column)
with lbp = (line-beginning-position)
for diff = (- column
(/ (- (length (encode-coding-region lbp (point) 'utf-16 t))
2)
2))
until (zerop diff)
do (forward-char (/ (if (> diff 0) (1+ diff) (1- diff)) 2))))
(save-restriction
(cl-loop
with lbp = (line-beginning-position)
initially
(narrow-to-region lbp (line-end-position))
(move-to-column column)
for diff = (- column
(/ (- (length (encode-coding-region lbp (point) 'utf-16 t))
2)
2))
until (zerop diff)
do (condition-case eob-err
(forward-char (/ (if (> diff 0) (1+ diff) (1- diff)) 2))
(end-of-buffer (cl-return eob-err))))))

(defun eglot--lsp-position-to-point (pos-plist &optional marker)
"Convert LSP position POS-PLIST to Emacs point.
Expand Down

0 comments on commit 911f816

Please sign in to comment.