[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/elpa 571b08f 076/139: Fix the odd bug here and there
From: |
João Távora |
Subject: |
[elpa] externals/elpa 571b08f 076/139: Fix the odd bug here and there |
Date: |
Mon, 14 May 2018 09:53:39 -0400 (EDT) |
branch: externals/elpa
commit 571b08f52bf8420a5e0bb3cfa727235048d94ba6
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Fix the odd bug here and there
* eglot.el (eglot--connect): Activate editing mode where
applicable here.
(eglot, eglot-reconnect): Not here or here.
(eglot--process-sentinel): Catch auto-reconnect errors.
(eglot--notify): Dont send 'id=null', it messes up js's lsp
(eglot--reply): Do send id here.
(eglot--log-event): Simplify protocol. Complexify implementation.
(eglot--process-receive, eglot--process-send): Simplify
eglot--log-event call.
(eglot--request, eglot--notify, eglot--reply): Simplify
eglot--process-send call
(eglot--server-client/registerCapability): Fix bug when replying
with wrong id.
(eglot--xref-reset-known-symbols): Take DUMMY arg.
---
eglot.el | 131 +++++++++++++++++++++++++++++----------------------------------
1 file changed, 61 insertions(+), 70 deletions(-)
diff --git a/eglot.el b/eglot.el
index cb92361..d6ecdfe 100644
--- a/eglot.el
+++ b/eglot.el
@@ -265,6 +265,9 @@ SUCCESS-FN with no args if all goes well."
(lambda (&key capabilities)
(setf (eglot--capabilities proc) capabilities)
(setf (eglot--status proc) nil)
+ (dolist (buffer (buffer-list))
+ (with-current-buffer buffer
+ (eglot--maybe-activate-editing-mode proc)))
(when success-fn (funcall success-fn proc))
(eglot--notify proc :initialized (eglot--obj :__dummy__ t)))))))))
@@ -344,10 +347,7 @@ INTERACTIVE is t if called interactively."
buffers in project %s."
proc
managed-major-mode
- short-name)
- (dolist (buffer (buffer-list))
- (with-current-buffer buffer
- (eglot--maybe-activate-editing-mode proc)))))))))
+ short-name)))))))
(defun eglot-reconnect (process &optional interactive)
"Reconnect to PROCESS.
@@ -360,11 +360,7 @@ INTERACTIVE is t if called interactively."
(eglot--major-mode process)
(eglot--short-name process)
(eglot--contact process)
- (lambda (proc)
- (eglot--message "Reconnected!")
- (dolist (buffer (buffer-list))
- (with-current-buffer buffer
- (eglot--maybe-activate-editing-mode proc))))))
+ (lambda (_proc) (eglot--message "Reconnected!"))))
(defvar eglot--inhibit-auto-reconnect nil
"If non-nil, don't autoreconnect on unexpected quit.")
@@ -397,9 +393,11 @@ INTERACTIVE is t if called interactively."
(process-exit-status process)))
((null eglot--inhibit-auto-reconnect)
(eglot--warn
- "(sentinel) Reconnecting after process unexpectedly changed to %s."
+ "(sentinel) Reconnecting after process unexpectedly changed to
`%s'."
change)
- (eglot-reconnect process)
+ (condition-case-unless-debug err
+ (eglot-reconnect process)
+ (error (eglot--warn "Auto-reconnect failed: %s " err) ))
(setq eglot--inhibit-auto-reconnect
(run-with-timer
3 nil
@@ -493,13 +491,22 @@ INTERACTIVE is t if called interactively."
(display-buffer buffer))
buffer))
-(defun eglot--log-event (proc type message &optional id error)
+(defun eglot--log-event (proc message type)
"Log an eglot-related event.
-PROC is the current process. TYPE is an identifier. MESSAGE is
-a JSON-like plist or anything else. ID is a continuation
-identifier. ERROR is non-nil if this is a JSON-RPC error."
+PROC is the current process. MESSAGE is a JSON-like plist. TYPE
+is a symbol saying if this is a client or server originated."
(with-current-buffer (eglot-events-buffer proc)
- (let ((inhibit-read-only t))
+ (let* ((inhibit-read-only t)
+ (id (plist-get message :id))
+ (error (plist-get message :error))
+ (method (plist-get message :method))
+ (subtype (cond ((and method id) 'request)
+ (method 'notification)
+ (id 'reply)
+ ;; pyls keeps on sending these
+ (t 'unexpected-thingy)))
+ (type
+ (format "%s-%s" type subtype)))
(goto-char (point-max))
(let ((msg (format "%s%s%s:\n%s\n"
type
@@ -518,15 +525,7 @@ identifier. ERROR is non-nil if this is a JSON-RPC error."
(continuations (and id
(not method)
(gethash id (eglot--pending-continuations
proc)))))
- (eglot--log-event proc
- (cond ((and method id) 'server-request)
- (method 'server-notification)
- (continuations 'server-reply)
- ;; pyls keeps on sending these
- (t 'unexpected-server-thingy))
- message
- id
- err)
+ (eglot--log-event proc message 'server)
(when err (setf (eglot--status proc) '("error" t)))
(cond (method
;; a server notification or a server request
@@ -557,19 +556,13 @@ identifier. ERROR is non-nil if this is a JSON-RPC
error."
(defvar eglot--expect-carriage-return nil)
-(defun eglot--process-send (id proc message &optional reply)
+(defun eglot--process-send (proc message)
"Send MESSAGE to PROC (ID is optional)."
- (let* ((json (json-encode message))
- (to-send (format "Content-Length: %d\r\n\r\n%s"
- (string-bytes json)
- json)))
- (process-send-string proc to-send)
- (eglot--log-event proc (if id
- (if reply
- 'client-reply
- 'client-request)
- 'client-notification)
- message id (plist-get message :error))))
+ (let ((json (json-encode message)))
+ (process-send-string proc (format "Content-Length: %d\r\n\r\n%s"
+ (string-bytes json)
+ json))
+ (eglot--log-event proc message 'client)))
(defvar eglot--next-request-id 0)
@@ -614,8 +607,7 @@ identifier. ERROR is non-nil if this is a JSON-RPC error."
"(request) Request id=%s replied to with result=%s: %s"
id result-body)))))
(catch-tag (cl-gensym (format "eglot--tag-%d-" id))))
- (eglot--process-send id
- process
+ (eglot--process-send process
(eglot--obj :jsonrpc "2.0"
:id id
:method method
@@ -678,21 +670,18 @@ Meaning only return locally if successful, otherwise exit
non-locally."
(cl-defun eglot--notify (process method params)
"Notify PROCESS of something, don't expect a reply.e"
- (eglot--process-send nil
- process
+ (eglot--process-send process
(eglot--obj :jsonrpc "2.0"
- :id nil
:method method
:params params)))
(cl-defun eglot--reply (process id &key result error)
"Reply to PROCESS's request ID with MESSAGE."
- (eglot--process-send id process
+ (eglot--process-send process
(eglot--obj :jsonrpc "2.0"
- :id nil
+ :id id
:result result
- :error error)
- t))
+ :error error)))
;;; Helpers
@@ -1057,28 +1046,29 @@ running. INTERACTIVE is t if called interactively."
(cl-defun eglot--server-client/registerCapability
(proc &key id registrations)
"Handle notification client/registerCapability"
- (catch 'done
- (mapc
- (lambda (reg)
- (apply
- (cl-function
- (lambda (&key id method registerOptions)
- (pcase-let*
- ((handler-sym (intern (concat "eglot--register-"
- method)))
- (`(,ok ,message)
- (and (functionp handler-sym)
- (apply handler-sym proc :id id registerOptions))))
- (unless ok
- (throw
- 'done
- (eglot--reply proc id
- :error (eglot--obj
- :code -32601
- :message (or message "sorry :-("))))))))
- reg))
- registrations)
- (eglot--reply proc id :result (eglot--obj :message "OK"))))
+ (let ((jsonrpc-id id))
+ (catch 'done
+ (mapc
+ (lambda (reg)
+ (apply
+ (cl-function
+ (lambda (&key id method registerOptions)
+ (pcase-let*
+ ((handler-sym (intern (concat "eglot--register-"
+ method)))
+ (`(,ok ,message)
+ (and (functionp handler-sym)
+ (apply handler-sym proc :id id registerOptions))))
+ (unless ok
+ (throw
+ 'done
+ (eglot--reply proc jsonrpc-id
+ :error (eglot--obj
+ :code -32601
+ :message (or message "sorry
:-("))))))))
+ reg))
+ registrations)
+ (eglot--reply proc id :result (eglot--obj :message "OK")))))
(defvar eglot--recent-before-changes nil
"List of recent changes as collected by `eglot--before-change'.")
@@ -1236,8 +1226,9 @@ Calls REPORT-FN maybe if server publishes diagnostics in
time."
(defvar eglot--xref-known-symbols nil)
-(defun eglot--xref-reset-known-symbols ()
- "Reset `eglot--xref-reset-known-symbols'."
+(defun eglot--xref-reset-known-symbols (&rest _dummy)
+ "Reset `eglot--xref-reset-known-symbols'.
+DUMMY is ignored"
(setq eglot--xref-known-symbols nil))
(advice-add 'xref-find-definitions :after #'eglot--xref-reset-known-symbols)
- [elpa] externals/elpa 9af84a2 124/139: Prepare to sumbit to GNU ELPA, (continued)
- [elpa] externals/elpa 9af84a2 124/139: Prepare to sumbit to GNU ELPA, João Távora, 2018/05/14
- [elpa] externals/elpa 9577dfc 125/139: Duh, json.el is in Emacs, and json-mode.el is useless here, João Távora, 2018/05/14
- [elpa] externals/elpa 6e76b08 100/139: Support workspace/applyEdit, João Távora, 2018/05/14
- [elpa] externals/elpa 3e0f1c3 122/139: Misc little adjustments for readability, João Távora, 2018/05/14
- [elpa] externals/elpa 9bf3166 136/139: Don't define a menu if nothing to show there for now, João Távora, 2018/05/14
- [elpa] externals/elpa 1fb2bcb 132/139: Ask server for textDocument/signatureHelp if it supports it, João Távora, 2018/05/14
- [elpa] externals/elpa c7bd095 118/139: Improve eglot-eldoc-function, João Távora, 2018/05/14
- [elpa] externals/elpa ab575d2 120/139: Rename functions. eglot--request is now the synchronous one, João Távora, 2018/05/14
- [elpa] externals/elpa 8448d9b 133/139: Work with any old directory, no formal project needed, João Távora, 2018/05/14
- [elpa] externals/elpa 589e1ea 138/139: Remove an unused variable, João Távora, 2018/05/14
- [elpa] externals/elpa 571b08f 076/139: Fix the odd bug here and there,
João Távora <=
- [elpa] externals/elpa c4ffabc 083/139: Half-decent completion support, João Távora, 2018/05/14
- [elpa] externals/elpa 71e47d2 102/139: Fix odd bugs and tweak stuff, João Távora, 2018/05/14
- [elpa] externals/elpa ecd334f 101/139: Update README, João Távora, 2018/05/14
- [elpa] externals/elpa dda11dd 095/139: Try to fix some textDocument/completion bugs, João Távora, 2018/05/14
- [elpa] externals/elpa bfd82b5 108/139: Fancier RLS spinner, João Távora, 2018/05/14
- [elpa] externals/elpa c7b9002 116/139: Only call deferred actions after a full message has been received, João Távora, 2018/05/14
- [elpa] externals/elpa dc08e8e 134/139: Fix automatic project creation, João Távora, 2018/05/14
- [elpa] externals/elpa e63dad0 092/139: Simplify mode-line code with a helper., João Távora, 2018/05/14
- [elpa] externals/elpa e964abe 091/139: Get rid of eglot--buffer-open-count, João Távora, 2018/05/14
- [elpa] externals/elpa 37b7329 098/139: Reasonable textDocument/documentHighlight support, João Távora, 2018/05/14