[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot c7bd095 118/139: Improve eglot-eldoc-function
From: |
Jo�o T�vora |
Subject: |
[elpa] externals/eglot c7bd095 118/139: Improve eglot-eldoc-function |
Date: |
Mon, 14 May 2018 09:55:05 -0400 (EDT) |
branch: externals/eglot
commit c7bd0952335bab43667974f15672b9fa3c99913e
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Improve eglot-eldoc-function
Use the :range key if the server provided it. Also simplify code with
a new eglot--with-lsp-range macro.
* eglot.el (eglot--format-markup): Tweak comment.
(eglot--with-lsp-range): New helper macro.
(eglot--server-textDocument/publishDiagnostics)
(eglot--apply-text-edits): Use it.
(eglot-eldoc-function): Use range if server provides it.
---
eglot.el | 69 +++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 38 insertions(+), 31 deletions(-)
diff --git a/eglot.el b/eglot.el
index d1e4d15..b2709a6 100644
--- a/eglot.el
+++ b/eglot.el
@@ -740,7 +740,7 @@ DEFERRED is passed to `eglot--request', which see."
"Format MARKUP according to LSP's spec."
(cond ((stringp markup)
(with-temp-buffer
- (ignore-errors (funcall (intern "markdown-mode"))) ;escape
bytecompiler
+ (ignore-errors (funcall (intern "markdown-mode"))) ;escape bytecomp
(font-lock-ensure)
(insert markup)
(string-trim (buffer-string))))
@@ -757,6 +757,15 @@ DEFERRED is passed to `eglot--request', which see."
"Determine if current server is capable of FEAT."
(plist-get (eglot--capabilities (eglot--current-process-or-lose)) feat))
+(cl-defmacro eglot--with-lsp-range ((start end) range &body body
+ &aux (range-sym (cl-gensym)))
+ "Bind LSP RANGE to START and END. Evaluate BODY."
+ (declare (indent 2) (debug (sexp sexp &rest form)))
+ `(let* ((,range-sym ,range)
+ (,start (eglot--lsp-position-to-point (plist-get ,range-sym :start)))
+ (,end (eglot--lsp-position-to-point (plist-get ,range-sym :end))))
+ ,@body))
+
;;; Minor modes
;;;
@@ -965,17 +974,13 @@ called interactively."
collect (cl-destructuring-bind (&key range severity _group
_code source message)
diag-spec
- (cl-destructuring-bind (&key start end)
- range
- (let* ((begin-pos (eglot--lsp-position-to-point start))
- (end-pos (eglot--lsp-position-to-point end)))
- (flymake-make-diagnostic
- (current-buffer)
- begin-pos end-pos
- (cond ((<= severity 1) :error)
- ((= severity 2) :warning)
- (t :note))
- (concat source ": " message)))))
+ (eglot--with-lsp-range (beg end) range
+ (flymake-make-diagnostic (current-buffer)
+ beg end
+ (cond ((<= severity 1) :error)
+ ((= severity 2) :warning)
+ (t :note))
+ (concat source ": " message))))
into diags
finally (cond (eglot--current-flymake-report-fn
(funcall eglot--current-flymake-report-fn diags)
@@ -1302,15 +1307,23 @@ DUMMY is ignored"
(proc (eglot--current-process-or-lose))
(position-params (eglot--current-buffer-TextDocumentPositionParams)))
(when (eglot--server-capable :hoverProvider)
- (eglot--request proc :textDocument/hover position-params
- :success-fn (eglot--lambda (&key contents _range)
- (eldoc-message
- (mapconcat #'eglot--format-markup
- (if (vectorp contents)
- contents
- (list contents))
- "\n")))
- :deferred :textDocument/hover))
+ (eglot--request
+ proc :textDocument/hover position-params
+ :success-fn (eglot--lambda (&key contents range)
+ (when (get-buffer-window buffer)
+ (with-current-buffer buffer
+ (eldoc-message
+ (concat
+ (and range
+ (eglot--with-lsp-range (beg end) range
+ (concat (buffer-substring beg end) ": ")))
+ (mapconcat #'eglot--format-markup
+ (append
+ (cond ((vectorp contents)
+ contents)
+ (contents
+ (list contents)))) "\n"))))))
+ :deferred :textDocument/hover))
(when (eglot--server-capable :documentHighlightProvider)
(eglot--request
proc :textDocument/documentHighlight position-params
@@ -1321,11 +1334,8 @@ DUMMY is ignored"
(with-current-buffer buffer
(eglot--mapply
(eglot--lambda (&key range kind)
- (cl-destructuring-bind (&key start end) range
- (let ((ov (make-overlay
- (eglot--lsp-position-to-point
start)
- (eglot--lsp-position-to-point
end)
- buffer)))
+ (eglot--with-lsp-range (beg end) range
+ (let ((ov (make-overlay beg end)))
(overlay-put ov 'face 'highlight)
(overlay-put ov 'evaporate t)
(overlay-put ov :kind kind)
@@ -1366,11 +1376,8 @@ DUMMY is ignored"
(save-restriction
(widen)
(save-excursion
- (let ((start (eglot--lsp-position-to-point (plist-get range
:start))))
- (goto-char start)
- (delete-region start
- (eglot--lsp-position-to-point (plist-get range
:end)))
- (insert newText)))))
+ (eglot--with-lsp-range (beg end) range
+ (goto-char beg) (delete-region beg end) (insert newText)))))
edits)
(eglot--message "%s: Performed %s edits" (current-buffer) (length edits))))
- [elpa] externals/eglot a199c8e 070/139: Honour textDocumentSync, (continued)
- [elpa] externals/eglot a199c8e 070/139: Honour textDocumentSync, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot e86f9b4 073/139: New helper eglot--sync-request, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot 1add335 078/139: Workaround two suspected Emacs bugs, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot 889ef20 085/139: Tweak the async request engine., Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot 193c57d 075/139: Half-decent xref support, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot fc6879f 084/139: Explain why didOpen on after-revert-hook is a bad idea, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot 24466a9 096/139: When killing server, always wait 3 seconds, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot fceb6bb 090/139: Get rid of eglot--special-buffer-process, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot d254f97 082/139: Solve another textDocument/didChange bug, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot f257d63 089/139: * eglot.el: Reformat to shave off some lines., Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot c7bd095 118/139: Improve eglot-eldoc-function,
Jo�o T�vora <=
- [elpa] externals/eglot 3e0f1c3 122/139: Misc little adjustments for readability, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot 3dcbc30 109/139: Add minimal headers, commentary and autoloads, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot 71e47d2 102/139: Fix odd bugs and tweak stuff, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot 05c67ee 112/139: Adjust flymake integration, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot 9ff97a6 079/139: Increase request timeout length to 10 seconds, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot 571b08f 076/139: Fix the odd bug here and there, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot a7ddce6 080/139: Support javascript's javascript-typescript-langserver, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot d40f9ac 094/139: Half-decent imenu support via textDocument/documentSymbol, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot bbc64b4 087/139: Clean up client capabilities, Jo�o T�vora, 2018/05/14
- [elpa] externals/eglot 9882bf2 072/139: Cleanup mistake with TextDocumentItem and TextDocumentIdentifier, Jo�o T�vora, 2018/05/14