Skip to content

Commit

Permalink
Merge branch 'jsonrpc-refactor', bump version to 1.0
Browse files Browse the repository at this point in the history
* eglot.el (Version): Bump to 1.0
  • Loading branch information
joaotavora committed Jun 22, 2018
2 parents 0176264 + 0f20fdf commit f385d9c
Show file tree
Hide file tree
Showing 6 changed files with 1,335 additions and 715 deletions.
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# Variables
#
EMACS=emacs
SELECTOR=t

LOAD_PATH=-L .

ELFILES := eglot.el eglot-tests.el
ELFILES := eglot.el jsonrpc.el eglot-tests.el jsonrpc-tests.el
ELCFILES := $(ELFILES:.el=.elc)

all: compile
Expand All @@ -20,13 +21,17 @@ compile: $(ELCFILES)

# Automated tests
#
check: compile

check: SELECTOR=t
check: compile
eglot-check: compile
$(EMACS) -Q --batch $(LOAD_PATH) \
-l eglot-tests \
-f ert-run-tests-batch-and-exit \
--eval '(ert-run-tests-batch-and-exit (quote $(SELECTOR)))'

jsonrpc-check: jsonrpc.elc jsonrpc-tests.elc
$(EMACS) -Q --batch $(LOAD_PATH) \
-l jsonrpc-tests \
--eval '(ert-run-tests-batch-and-exit (quote $(SELECTOR)))'

check: eglot-check jsonrpc-check

# Cleanup
#
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Here's a summary of available commands:
- `M-x eglot-rename` ask the server to rename the symbol at point;

- `M-x eglot-format-buffer` ask the server to reformat the current
buffer.
buffer;

- `M-x eglot-code-actions` asks the server for any code actions at
point. These may tipically be simple fixes, like deleting an unused
Expand Down Expand Up @@ -222,9 +222,7 @@ Under the hood:
- Doesn't *require* anything other than Emacs 26, but will
automatically upgrade to work with stuff outside Emacs, like
`company`, `markdown-mode`, if you happen to have these installed.
- Contained in one file
- Has automated tests that check against actual LSP servers

- Has automated tests that check against actual LSP servers.

[lsp]: https://microsoft.github.io/language-server-protocol/
[rls]: https://github.com/rust-lang-nursery/rls
Expand Down
32 changes: 15 additions & 17 deletions eglot-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
(message "[yas] oops don't know this content")))))

(defun eglot--call-with-dirs-and-files (dirs fn)
(let* ((default-directory (make-temp-file "eglot--fixture" t))
(let* ((fixture-directory (make-temp-file "eglot--fixture" t))
(default-directory fixture-directory)
new-buffers new-servers)
(unwind-protect
(let ((find-file-hook
Expand All @@ -63,16 +64,15 @@
(eglot--message "Killing buffers %s, deleting %s, killing %s"
(mapconcat #'buffer-name new-buffers ", ")
default-directory
(mapcar #'eglot--name new-servers))
(mapcar #'jsonrpc-name new-servers))
(unwind-protect
(let ((eglot-autoreconnect nil))
(mapc #'eglot-shutdown
(cl-remove-if-not (lambda (server) (process-live-p (eglot--process server)))
new-servers)))
(mapc #'kill-buffer (mapcar #'eglot--events-buffer new-servers))
(cl-remove-if-not #'jsonrpc-running-p new-servers)))
(mapc #'kill-buffer (mapcar #'jsonrpc--events-buffer new-servers))
(dolist (buf new-buffers) ;; have to save otherwise will get prompted
(with-current-buffer buf (save-buffer) (kill-buffer)))
(delete-directory default-directory 'recursive)))))
(delete-directory fixture-directory 'recursive)))))

(cl-defmacro eglot--with-timeout (timeout &body body)
(declare (indent 1) (debug t))
Expand Down Expand Up @@ -124,7 +124,7 @@
client-notifications
client-replies))
(advice-add
#'eglot--log-event :before
#'jsonrpc--log-event :before
(lambda (_proc message &optional type)
(cl-destructuring-bind (&key method id _error &allow-other-keys)
message
Expand All @@ -148,7 +148,7 @@
`(push message ,client-replies)))))))))
'((name . ,log-event-ad-sym)))
,@body)
(advice-remove #'eglot--log-event ',log-event-ad-sym))))
(advice-remove #'jsonrpc--log-event ',log-event-ad-sym))))

(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.
Expand All @@ -165,7 +165,7 @@ Pass TIMEOUT to `eglot--with-timeout'."
(symbol-name method)
1))
when (funcall
(eglot--lambda ,args ,@body) json)
(jsonrpc-lambda ,args ,@body) json)
return (cons json before)
collect json into before)
for i from 0
Expand Down Expand Up @@ -225,16 +225,14 @@ Pass TIMEOUT to `eglot--with-timeout'."
;; In 1.2 seconds > `eglot-autoreconnect' kill servers. We
;; should have a automatic reconnection.
(run-with-timer 1.2 nil (lambda () (delete-process
(eglot--process server))))
(while (process-live-p (eglot--process server))
(accept-process-output nil 0.5))
(jsonrpc--process server))))
(while (jsonrpc-running-p server) (accept-process-output nil 0.5))
(should (eglot--current-server))
;; Now try again too quickly
(setq server (eglot--current-server))
(run-with-timer 0.5 nil (lambda () (delete-process
(eglot--process server))))
(while (process-live-p (eglot--process server))
(accept-process-output nil 0.5))
(let ((proc (jsonrpc--process server)))
(run-with-timer 0.5 nil (lambda () (delete-process proc)))
(while (process-live-p proc) (accept-process-output nil 0.5)))
(should (not (eglot--current-server))))))))

(ert-deftest rls-watches-files ()
Expand Down Expand Up @@ -421,7 +419,7 @@ Pass TIMEOUT to `eglot--with-timeout'."
(eglot--wait-for (s-notifs 1) (&key params method &allow-other-keys)
(and (string= method "textDocument/publishDiagnostics")
(cl-destructuring-bind (&key _uri diagnostics) params
(cl-find-if (eglot--lambda (&key severity &allow-other-keys)
(cl-find-if (jsonrpc-lambda (&key severity &allow-other-keys)
(= severity 1))
diagnostics))))))))))

Expand Down
Loading

0 comments on commit f385d9c

Please sign in to comment.