Commit e0b9944b authored by João Távora's avatar João Távora
Browse files

Jsonrpc: overhaul logging mechanics

* lisp/jsonrpc.el (jsonrpc-connection): Rework.
(initialize-instance :after jsonrpc-connection): New method.
(slot-missing jsonrpc-connection :events-buffer-scrollback-size oset):
New hack.
(jsonrpc-connection-receive): Rework.
(initialize-instance :after jsonrpc-process-connection): Rework
from non-after version.
(jsonrpc-connection-send)
(jsonrpc--call-deferred)
(jsonrpc--process-sentinel)
(jsonrpc--async-request-1, jsonrpc--debug, jsonrpc--log-event)
(jsonrpc--forwarding-buffer): Rework.
(jsonrpc--run-event-hook): New helper.
(jsonrpc-event-hook): New hook.

* lisp/progmodes/eglot.el (eglot-lsp-server): Fix project slot
initform.
(eglot--connect): Use new jsonrpc-connection initarg.

* test/lisp/progmodes/eglot-tests.el (eglot--sniffing): Use
jsonrpc-event-hook.
(eglot-test-basic-completions): Fix test.
parent 4adc67c5
Pipeline #27577 failed with stage
in 1 minute and 58 seconds
This diff is collapsed.
......@@ -993,6 +993,7 @@ ACTION is an LSP object of either `CodeAction' or `Command' type."
:documentation "Flag set when server is shutting down."
:accessor eglot--shutdown-requested)
(project
:initform nil
:documentation "Project associated with server."
:accessor eglot--project)
(progress-reporters
......@@ -1512,7 +1513,7 @@ This docstring appeases checkdoc, that's all."
(apply
#'make-instance class
:name readable-name
:events-buffer-scrollback-size eglot-events-buffer-size
:events-buffer-config `(:size ,eglot-events-buffer-size :format full)
:notification-dispatcher (funcall spread #'eglot-handle-notification)
:request-dispatcher (funcall spread #'eglot-handle-request)
:on-shutdown #'eglot--on-shutdown
......
......@@ -199,38 +199,40 @@ directory hierarchy."
&rest body)
"Run BODY saving LSP JSON messages in variables, most recent first."
(declare (indent 1) (debug (sexp &rest form)))
(let ((log-event-ad-sym (make-symbol "eglot--event-sniff")))
`(unwind-protect
(let ,(delq nil (list server-requests
server-notifications
server-replies
client-requests
client-notifications
client-replies))
(advice-add
#'jsonrpc--log-event :before
(lambda (_proc message &optional origin subtype)
(let ((req-p (eq subtype 'request))
(notif-p (eq subtype 'notification))
(reply-p (eql subtype 'reply)))
(cond
((eq origin 'server)
(cond (req-p ,(when server-requests
`(push message ,server-requests)))
(notif-p ,(when server-notifications
`(push message ,server-notifications)))
(reply-p ,(when server-replies
`(push message ,server-replies)))))
((eq origin 'client)
(cond (req-p ,(when client-requests
`(push message ,client-requests)))
(notif-p ,(when client-notifications
`(push message ,client-notifications)))
(reply-p ,(when client-replies
`(push message ,client-replies))))))))
'((name . ,log-event-ad-sym)))
,@body)
(advice-remove #'jsonrpc--log-event ',log-event-ad-sym))))
(let ((log-event-hook-sym (make-symbol "eglot--event-sniff")))
`(let* (,@(delq nil (list server-requests
server-notifications
server-replies
client-requests
client-notifications
client-replies)))
(cl-flet ((,log-event-hook-sym (_connection
origin
&key _json kind message _foreign-message
&allow-other-keys)
(let ((req-p (eq kind 'request))
(notif-p (eq kind 'notification))
(reply-p (eql kind 'reply)))
(cond
((eq origin 'server)
(cond (req-p ,(when server-requests
`(push message ,server-requests)))
(notif-p ,(when server-notifications
`(push message ,server-notifications)))
(reply-p ,(when server-replies
`(push message ,server-replies)))))
((eq origin 'client)
(cond (req-p ,(when client-requests
`(push message ,client-requests)))
(notif-p ,(when client-notifications
`(push message ,client-notifications)))
(reply-p ,(when client-replies
`(push message ,client-replies)))))))))
(unwind-protect
(progn
(add-hook 'jsonrpc-event-hook #',log-event-hook-sym)
,@body)
(remove-hook 'jsonrpc-event-hook #',log-event-hook-sym))))))
(cl-defmacro eglot--wait-for ((events-sym &optional (timeout 1) message) args &body body)
(declare (indent 2) (debug (sexp sexp sexp &rest form)))
......@@ -542,10 +544,7 @@ directory hierarchy."
`(("project" . (("coiso.c" . "#include <stdio.h>\nint main () {fprin"))))
(with-current-buffer
(eglot--find-file-noselect "project/coiso.c")
(eglot--sniffing (:server-notifications s-notifs)
(eglot--wait-for-clangd)
(eglot--wait-for (s-notifs 20) (&key method &allow-other-keys)
(string= method "textDocument/publishDiagnostics")))
(eglot--wait-for-clangd)
(goto-char (point-max))
(completion-at-point)
(message (buffer-string))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment