branch: externals/eglot commit 433361ee9bb607961ffe13b3a560a7a9001ba216 Author: João Távora <joaotav...@gmail.com> Commit: João Távora <joaotav...@gmail.com>
Add some completion tests for pyls * eglot-tests.el (edebug): Require it. (eglot--call-with-dirs-and-files): Simplify. (eglot--call-with-test-timeout): Don't timeout if edebug. (auto-detect-running-server, auto-reconnect): Skip unless rls is found. (basic-completions): New test. (hover-after-completions): New failing test. * eglot.el (eglot-eldoc-function): Force write eldoc-last-message, for tests sake. --- eglot-tests.el | 74 +++++++++++++++++++++++++++++++++++++++++++--------------- eglot.el | 4 ++-- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/eglot-tests.el b/eglot-tests.el index accb113..3f06732 100644 --- a/eglot-tests.el +++ b/eglot-tests.el @@ -26,6 +26,7 @@ (require 'eglot) (require 'cl-lib) (require 'ert) +(require 'edebug) ;; Helpers @@ -51,24 +52,24 @@ (defun eglot--call-with-dirs-and-files (dirs fn) (let* ((default-directory (make-temp-file "eglot--fixture" t)) new-buffers new-processes) - (with-temp-message "" - (unwind-protect - (let ((find-file-hook - (cons (lambda () (push (current-buffer) new-buffers)) - find-file-hook)) - (eglot-connect-hook - (lambda (proc) (push proc new-processes)))) - (mapc #'eglot--make-file-or-dirs dirs) - (funcall fn)) - (eglot--message "Killing buffers %s, deleting %s, killing %s" - (mapconcat #'buffer-name new-buffers ", ") - default-directory - new-processes) - (delete-directory default-directory 'recursive) - (let ((eglot-autoreconnect nil)) - (mapc #'eglot-shutdown - (cl-remove-if-not #'process-live-p new-processes))) - (mapc #'kill-buffer new-buffers))))) + (unwind-protect + (let ((find-file-hook + (cons (lambda () (push (current-buffer) new-buffers)) + find-file-hook)) + (eglot-connect-hook + (lambda (proc) (push proc new-processes)))) + (mapc #'eglot--make-file-or-dirs dirs) + (funcall fn)) + (eglot--message "Killing buffers %s, deleting %s, killing %s" + (mapconcat #'buffer-name new-buffers ", ") + default-directory + new-processes) + (let ((eglot-autoreconnect nil)) + (mapc #'eglot-shutdown + (cl-remove-if-not #'process-live-p new-processes))) + (dolist (buf new-buffers) ;; have to save otherwise will get prompted + (with-current-buffer buf (save-buffer) (kill-buffer))) + (delete-directory default-directory 'recursive)))) (cl-defmacro eglot--with-test-timeout (timeout &body body) (declare (indent 1) (debug t)) @@ -85,7 +86,9 @@ (catch tag (setq timer (run-with-timer timeout nil - (lambda () (throw tag timed-out)))) + (lambda () + (unless edebug-active + (throw tag timed-out))))) (funcall fn))) (cancel-timer timer) (when (eq retval timed-out) @@ -108,6 +111,7 @@ (ert-deftest auto-detect-running-server () "Visit a file and M-x eglot, then visit a neighbour. " + (skip-unless (executable-find "rls")) (let (proc) (eglot--with-test-timeout 2 (eglot--with-dirs-and-files @@ -130,6 +134,7 @@ (ert-deftest auto-reconnect () "Start a server. Kill it. Watch it reconnect." + (skip-unless (executable-find "rls")) (let (proc (eglot-autoreconnect 1)) (eglot--with-test-timeout 3 @@ -152,6 +157,37 @@ (while (process-live-p proc) (accept-process-output nil 0.5)) (should (not (eglot--current-process)))))))) +(ert-deftest basic-completions () + "Test basic autocompletion in a python LSP" + (skip-unless (executable-find "pyls")) + (unwind-protect + (eglot--with-test-timeout 10 + (eglot--with-dirs-and-files + '(("project" . (("something.py" . "import sys\nsys.exi")))) + (with-current-buffer + (eglot--find-file-noselect "project/something.py") + (eglot 'python-mode `(transient . ,default-directory) '("pyls")) + (goto-char (point-max)) + (completion-at-point) + (should (looking-back "sys.exit")) + ))))) + +(ert-deftest hover-after-completions () + "Test basic autocompletion in a python LSP" + (skip-unless (executable-find "pyls")) + (eglot--with-test-timeout 3 + (eglot--with-dirs-and-files + '(("project" . (("something.py" . "import sys\nsys.exi")))) + (with-current-buffer + (eglot--find-file-noselect "project/something.py") + (eglot 'python-mode `(transient . ,default-directory) '("pyls")) + (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)))))) + (provide 'eglot-tests) ;;; eglot-tests.el ends here diff --git a/eglot.el b/eglot.el index 5829aff..e9da523 100644 --- a/eglot.el +++ b/eglot.el @@ -1429,8 +1429,8 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp." proc :textDocument/hover position-params :success-fn (eglot--lambda (&key contents range) (unless sig-showing - (when-buffer-window - (eldoc-message (eglot--hover-info contents range))))) + (setq eldoc-last-message (eglot--hover-info contents range)) + (when-buffer-window (eldoc-message eldoc-last-message)))) :deferred :textDocument/hover)) (when (eglot--server-capable :documentHighlightProvider) (eglot--async-request