"Politely ask SERVER to quit.
Forcefully quit it if it doesn't respond. Don't leave this
function with the server still running."
- (interactive (list (jsonrpc-current-connection-or-lose) t))
+ (interactive (list (eglot--current-server-or-lose) t))
(eglot--message "Asking %s politely to terminate" (jsonrpc-name server))
(unwind-protect
(progn
(interactive (eglot--interactive))
(let* ((nickname (file-name-base (directory-file-name
(car (project-roots project)))))
- (current-server (jsonrpc-current-connection))
+ (current-server (eglot--current-server))
(live-p (and current-server (jsonrpc-running-p current-server))))
(if (and live-p
interactive
(defun eglot-reconnect (server &optional interactive)
"Reconnect to SERVER.
INTERACTIVE is t if called interactively."
- (interactive (list (jsonrpc-current-connection-or-lose) t))
+ (interactive (list (eglot--current-server-or-lose) t))
(when (jsonrpc-running-p server)
(ignore-errors (eglot-shutdown server interactive)))
(eglot--connect (eglot--project server)
(eglot--saved-initargs server))
(eglot--message "Reconnected!"))
-(defalias 'eglot-events-buffer 'jsonrpc-events-buffer)
+(defun eglot-events-buffer (server)
+ "Display events buffer for SERVER."
+ (interactive (eglot--current-server-or-lose))
+ (display-buffer (jsonrpc-events-buffer server)))
+
+(defun eglot-stderr-buffer (server)
+ "Display stderr buffer for SERVER."
+ (interactive (eglot--current-server-or-lose))
+ (display-buffer (jsonrpc-stderr-buffer server)))
+
+(defun eglot-forget-pending-continuations (server)
+ "Forget pending requests for SERVER."
+ (interactive (eglot--current-server-or-lose))
+ (jsonrpc-forget-pending-continuations server))
(defvar eglot-connect-hook nil "Hook run after connecting in `eglot--connect'.")
(unless (cl-some (lambda (feat)
(memq feat eglot-ignored-server-capabilites))
feats)
- (cl-loop for caps = (eglot--capabilities (jsonrpc-current-connection-or-lose))
+ (cl-loop for caps = (eglot--capabilities (eglot--current-server-or-lose))
then (cadr probe)
for feat in feats
for probe = (plist-member caps feat)
nil nil eglot-mode-map
(cond
(eglot--managed-mode
- (add-hook 'jsonrpc-find-connection-functions 'eglot--find-current-server nil t)
(add-hook 'after-change-functions 'eglot--after-change nil t)
(add-hook 'before-change-functions 'eglot--before-change nil t)
(add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t)
#'eglot-eldoc-function)
(add-function :around (local imenu-create-index-function) #'eglot-imenu))
(t
- (remove-hook 'jsonrpc-find-connection-functions 'eglot--find-current-server t)
(remove-hook 'flymake-diagnostic-functions 'eglot-flymake-backend t)
(remove-hook 'after-change-functions 'eglot--after-change t)
(remove-hook 'before-change-functions 'eglot--before-change t)
(add-hook 'eglot--managed-mode-hook 'flymake-mode)
(add-hook 'eglot--managed-mode-hook 'eldoc-mode)
-(defun eglot--find-current-server ()
+(defun eglot--current-server ()
"Find the current logical EGLOT server."
(let* ((probe (or (project-current) `(transient . ,default-directory))))
(cl-find major-mode (gethash probe eglot--servers-by-project)
:key #'eglot--major-mode)))
+(defun eglot--current-server-or-lose ()
+ "Return current logical EGLOT server connection or error."
+ (or (eglot--current-server)
+ (jsonrpc-error "No current JSON-RPC connection")))
+
(defvar-local eglot--unreported-diagnostics nil
"Unreported Flymake diagnostics for this buffer.")
If SERVER is supplied, do it only if BUFFER is managed by it. In
that case, also signal textDocument/didOpen."
;; Called even when revert-buffer-in-progress-p
- (let* ((cur (and buffer-file-name (eglot--find-current-server)))
+ (let* ((cur (and buffer-file-name (eglot--current-server)))
(server (or (and (null server) cur) (and server (eq server cur) cur))))
(when server
(setq eglot--unreported-diagnostics `(:just-opened . nil))
(defun eglot-clear-status (server)
"Clear the last JSONRPC error for SERVER."
- (interactive (list (jsonrpc-current-connection-or-lose)))
+ (interactive (list (eglot--current-server-or-lose)))
(setf (jsonrpc-last-error server) nil))
\f
(defun eglot--mode-line-format ()
"Compose the EGLOT's mode-line."
- (pcase-let* ((server (jsonrpc-current-connection))
+ (pcase-let* ((server (eglot--current-server))
(nick (and server (eglot--project-nickname server)))
(pending (and server (hash-table-count
(jsonrpc--request-continuations server))))
(when nick
`(":" ,(eglot--mode-line-props
nick 'eglot-mode-line
- '((C-mouse-1 jsonrpc-stderr-buffer "go to stderr buffer")
+ '((C-mouse-1 eglot-stderr-buffer "go to stderr buffer")
(mouse-1 eglot-events-buffer "go to events buffer")
(mouse-2 eglot-shutdown "quit server")
(mouse-3 eglot-reconnect "reconnect to server")))
,@(when (cl-plusp pending)
`("/" ,(eglot--mode-line-props
(format "%d oustanding requests" pending) 'warning
- '((mouse-3 jsonrpc-forget-pending-continuations
+ '((mouse-3 eglot-forget-pending-continuations
"fahgettaboudit"))))))))))
(add-to-list 'mode-line-misc-info
(defun eglot--signal-textDocument/didChange ()
"Send textDocument/didChange to server."
(when eglot--recent-changes
- (let* ((server (jsonrpc-current-connection-or-lose))
+ (let* ((server (eglot--current-server-or-lose))
(sync-kind (eglot--server-capable :textDocumentSync))
(full-sync-p (or (eq sync-kind 1)
(eq :emacs-messup eglot--recent-changes))))
"Send textDocument/didOpen to server."
(setq eglot--recent-changes nil eglot--versioned-identifier 0)
(jsonrpc-notify
- (jsonrpc-current-connection-or-lose)
+ (eglot--current-server-or-lose)
:textDocument/didOpen `(:textDocument ,(eglot--TextDocumentItem))))
(defun eglot--signal-textDocument/didClose ()
"Send textDocument/didClose to server."
(jsonrpc-notify
- (jsonrpc-current-connection-or-lose)
+ (eglot--current-server-or-lose)
:textDocument/didClose `(:textDocument ,(eglot--TextDocumentIdentifier))))
(defun eglot--signal-textDocument/willSave ()
"Send textDocument/willSave to server."
- (let ((server (jsonrpc-current-connection-or-lose))
+ (let ((server (eglot--current-server-or-lose))
(params `(:reason 1 :textDocument ,(eglot--TextDocumentIdentifier))))
(jsonrpc-notify server :textDocument/willSave params)
(when (eglot--server-capable :textDocumentSync :willSaveWaitUntil)
(defun eglot--signal-textDocument/didSave ()
"Send textDocument/didSave to server."
(jsonrpc-notify
- (jsonrpc-current-connection-or-lose)
+ (eglot--current-server-or-lose)
:textDocument/didSave
(list
;; TODO: Handle TextDocumentSaveRegistrationOptions to control this.
(cl-defmethod xref-backend-identifier-completion-table ((_backend (eql eglot)))
(when (eglot--server-capable :documentSymbolProvider)
- (let ((server (jsonrpc-current-connection-or-lose))
+ (let ((server (eglot--current-server-or-lose))
(text-id (eglot--TextDocumentIdentifier)))
(completion-table-with-cache
(lambda (string)
(location-or-locations
(if rich-identifier
(get-text-property 0 :locations rich-identifier)
- (jsonrpc-request (jsonrpc-current-connection-or-lose)
+ (jsonrpc-request (eglot--current-server-or-lose)
:textDocument/definition
(get-text-property
0 :textDocumentPositionParams identifier)))))
(mapcar
(jsonrpc-lambda (&key uri range)
(eglot--xref-make identifier uri (plist-get range :start)))
- (jsonrpc-request (jsonrpc-current-connection-or-lose)
+ (jsonrpc-request (eglot--current-server-or-lose)
:textDocument/references
(append
params
(jsonrpc-lambda (&key name location &allow-other-keys)
(cl-destructuring-bind (&key uri range) location
(eglot--xref-make name uri (plist-get range :start))))
- (jsonrpc-request (jsonrpc-current-connection-or-lose)
+ (jsonrpc-request (eglot--current-server-or-lose)
:workspace/symbol
`(:query ,pattern)))))
(defun eglot-completion-at-point ()
"EGLOT's `completion-at-point' function."
(let ((bounds (bounds-of-thing-at-point 'symbol))
- (server (jsonrpc-current-connection-or-lose)))
+ (server (eglot--current-server-or-lose)))
(when (eglot--server-capable :completionProvider)
(list
(or (car bounds) (point))
"Request \"hover\" information for the thing at point."
(interactive)
(cl-destructuring-bind (&key contents range)
- (jsonrpc-request (jsonrpc-current-connection-or-lose) :textDocument/hover
+ (jsonrpc-request (eglot--current-server-or-lose) :textDocument/hover
(eglot--TextDocumentPositionParams))
(when (seq-empty-p contents) (eglot--error "No hover info here"))
(let ((blurb (eglot--hover-info contents range)))
"EGLOT's `eldoc-documentation-function' function.
If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp."
(let* ((buffer (current-buffer))
- (server (jsonrpc-current-connection-or-lose))
+ (server (eglot--current-server-or-lose))
(position-params (eglot--TextDocumentPositionParams))
sig-showing)
(cl-macrolet ((when-buffer-window
(cons (propertize name :kind (cdr (assoc kind eglot--kind-names)))
(eglot--lsp-position-to-point
(plist-get (plist-get location :range) :start))))
- (jsonrpc-request (jsonrpc-current-connection-or-lose)
+ (jsonrpc-request (eglot--current-server-or-lose)
:textDocument/documentSymbol
`(:textDocument ,(eglot--TextDocumentIdentifier))))))
(append
(unless (eglot--server-capable :renameProvider)
(eglot--error "Server can't rename!"))
(eglot--apply-workspace-edit
- (jsonrpc-request (jsonrpc-current-connection-or-lose)
+ (jsonrpc-request (eglot--current-server-or-lose)
:textDocument/rename `(,@(eglot--TextDocumentPositionParams)
:newName ,newname))
current-prefix-arg))
(t (list (point-min) (point-max))))))
(unless (eglot--server-capable :codeActionProvider)
(eglot--error "Server can't execute code actions!"))
- (let* ((server (jsonrpc-current-connection-or-lose))
+ (let* ((server (eglot--current-server-or-lose))
(actions (jsonrpc-request
server
:textDocument/codeAction