[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 1.2 8529b55 089/101: Fix #124: add ability to move to LSP-precise
From: |
Christian Johansson |
Subject: |
[elpa] 1.2 8529b55 089/101: Fix #124: add ability to move to LSP-precise columns |
Date: |
Thu, 29 Apr 2021 15:09:07 -0400 (EDT) |
tag: 1.2
commit 8529b55f07e7d91399ed2f5d5aaa919654b3e5ec
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>
Fix #124: add ability to move to LSP-precise columns
Also close #125.
Idea and much of design contributed by Michał Krzywkowski
<k.michal@zoho.com>
This introduces the variable eglot-move-to-column-function.
According to the standard, LSP column/character offsets are based
on a count of UTF-16 code units, not actual visual columns. So
when LSP says position 3 of a line containing just \"aXbc\",
where X is a multi-byte character, it actually means `b', not
`c'. This is what the function
`eglot-move-to-lsp-abiding-column' does.
However, many servers don't follow the spec this closely, and
thus this variable should be set to `move-to-column' in buffers
managed by those servers.
* eglot.el (eglot-move-to-column-function): New variable.
(eglot-move-to-lsp-abiding-column): New function.
(eglot--lsp-position-to-point): Use eglot-move-to-column-function.
---
eglot.el | 43 +++++++++++++++++++++++++++++++++++--------
1 file changed, 35 insertions(+), 8 deletions(-)
diff --git a/eglot.el b/eglot.el
index 576d7f3..f7b9c86 100644
--- a/eglot.el
+++ b/eglot.el
@@ -728,16 +728,43 @@ CONNECT-ARGS are passed as additional arguments to
:character (- (goto-char (or pos (point)))
(line-beginning-position)))))
+(defvar eglot-move-to-column-function #'move-to-column
+ "How to move to a column reported by the LSP server.
+
+According to the standard, LSP column/character offsets are based
+on a count of UTF-16 code units, not actual visual columns. So
+when LSP says position 3 of a line containing just \"aXbc\",
+where X is a multi-byte character, it actually means `b', not
+`c'. This is what the function
+`eglot-move-to-lsp-abiding-column' does.
+
+However, many servers don't follow the spec this closely, and
+thus this variable should be set to `move-to-column' in buffers
+managed by those servers.")
+
+(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)
+ for offset = (max 1 (abs (/ diff 2)))
+ do (if (> diff 0) (forward-char offset) (backward-char offset))))
+
(defun eglot--lsp-position-to-point (pos-plist &optional marker)
"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)))
- (forward-char (min (plist-get pos-plist :character)
- (- (line-end-position)
- (line-beginning-position))))
- (if marker (copy-marker (point-marker)) (point))))
+ (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
+ (funcall eglot-move-to-column-function (plist-get pos-plist :character)))
+ (if marker (copy-marker (point-marker)) (point))))
(defun eglot--path-to-uri (path)
"URIfy PATH."
@@ -1040,7 +1067,7 @@ Uses THING, FACE, DEFS and PREPEND."
(priority . ,(+ 50 i))
(keymap . ,(let ((map (make-sparse-keymap)))
(define-key map [mouse-1]
- (eglot--mouse-call 'eglot-code-actions))
+ (eglot--mouse-call
'eglot-code-actions))
map)))))
- [elpa] 1.2 989647a 049/101: When exiting emacs, don't ask the user to confirm killing processes (#83), (continued)
- [elpa] 1.2 989647a 049/101: When exiting emacs, don't ask the user to confirm killing processes (#83), Christian Johansson, 2021/04/29
- [elpa] 1.2 ce9076d 047/101: Close #82: Correctly delete text before expanding snippet completions, Christian Johansson, 2021/04/29
- [elpa] 1.2 746505f 072/101: Require subr-x at compile time (#139), Christian Johansson, 2021/04/29
- [elpa] 1.2 eec30e3 070/101: Fix misspelling of "outstanding" (#74), Christian Johansson, 2021/04/29
- [elpa] 1.2 ff62057 071/101: Fix #138: accept deprecated field in SymbolInformation, Christian Johansson, 2021/04/29
- [elpa] 1.2 f317a7d 069/101: * eglot-tests.el: Disable eclipse connection tests., Christian Johansson, 2021/04/29
- [elpa] 1.2 ff92d67 073/101: Remove duplicates from imenu, Christian Johansson, 2021/04/29
- [elpa] 1.2 660d9e3 078/101: Slightly robustify test engine, Christian Johansson, 2021/04/29
- [elpa] 1.2 da4cd2a 083/101: Make imenu hierarchical, Christian Johansson, 2021/04/29
- [elpa] 1.2 912d10f 088/101: Fix a bug introduced by previous bugfix, Christian Johansson, 2021/04/29
- [elpa] 1.2 8529b55 089/101: Fix #124: add ability to move to LSP-precise columns,
Christian Johansson <=
- [elpa] 1.2 90b3bfd 090/101: Fix #148: complex completions work when chosen from *completions*, Christian Johansson, 2021/04/29
- [elpa] 1.2 63c2bbc 092/101: Add support for TextEdits in completion, Christian Johansson, 2021/04/29
- [elpa] 1.2 d52738f 095/101: Treat tab characters as 1 column wide in position conversion functions, Christian Johansson, 2021/04/29
- [elpa] 1.2 7e9cc05 098/101: Fix #154: fix potential security issue fontifying LSP doc, Christian Johansson, 2021/04/29
- [elpa] 1.2 2bbf06e 097/101: Add support for R's languageserver (#161), Christian Johansson, 2021/04/29
- [elpa] 1.2 c667d79 093/101: Fix #125: add ability to report LSP-compliant columns, Christian Johansson, 2021/04/29
- [elpa] 1.2 a39a446 020/101: Close #61: Snappier completions that don't hinder typing, Christian Johansson, 2021/04/29
- [elpa] 1.2 2e21c12 084/101: * eglot.el (eglot-client-capabilities): Mention supported SymbolKinds., Christian Johansson, 2021/04/29
- [elpa] 1.2 9cee9eb 086/101: Move constants to top instead of forward-declaring, Christian Johansson, 2021/04/29
- [elpa] 1.2 fc9bbf7 096/101: Fix #160: Properly delete inserted text after completion, Christian Johansson, 2021/04/29