]> git.eshelyaron.com Git - emacs.git/commitdiff
Add half-baked m-x eglot-list-connections
authorJoão Távora <joaotavora@gmail.com>
Tue, 4 Oct 2022 20:11:38 +0000 (21:11 +0100)
committerJoão Távora <joaotavora@gmail.com>
Wed, 5 Oct 2022 19:54:01 +0000 (20:54 +0100)
Not very useful for now, but more functionality could be added later,
like bindings for disconnecting a given connection, switching to its
events buffers, or just listing some details like capabilities.

* eglot.el (eglot-list-connections-mode, eglot-list-connections):
New mode and function.

lisp/progmodes/eglot.el

index 010f8c86c70afab1f3d58e65bb44e328629f9c04..918bba621031267a0d8d322e8924b85c7672c33c 100644 (file)
@@ -3316,6 +3316,40 @@ If NOERROR, return predicate, else erroring function."
   (when (eq ?! (aref arg 1)) (aset arg 1 ?^))
   `(,self () (re-search-forward ,(concat "\\=" arg)) (,next)))
 
+\f
+;;; List connections mode
+
+(define-derived-mode eglot-list-connections-mode  tabulated-list-mode
+  "" "Eglot Connection List Mode
+
+\\{sly-connection-list-mode-map}"
+  (setq-local tabulated-list-format
+              `[("Language server" 16) ("Project name" 16) ("Modes handled" 16)])
+  (tabulated-list-init-header))
+
+(defun eglot-list-connections ()
+  "List currently active Eglot connections."
+  (interactive)
+  (with-current-buffer
+      (get-buffer-create "*EGLOT connections*")
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (eglot-list-connections-mode)
+      (setq-local tabulated-list-entries
+                  (mapcar
+                   (lambda (server)
+                     (list server
+                           `[,(or (plist-get (eglot--server-info server) :name)
+                                  (jsonrpc-name server))
+                             ,(eglot-project-nickname server)
+                             ,(mapconcat #'symbol-name
+                                         (eglot--major-modes server)
+                                         ", ")]))
+                   (cl-reduce #'append
+                              (hash-table-values eglot--servers-by-project))))
+      (revert-buffer)
+      (pop-to-buffer (current-buffer)))))
+
 \f
 ;;; Hacks
 ;;;