[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 0a18dca 37/45: Fix #125: add ability to report LS
From: |
João Távora |
Subject: |
[elpa] externals/eglot 0a18dca 37/45: Fix #125: add ability to report LSP-compliant columns |
Date: |
Thu, 22 Nov 2018 19:15:32 -0500 (EST) |
branch: externals/eglot
commit 0a18dca4cafa9c95f2f7341d7eab39e702c173e3
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Fix #125: add ability to report LSP-compliant columns
* eglot.el (eglot-current-column-function): New variable.
(eglot-lsp-abiding-column): New helper.
(eglot--pos-to-lsp-position): Use eglot-current-column-function.
(eglot-move-to-column-function): Tweak docstring.
---
eglot.el | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/eglot.el b/eglot.el
index d4a8b6f..2c0b22e 100644
--- a/eglot.el
+++ b/eglot.el
@@ -721,26 +721,42 @@ CONNECT-ARGS are passed as additional arguments to
(let ((warning-minimum-level :error))
(display-warning 'eglot (apply #'format format args) :warning)))
+(defvar eglot-current-column-function #'current-column
+ "Function to calculate the current column.
+
+This is the inverse operation of
+`eglot-move-to-column-function' (which see). It is a function of
+no arguments returning a column number. For buffers managed by
+fully LSP-compliant servers, this should be set to
+`eglot-lsp-abiding-column', and `current-column' (the default)
+for all others.")
+
+(defun eglot-lsp-abiding-column ()
+ "Calculate current COLUMN as defined by the LSP spec."
+ (/ (- (length (encode-coding-region (line-beginning-position)
+ (point) 'utf-16 t))
+ 2)
+ 2))
+
(defun eglot--pos-to-lsp-position (&optional pos)
"Convert point POS to LSP position."
(eglot--widening
(list :line (1- (line-number-at-pos pos t)) ; F!@&#$CKING OFF-BY-ONE
- :character (- (goto-char (or pos (point)))
- (line-beginning-position)))))
+ :character (progn (when pos (goto-char pos))
+ (funcall eglot-current-column-function)))))
(defvar eglot-move-to-column-function #'move-to-column
- "How to move to a column reported by the LSP server.
+ "Function 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.
+`c'. However, many servers don't follow the spec this closely.
-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.")
+For buffers managed by fully LSP-compliant servers, this should
+be set to `eglot-move-to-lsp-abiding-column', and
+`move-to-column' (the default) for all others.")
(defun eglot-move-to-lsp-abiding-column (column)
"Move to COLUMN abiding by the LSP spec."
- [elpa] externals/eglot 3c180c0 19/45: Rework test macros for hopefully more stable testing, (continued)
- [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
- [elpa] externals/eglot fc03d7c 40/45: Fix #160: Properly delete inserted text after completion, João Távora, 2018/11/22
- [elpa] externals/eglot 604c1b0 38/45: Per #144: Format documentation of signature parameters, João Távora, 2018/11/22
- [elpa] externals/eglot 894fe5a 42/45: Fix #154: fix potential security issue fontifying LSP doc, João Távora, 2018/11/22
- [elpa] externals/eglot b9e9cf3 34/45: Fix #148: complex completions work when chosen from *completions*, João Távora, 2018/11/22
- [elpa] externals/eglot 0a18dca 37/45: Fix #125: add ability to report LSP-compliant columns,
João Távora <=
- [elpa] externals/eglot f291816 45/45: * eglot.el (Version): Bump to 1.2, João Távora, 2018/11/22
- [elpa] externals/eglot ee7f9c6 43/45: Fix #167: correctly insert TextEdit-less snippets, João Távora, 2018/11/22