[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 0462130 15/24: New RLS tests
From: |
João Távora |
Subject: |
[elpa] externals/eglot 0462130 15/24: New RLS tests |
Date: |
Sat, 26 May 2018 14:31:16 -0400 (EDT) |
branch: externals/eglot
commit 04621301a0f91a00d3b52684509e5c6aa947de06
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
New RLS tests
* eglot-tests.el (eglot--wait-for): Rework macro.
(dummy): Delete test.
(rls-watches-files): Rework test.
(rls-basic-diagnostics, rls-hover-after-edit): New tests.
---
eglot-tests.el | 110 +++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 83 insertions(+), 27 deletions(-)
diff --git a/eglot-tests.el b/eglot-tests.el
index 4abd773..dab5aa6 100644
--- a/eglot-tests.el
+++ b/eglot-tests.el
@@ -150,24 +150,30 @@
,@body)
(advice-remove #'eglot--log-event ',log-event-ad-sym))))
-(defmacro eglot--wait-for (events-sym fn timeout)
+(cl-defmacro eglot--wait-for ((events-sym &optional (timeout 1) message) args
&body body)
"Spin until FN match in EVENTS-SYM, flush events after it.
Pass TIMEOUT to `eglot--with-timeout'."
- `(eglot--with-timeout ,timeout
+ (declare (indent 2) (debug (sexp sexp sexp &rest form)))
+ `(eglot--with-timeout (,timeout ,(or message
+ (format "waiting for:\n%s"
(pp-to-string body))))
(let ((event
(cl-loop thereis (cl-loop for json in ,events-sym
- when (funcall ,fn json) return
- (cons json before)
+ when (funcall
+ (eglot--lambda ,args ,@body) json)
+ return (cons json before)
collect json into before)
+ for i from 0
+ when (zerop (mod i 5))
+ ;; do (eglot--message "still struggling to find in %s"
+ ;; ,events-sym)
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))))))
-
+ (eglot--message "Event detected:\n%s"
+ (pp-to-string (car event))))))
;; `rust-mode' is not a part of emacs. So define these two shims which
;; should be more than enough for testing
@@ -175,9 +181,6 @@ Pass TIMEOUT to `eglot--with-timeout'."
(define-derived-mode rust-mode prog-mode "Rust"))
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
-
-(ert-deftest dummy () "A dummy test" (should t))
-
(ert-deftest auto-detect-running-server ()
"Visit a file and M-x eglot, then visit a neighbour. "
(skip-unless (executable-find "rls"))
@@ -245,25 +248,78 @@ Pass TIMEOUT to `eglot--with-timeout'."
)
(should (apply #'eglot (eglot--interactive)))
(let (register-id)
- (eglot--wait-for s-requests
- (eglot--lambda (&key id method
&allow-other-keys)
- (setq register-id id)
- (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)))
- (1 "waiting for client reply")))
+ (eglot--wait-for (s-requests 1)
+ (&key id method &allow-other-keys)
+ (setq register-id id)
+ (string= method "client/registerCapability"))
+ (eglot--wait-for (c-replies 1)
+ (&key id error &allow-other-keys)
+ (and (eq id register-id) (null error))))
(delete-file "Cargo.toml")
(eglot--wait-for
- c-notifs
- (eglot--lambda (&key method params &allow-other-keys)
- (and (eq method :workspace/didChangeWatchedFiles)
- (cl-destructuring-bind (&key uri type)
- (elt (plist-get params :changes) 0)
- (and (string= (eglot--path-to-uri "Cargo.toml") uri)
- (= type 3)))))
- (3 "waiting for didChangeWatchedFiles notification"))))))))
+ (c-notifs 3 "waiting for didChangeWatchedFiles notification")
+ (&key method params &allow-other-keys)
+ (and (eq method :workspace/didChangeWatchedFiles)
+ (cl-destructuring-bind (&key uri type)
+ (elt (plist-get params :changes) 0)
+ (and (string= (eglot--path-to-uri "Cargo.toml") uri)
+ (= type 3)))))))))))
+
+(ert-deftest rls-basic-diagnostics ()
+ "Hover and highlightChanges are tricky in RLS."
+ (skip-unless (executable-find "rls"))
+ (skip-unless (executable-find "cargo"))
+ (eglot--with-dirs-and-files
+ '(("project" . (("main.rs" . "bla"))))
+ (eglot--with-timeout 3
+ (with-current-buffer
+ (eglot--find-file-noselect "project/main.rs")
+ (should (zerop (shell-command "cargo init")))
+ (eglot--sniffing (:server-notifications s-notifs)
+ (insert "fn main() {\nprintfoo!(\"Hello, world!\");\n}")
+ (apply #'eglot (eglot--interactive))
+ (eglot--wait-for (s-notifs 1)
+ (&key _id method &allow-other-keys)
+ (string= method "textDocument/publishDiagnostics"))
+ (flymake-goto-next-error)
+ (should (eq 'flymake-error (face-at-point))))))))
+
+(ert-deftest rls-hover-after-edit ()
+ "Hover and highlightChanges are tricky in RLS."
+ (skip-unless (executable-find "rls"))
+ (skip-unless (executable-find "cargo"))
+ (eglot--with-dirs-and-files
+ '(("project" . (("main.rs" . "bla"))))
+ (eglot--with-timeout 3
+ (with-current-buffer
+ (eglot--find-file-noselect "project/main.rs")
+ (should (zerop (shell-command "cargo init")))
+ (eglot--sniffing (
+ :server-notifications s-notifs
+ :server-requests s-requests
+ :server-replies s-replies
+ :client-notifications c-notifs
+ :client-replies c-replies
+ :client-requests c-reqs
+ )
+ (insert "fn test() -> i32 { let test=3; return te; }")
+ (apply #'eglot (eglot--interactive))
+ (goto-char (point-min))
+ (search-forward "return te")
+ (insert "st")
+ (progn
+ ;; simulate these two which don't happen when buffer isn't
+ ;; visible in a window.
+ (eglot--signal-textDocument/didChange)
+ (eglot-eldoc-function))
+ (let (pending-id)
+ (eglot--wait-for (c-reqs)
+ (&key id method &allow-other-keys)
+ (setq pending-id id)
+ (string= method :textDocument/documentHighlight))
+ (eglot--wait-for (s-replies)
+ (&key id &allow-other-keys)
+ (eq id pending-id))))))))
(ert-deftest basic-completions ()
"Test basic autocompletion in a python LSP"
- [elpa] externals/eglot 89baadf 05/24: Fix indentation broken by the defclass monster commit, (continued)
- [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, 2018/05/26
- [elpa] externals/eglot 0462130 15/24: New RLS tests,
João Távora <=
- [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
- [elpa] externals/eglot 94c008d 18/24: Cleanup deferred request mechanism with a readable log, João Távora, 2018/05/26