[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 07078da 08/24: Rework eglot-tests.el for better d
From: |
João Távora |
Subject: |
[elpa] externals/eglot 07078da 08/24: Rework eglot-tests.el for better debuggability |
Date: |
Sat, 26 May 2018 14:31:14 -0400 (EDT) |
branch: externals/eglot
commit 07078daefc5691e233f147412aa6cb9bb87ed366
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Rework eglot-tests.el for better debuggability
* eglot-tests.el (eglot--with-timeout): Renamed from
eglot--with-test-timeout.
(eglot--call-with-timeout): Rework.
(eglot--wait-for): Accept TIMEOUT arg.
(auto-detect-running-server, auto-reconnect, rls-watches-files)
(basic-completions, hover-after-completions): Use eglot--with-test-timeout.
(rls-watches-files): Pass TIMEOUT to eglot--wait-for
---
eglot-tests.el | 72 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 39 insertions(+), 33 deletions(-)
diff --git a/eglot-tests.el b/eglot-tests.el
index 718b811..84b09f5 100644
--- a/eglot-tests.el
+++ b/eglot-tests.el
@@ -73,15 +73,19 @@
(with-current-buffer buf (save-buffer) (kill-buffer)))
(delete-directory default-directory 'recursive)))))
-(cl-defmacro eglot--with-test-timeout (timeout &body body)
+(cl-defmacro eglot--with-timeout (timeout &body body)
(declare (indent 1) (debug t))
- `(eglot--call-with-test-timeout ,timeout (lambda () ,@body)))
+ `(eglot--call-with-timeout ',timeout (lambda () ,@body)))
-(defun eglot--call-with-test-timeout (timeout fn)
- (let* ((tag (make-symbol "tag"))
+(defun eglot--call-with-timeout (timeout fn)
+ (let* ((tag (gensym "eglot-test-timeout"))
(timed-out (make-symbol "timeout"))
- (timer )
- (eglot-request-timeout 1)
+ (timeout-and-message
+ (if (listp timeout) timeout
+ (list timeout "waiting for test to finish")))
+ (timeout (car timeout-and-message))
+ (message (cadr timeout-and-message))
+ (timer)
(retval))
(unwind-protect
(setq retval
@@ -94,7 +98,7 @@
(funcall fn)))
(cancel-timer timer)
(when (eq retval timed-out)
- (error "Test timeout!")))))
+ (error "%s" (concat "Timed out " message))))))
(defun eglot--find-file-noselect (file &optional noerror)
(unless (or noerror
@@ -145,17 +149,23 @@
,@body)
(advice-remove #'eglot--log-event ',log-event-ad-sym))))
-(defmacro eglot--wait-for (events-sym fn)
- "Spin until FN match in EVENTS-SYM, discard events after it."
- `(setq ,events-sym
- (cdr
- (cl-loop thereis (cl-loop for json in ,events-sym
- when (funcall ,fn json) return (cons t
before)
- collect json into before)
- do
- ;; `read-event' is essential to have the file
- ;; watchers come through.
- (read-event "" nil 0.1) (accept-process-output nil 0.1)))))
+(defmacro eglot--wait-for (events-sym fn timeout)
+ "Spin until FN match in EVENTS-SYM, flush events after it.
+Pass TIMEOUT to `eglot--with-timeout'."
+ `(eglot--with-timeout ,timeout
+ (let ((event
+ (cl-loop thereis (cl-loop for json in ,events-sym
+ when (funcall ,fn json) return
+ (cons json before)
+ collect json into before)
+ do
+ ;; `read-event' is essential to have the file
+ ;; watchers come through.
+ (read-event "[eglot] Waiting a bit..." nil 0.1)
+ (accept-process-output nil 0.1))))
+ (setq ,events-sym (cdr event))
+ (message "[eglot] Event detected:\n%s"
+ (pp-to-string (car event))))))
;; `rust-mode' is not a part of emacs. So define these two shims which
@@ -175,7 +185,7 @@
'(("project" . (("coiso.rs" . "bla")
("merdix.rs" . "bla")))
("anotherproject" . (("cena.rs" . "bla"))))
- (eglot--with-test-timeout 2
+ (eglot--with-timeout 2
(with-current-buffer
(eglot--find-file-noselect "project/coiso.rs")
(setq proc
@@ -198,7 +208,7 @@
(eglot--with-dirs-and-files
'(("project" . (("coiso.rs" . "bla")
("merdix.rs" . "bla"))))
- (eglot--with-test-timeout 3
+ (eglot--with-timeout 3
(with-current-buffer
(eglot--find-file-noselect "project/coiso.rs")
(setq proc
@@ -223,7 +233,7 @@
(eglot--with-dirs-and-files
'(("project" . (("coiso.rs" . "bla")
("merdix.rs" . "bla"))))
- (eglot--with-test-timeout 3
+ (eglot--with-timeout 10
(with-current-buffer
(eglot--find-file-noselect "project/coiso.rs")
(should (zerop (shell-command "cargo init")))
@@ -233,21 +243,16 @@
:client-replies c-replies
)
(should (eglot 'rust-mode (project-current) '("rls")))
- ;; Wait for a `client/registerCapability' negotiation to
- ;; happen
- ;;
(let (register-id)
(eglot--wait-for s-requests
(eglot--lambda (&key id method
&allow-other-keys)
(setq register-id id)
- (string= method "client/registerCapability")))
+ (string= method "client/registerCapability"))
+ (1 "waiting for registerCapability request"))
(eglot--wait-for c-replies
(eglot--lambda (&key id error &allow-other-keys)
- (and (eq id register-id) (null error)))))
- ;; Now delete "Cargo.toml" and wait for us to send a
- ;; :workspace/didChangeWatchedFiles as a consequence of
- ;; having triggered a file watch.
- ;;
+ (and (eq id register-id) (null error)))
+ (1 "waiting for client reply")))
(delete-file "Cargo.toml")
(eglot--wait-for
c-notifs
@@ -256,14 +261,15 @@
(cl-destructuring-bind (&key uri type)
(elt (plist-get params :changes) 0)
(and (string= (eglot--path-to-uri "Cargo.toml") uri)
- (= type 3))))))))))))
+ (= type 3)))))
+ (3 "waiting for didChangeWatchedFiles notification"))))))))
(ert-deftest basic-completions ()
"Test basic autocompletion in a python LSP"
(skip-unless (executable-find "pyls"))
(eglot--with-dirs-and-files
'(("project" . (("something.py" . "import sys\nsys.exi"))))
- (eglot--with-test-timeout 4
+ (eglot--with-timeout 4
(with-current-buffer
(eglot--find-file-noselect "project/something.py")
(eglot 'python-mode `(transient . ,default-directory) '("pyls"))
@@ -276,7 +282,7 @@
(skip-unless (executable-find "pyls"))
(eglot--with-dirs-and-files
'(("project" . (("something.py" . "import sys\nsys.exi"))))
- (eglot--with-test-timeout 4
+ (eglot--with-timeout 4
(with-current-buffer
(eglot--find-file-noselect "project/something.py")
(eglot 'python-mode `(transient . ,default-directory) '("pyls"))
- [elpa] externals/eglot d673cf7 07/24: Increase test timeout in hopes of convincing Travis CI, (continued)
- [elpa] externals/eglot d673cf7 07/24: Increase test timeout in hopes of convincing Travis CI, João Távora, 2018/05/26
- [elpa] externals/eglot 89baadf 05/24: Fix indentation broken by the defclass monster commit, João Távora, 2018/05/26
- [elpa] externals/eglot 1ef8228 01/24: Introduce eglot-handle-request and eglot-handle-notification as API, João Távora, 2018/05/26
- [elpa] externals/eglot 3a1ff72 04/24: Introduce new API methods for experimental clients to use, João Távora, 2018/05/26
- [elpa] externals/eglot 9c87771 12/24: Introduce eglot--debug for unimportant messages, João Távora, 2018/05/26
- [elpa] externals/eglot 8d4c2c3 13/24: Demote unvisited diagnostics logging to debug level, João Távora, 2018/05/26
- [elpa] externals/eglot 85c5353 11/24: Add cquery support for C/C++ projects, João Távora, 2018/05/26
- [elpa] externals/eglot d40a458 14/24: Log debug messages through eglot--debug, João Távora, 2018/05/26
- [elpa] externals/eglot 17a3257 03/24: Do Rust's RLS hack properly with new class-based API, João Távora, 2018/05/26
- [elpa] externals/eglot 3aa2958 06/24: Add a complex RLS test, João Távora, 2018/05/26
- [elpa] externals/eglot 07078da 08/24: Rework eglot-tests.el for better debuggability,
João Távora <=
- [elpa] externals/eglot 0462130 15/24: New RLS tests, João Távora, 2018/05/26
- [elpa] externals/eglot e1d7ff3 09/24: Disable file-watching tests on Travis, João Távora, 2018/05/26
- [elpa] externals/eglot c8e7ab0 16/24: Don't rely on Flymake's idle timer for textDocument/didChange, João Távora, 2018/05/26
- [elpa] externals/eglot 99ca690 17/24: Simpify eglot--server-receive, João Távora, 2018/05/26
- [elpa] externals/eglot 1b5ed29 21/24: Really ensure eglot--shutdown deletes a process completely, João Távora, 2018/05/26
- [elpa] externals/eglot 897cbc3 24/24: * eglot.el (Version): Bump to 0.5, João Távora, 2018/05/26
- [elpa] externals/eglot ec10de2 23/24: Another unstable test on Travis, João Távora, 2018/05/26
- [elpa] externals/eglot d0fb9d2 22/24: Merge branch 'cquery-support' into master, João Távora, 2018/05/26
- [elpa] externals/eglot 97db670 19/24: Get rid of eglot--obj, an uninteresting abstraction, João Távora, 2018/05/26
- [elpa] externals/eglot 5e3804b 20/24: Add a new test., João Távora, 2018/05/26