[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 4548202 28/69: Simplify eldoc usage (#269)
From: |
João Távora |
Subject: |
[elpa] externals/eglot 4548202 28/69: Simplify eldoc usage (#269) |
Date: |
Sun, 20 Oct 2019 08:21:46 -0400 (EDT) |
branch: externals/eglot
commit 4548202afa73edb65b60aaab2a0532f2d63874a9
Author: Ingo Lohmar <address@hidden>
Commit: João Távora <address@hidden>
Simplify eldoc usage (#269)
* eglot-tests.el (hover-after-completions): Protect test. Rewrite
docstring.
* eglot.el (eglot--managed-mode): Don't mess with eldoc-message-function.
(eglot--eldoc-hint): Remove.
(eglot--update-doc): Rename and rewrite from eglot--eldoc-message.
(eglot-eldoc-function): Don't set eglot--eldoc-hint.
Call eglot--update-doc.
---
eglot-tests.el | 28 +++++++++++++++-----------
eglot.el | 63 +++++++++++++++++++++++++++-------------------------------
2 files changed, 45 insertions(+), 46 deletions(-)
diff --git a/eglot-tests.el b/eglot-tests.el
index a037fb6..60c9f2f 100644
--- a/eglot-tests.el
+++ b/eglot-tests.el
@@ -433,19 +433,23 @@ Pass TIMEOUT to `eglot--with-timeout'."
(should (looking-back "sys.exit")))))
(ert-deftest hover-after-completions ()
- "Test basic autocompletion in a python LSP"
+ "Test documentation echo in a python LSP"
(skip-unless (executable-find "pyls"))
- (eglot--with-fixture
- '(("project" . (("something.py" . "import sys\nsys.exi"))))
- (with-current-buffer
- (eglot--find-file-noselect "project/something.py")
- (should (eglot--tests-connect))
- (goto-char (point-max))
- (setq eldoc-last-message nil)
- (completion-at-point)
- (should (looking-back "sys.exit"))
- (while (not eldoc-last-message) (accept-process-output nil 0.1))
- (should (string-match "^exit" eldoc-last-message)))))
+ ;; JT@19/06/21: We check with `eldoc-last-message' because it's
+ ;; practical, which forces us to use
+ ;; `eglot-put-doc-in-help-buffer' to nil.
+ (let ((eglot-put-doc-in-help-buffer nil))
+ (eglot--with-fixture
+ '(("project" . (("something.py" . "import sys\nsys.exi"))))
+ (with-current-buffer
+ (eglot--find-file-noselect "project/something.py")
+ (should (eglot--tests-connect))
+ (goto-char (point-max))
+ (setq eldoc-last-message nil)
+ (completion-at-point)
+ (should (looking-back "sys.exit"))
+ (while (not eldoc-last-message) (accept-process-output nil 0.1))
+ (should (string-match "^exit" eldoc-last-message))))))
(ert-deftest python-autopep-formatting ()
"Test formatting in the pyls python LSP.
diff --git a/eglot.el b/eglot.el
index d470555..aec975c 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1172,7 +1172,6 @@ and just return it. PROMPT shouldn't end with a question
mark."
(add-hook 'pre-command-hook 'eglot--pre-command-hook nil t)
(eglot--setq-saving eldoc-documentation-function #'eglot-eldoc-function)
(eglot--setq-saving flymake-diagnostic-functions '(eglot-flymake-backend
t))
- (add-function :before-until (local 'eldoc-message-function)
#'eglot--eldoc-message)
(add-function :around (local 'imenu-create-index-function) #'eglot-imenu)
(flymake-mode 1)
(eldoc-mode 1))
@@ -1189,7 +1188,6 @@ and just return it. PROMPT shouldn't end with a question
mark."
(remove-hook 'change-major-mode-hook #'eglot--managed-mode-onoff t)
(remove-hook 'post-self-insert-hook 'eglot--post-self-insert-hook t)
(remove-hook 'pre-command-hook 'eglot--pre-command-hook t)
- (remove-function (local 'eldoc-message-function) #'eglot--eldoc-message)
(cl-loop for (var . saved-binding) in eglot--saved-bindings
do (set (make-local-variable var) saved-binding))
(setq eglot--current-flymake-report-fn nil))))
@@ -2050,8 +2048,6 @@ is not active."
(buffer-string))))
when moresigs concat "\n"))
-(defvar eglot--eldoc-hint nil)
-
(defvar eglot--help-buffer nil)
(defun eglot--help-buffer ()
@@ -2100,29 +2096,30 @@ Buffer is displayed with `display-buffer', which obeys
`display-buffer-alist' & friends."
:type 'boolean)
-(defun eglot--eldoc-message (format &rest args)
- (when format
- (let ((string (apply #'format format args))) ;; FIXME: overworking?
- (when (or (eq t eglot-put-doc-in-help-buffer)
- (and eglot-put-doc-in-help-buffer
- (funcall eglot-put-doc-in-help-buffer string)))
- (with-current-buffer (eglot--help-buffer)
- (rename-buffer (format "*eglot-help for %s*" eglot--eldoc-hint))
- (let ((inhibit-read-only t))
- (erase-buffer)
- (insert string)
- (goto-char (point-min))
- (if eglot-auto-display-help-buffer
- (display-buffer (current-buffer))
- (unless (get-buffer-window (current-buffer))
- (eglot--message
- "%s\n(...truncated. Full help is in `%s')"
- (truncate-string-to-width
- (replace-regexp-in-string "\\(.*\\)\n.*" "\\1" string)
- (frame-width) nil nil "...")
- (buffer-name eglot--help-buffer))))
- (help-mode)
- t))))))
+(defun eglot--update-doc (string hint)
+ "Put updated documentation STRING where it belongs.
+Honours `eglot-put-doc-in-help-buffer'. HINT is used to
+potentially rename EGLOT's help buffer."
+ (if (or (eq t eglot-put-doc-in-help-buffer)
+ (and eglot-put-doc-in-help-buffer
+ (funcall eglot-put-doc-in-help-buffer string)))
+ (with-current-buffer (eglot--help-buffer)
+ (rename-buffer (format "*eglot-help for %s*" hint))
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (insert string)
+ (goto-char (point-min))
+ (if eglot-auto-display-help-buffer
+ (display-buffer (current-buffer))
+ (unless (get-buffer-window (current-buffer))
+ (eglot--message
+ "%s\n(...truncated. Full help is in `%s')"
+ (truncate-string-to-width
+ (replace-regexp-in-string "\\(.*\\)\n.*" "\\1" string)
+ (frame-width) nil nil "...")
+ (buffer-name eglot--help-buffer))))
+ (help-mode)))
+ (eldoc-message string)))
(defun eglot-eldoc-function ()
"EGLOT's `eldoc-documentation-function' function.
@@ -2132,7 +2129,6 @@ If SKIP-SIGNATURE, don't try to send
textDocument/signatureHelp."
(position-params (eglot--TextDocumentPositionParams))
sig-showing
(thing-at-point (thing-at-point 'symbol)))
- (setq eglot--eldoc-hint thing-at-point)
(cl-macrolet ((when-buffer-window
(&body body) ; notice the exception when testing with `ert'
`(when (or (get-buffer-window buffer) (ert-running-test))
@@ -2146,10 +2142,10 @@ If SKIP-SIGNATURE, don't try to send
textDocument/signatureHelp."
(when-buffer-window
(when (cl-plusp (length signatures))
(setq sig-showing t)
- (let ((eglot--eldoc-hint thing-at-point))
- (eldoc-message (eglot--sig-info signatures
- activeSignature
- activeParameter))))))
+ (eglot--update-doc (eglot--sig-info signatures
+ activeSignature
+ activeParameter)
+ thing-at-point))))
:deferred :textDocument/signatureHelp))
(when (eglot--server-capable :hoverProvider)
(jsonrpc-async-request
@@ -2160,8 +2156,7 @@ If SKIP-SIGNATURE, don't try to send
textDocument/signatureHelp."
(when-let (info (and contents
(eglot--hover-info contents
range)))
- (let ((eglot--eldoc-hint thing-at-point))
- (eldoc-message info))))))
+ (eglot--update-doc info thing-at-point)))))
:deferred :textDocument/hover))
(when (eglot--server-capable :documentHighlightProvider)
(jsonrpc-async-request
- [elpa] externals/eglot 356100a 19/69: Fix #220: don't sort xref's by default, (continued)
- [elpa] externals/eglot 356100a 19/69: Fix #220: don't sort xref's by default, João Távora, 2019/10/20
- [elpa] externals/eglot 195c311 22/69: Fix local function call in directory watcher (#255), João Távora, 2019/10/20
- [elpa] externals/eglot 2df3991 13/69: Fix #206: Update README.md, João Távora, 2019/10/20
- [elpa] externals/eglot 8d0c8de 05/69: Add NEWS.md file and rework README.md, João Távora, 2019/10/20
- [elpa] externals/eglot b4f3028 18/69: Fix #223: use a less buggy Flymake, João Távora, 2019/10/20
- [elpa] externals/eglot 6c884c4 24/69: Fix #263: fix case when eglot-put-doc-in-help-buffer is nil, João Távora, 2019/10/20
- [elpa] externals/eglot e28b396 25/69: Fix #259: work around a bug in Emacs's change detection, João Távora, 2019/10/20
- [elpa] externals/eglot 2372bc8 30/69: Fixed extra ) in python example snippet (#287), João Távora, 2019/10/20
- [elpa] externals/eglot 6d87de1 35/69: Treat null/nil server capabilities as false, João Távora, 2019/10/20
- [elpa] externals/eglot 7f31f29 36/69: Use gopls server as the default for Go (#304), João Távora, 2019/10/20
- [elpa] externals/eglot 4548202 28/69: Simplify eldoc usage (#269),
João Távora <=
- [elpa] externals/eglot 36b7cf32 38/69: Fix #272: also use signature label offsets for parameter info, João Távora, 2019/10/20
- [elpa] externals/eglot 059ea59 43/69: Optionally shutdown after killing last buffer of managed project (#309), João Távora, 2019/10/20
- [elpa] externals/eglot 59ba0b1 39/69: New README section on how to best report bugs to Eglot, João Távora, 2019/10/20
- [elpa] externals/eglot ce983d1 47/69: Revert "Treat null/nil server capabilities as false", João Távora, 2019/10/20
- [elpa] externals/eglot 4693abf 50/69: Fix #258: Allow user to set idle time to wait before processing changes, João Távora, 2019/10/20
- [elpa] externals/eglot 14ab804 54/69: Fix #318: unbreak xref-find-definitions, João Távora, 2019/10/20
- [elpa] externals/eglot dbb5dd4 57/69: Slightly more robust completion tests, João Távora, 2019/10/20
- [elpa] externals/eglot 3604173 64/69: Unbreak eglot--setq-saving if symbol is unbound, João Távora, 2019/10/20
- [elpa] externals/eglot a11a41b 63/69: Use of company-capf backend in eglot-managed buffers, João Távora, 2019/10/20
- [elpa] externals/eglot 6e93622 27/69: Fix #273: leniently handle invalid positions sent by some servers, João Távora, 2019/10/20