[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 7b4ed97 33/45: Fix #124: add ability to move to L
From: |
João Távora |
Subject: |
[elpa] externals/eglot 7b4ed97 33/45: Fix #124: add ability to move to LSP-precise columns |
Date: |
Thu, 22 Nov 2018 19:15:32 -0500 (EST) |
branch: externals/eglot
commit 7b4ed9736f8ab21adeee0205546d160313ab8b8f
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Fix #124: add ability to move to LSP-precise columns
Also close #125.
Idea and much of design contributed by Michał Krzywkowski
<address@hidden>
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] externals/eglot 5ee05f9 16/45: Require subr-x at compile time (#139), (continued)
- [elpa] externals/eglot 5ee05f9 16/45: Require subr-x at compile time (#139), João Távora, 2018/11/22
- [elpa] externals/eglot d9c3696 15/45: Fix #138: accept deprecated field in SymbolInformation, João Távora, 2018/11/22
- [elpa] externals/eglot 82ae4f6 21/45: Re-enable eclipse-jdt tests, João Távora, 2018/11/22
- [elpa] externals/eglot ee41f06 22/45: Slightly robustify test engine, João Távora, 2018/11/22
- [elpa] externals/eglot faf93ad 13/45: * eglot-tests.el: Disable eclipse connection tests., João Távora, 2018/11/22
- [elpa] externals/eglot c664f40 28/45: * eglot.el (eglot-client-capabilities): Mention supported SymbolKinds., João Távora, 2018/11/22
- [elpa] externals/eglot edc6538 32/45: Fix a bug introduced by previous bugfix, João Távora, 2018/11/22
- [elpa] externals/eglot d6e0ba3 31/45: * eglot-tests.el (eclipse-connect): Increase connect timeout to 20., João Távora, 2018/11/22
- [elpa] externals/eglot 31bfe21 24/45: Add support for code action literals, João Távora, 2018/11/22
- [elpa] externals/eglot 11cd074 29/45: Support ocaml-language-server out of the box (#149), João Távora, 2018/11/22
- [elpa] externals/eglot 7b4ed97 33/45: Fix #124: add ability to move to LSP-precise columns,
João Távora <=
- [elpa] externals/eglot f2ccb77 25/45: Simplify eglot-code-action. Fix compilation warning, João Távora, 2018/11/22
- [elpa] externals/eglot 2a410e9 30/45: Move constants to top instead of forward-declaring, João Távora, 2018/11/22
- [elpa] externals/eglot f74a80f 27/45: Make imenu hierarchical, João Távora, 2018/11/22
- [elpa] externals/eglot 118f966 26/45: Fix a bug when response to definitions request is a single location, João Távora, 2018/11/22
- [elpa] externals/eglot 3c180c0 19/45: Rework test macros for hopefully more stable testing, João Távora, 2018/11/22
- [elpa] externals/eglot b31ba80 35/45: Tweak solution to #125 with a hint from Fangrui Song, João Távora, 2018/11/22
- [elpa] externals/eglot fdb1941 36/45: Add support for TextEdits in completion, João Távora, 2018/11/22
- [elpa] externals/eglot d66f2eb 39/45: Treat tab characters as 1 column wide in position conversion functions, João Távora, 2018/11/22
- [elpa] externals/eglot b731db5 41/45: Add support for R's languageserver (#161), João Távora, 2018/11/22
- [elpa] externals/eglot de1728c 44/45: * eglot.el (eglot-completion-at-point): Less chatter., João Távora, 2018/11/22