Eglot: use faster strategy for moving to LSP positions (bug#61726)

Turns out we don't need encode-coding-region after all.

* lisp/progmodes/eglot.el (eglot-move-to-lsp-abiding-column): Rewrite.

Co-authored-by: Augusto Stoffel <arstoffel@gmail.com>
This commit is contained in:
Eli Zaretskii 2023-02-26 10:27:18 +00:00 committed by João Távora
parent 5b174b9683
commit b0e87e930e

View file

@ -1491,19 +1491,16 @@ be set to `eglot-move-to-lsp-abiding-column' (the default), and
(line-end-position)))) (line-end-position))))
(defun eglot-move-to-lsp-abiding-column (column) (defun eglot-move-to-lsp-abiding-column (column)
"Move to COLUMN abiding by the LSP spec." "Move to COLUMN as computed by LSP's UTF-16 criterion."
(save-restriction (let* ((bol (line-beginning-position))
(cl-loop (goal-char (+ bol column))
with lbp = (line-beginning-position) (eol (line-end-position)))
initially (goto-char bol)
(narrow-to-region lbp (line-end-position)) (while (and (< (point) goal-char)
(move-to-column column) (< (point) eol))
for diff = (- column (if (<= #x010000 (char-after) #x10ffff)
(eglot-lsp-abiding-column lbp)) (setq goal-char (1- goal-char)))
until (zerop diff) (forward-char 1))))
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) (defun eglot--lsp-position-to-point (pos-plist &optional marker)
"Convert LSP position POS-PLIST to Emacs point. "Convert LSP position POS-PLIST to Emacs point.