]> git.eshelyaron.com Git - emacs.git/commitdiff
Introduce and use `eglot--current-process-or-lose'
authorJoão Távora <joaotavora@gmail.com>
Wed, 16 Aug 2017 11:13:52 +0000 (12:13 +0100)
committerJoão Távora <joaotavora@gmail.com>
Wed, 16 Aug 2017 12:52:00 +0000 (13:52 +0100)
lisp/progmodes/eglot.el

index 92c12162f921e149816e6e954d3e321a6e1ad5fc..5ca6833de7117af68a5e21b4545d87e5c27f0b6f 100644 (file)
       (eglot--error "No current project, so no process"))
     (gethash cur eglot--processes-by-project)))
 
+(defun eglot--current-process-or-lose ()
+  (or (eglot--current-process)
+      (eglot--error "No current EGLOT process")))
+
 (defmacro eglot--define-process-var (var-sym initval &optional doc)
   (declare (indent 2))
   `(progn
      (put ',var-sym 'function-documentation ,doc)
      (defun ,var-sym (&optional process)
-       (let* ((proc (or process (eglot--current-process)))
+       (let* ((proc (or process (eglot--current-process-or-lose)))
               (probe (process-get proc ',var-sym)))
          (or probe
              (let ((def ,initval))
@@ -58,7 +62,7 @@
                def))))
      (gv-define-setter ,var-sym (to-store &optional process)
        (let ((prop ',var-sym))
-         `(let ((proc (or ,process (eglot--current-process))))
+         `(let ((proc (or ,process (eglot--current-process-or-lose))))
             (process-put proc ',prop ,to-store))))))
 
 (eglot--define-process-var eglot--message-mark nil
                     major-mode))
     probe))
 
-(defun eglot-new-process (&optional _interactive)
+(defun eglot-new-process (&optional interactive)
   "Starts a new EGLOT process and initializes it"
   (interactive (list t))
   (let ((project (project-current))
             (let ((inhibit-read-only t))
               (insert
                (format "\n-----------------------------------\n"))))
-          (eglot--protocol-initialize proc))))))
+          (eglot--protocol-initialize proc interactive))))))
 
 (defun eglot-quit-server (process &optional sync)
-  (interactive (list (eglot--current-process)))
+  (interactive (list (eglot--current-process-or-lose)))
   (eglot--message "Asking server to terminate")
   (eglot--request
       process
                  )))))))
 
 (defun eglot-events-buffer (process &optional interactive)
-  (interactive (list (eglot--current-process) t))
+  (interactive (list (eglot--current-process-or-lose) t))
   (let* ((probe (eglot--events-buffer process))
          (buffer (or (and (buffer-live-p probe)
                           probe)
   (setq eglot--next-request-id (1+ eglot--next-request-id)))
 
 (defun eglot-forget-pending-continuations (process)
-  (interactive (eglot--current-process))
+  (interactive (eglot--current-process-or-lose))
   (clrhash (eglot--pending-continuations process)))
 
 (defun eglot--call-with-request (process
           (accept-process-output nil 0.01))))))
 
 
-(defun eglot--protocol-initialize (process)
+(defun eglot--protocol-initialize (process interactive)
   (eglot--request
-    process
-    :initialize
-    `(:processId  ,(emacs-pid)
-                  :rootPath  ,(concat "" ;; FIXME RLS doesn't like "file://"
-                                      (expand-file-name (car (project-roots
-                                                              (project-current)))))
-                  :initializationOptions  []
-                  :capabilities (:workspace (:executeCommand (:dynamicRegistration t))
-                                            :textDocument (:synchronization (:didSave t)))
-                  )
-    (lambda (&key capabilities)
-      (cl-destructuring-bind
-          (&rest all
-                 &key
-                 _textDocumentSync
-                 _hoverProvider
-                 _completionProvider
-                 _definitionProvider
-                 _referencesProvider
-                 _documentHighlightProvider
-                 _documentSymbolProvider
-                 _workspaceSymbolProvider
-                 _codeActionProvider
-                 _documentFormattingProvider
-                 _documentRangeFormattingProvider
-                 _renameProvider
-                 _executeCommandProvider
-                 )
-          capabilities
-        (message "so yeah I got lots (%d) of capabilities" (length all))))))
+   process
+   :initialize
+   `(:processId  ,(emacs-pid)
+                 :rootPath  ,(concat "" ;; FIXME RLS doesn't like "file://"
+                                     (expand-file-name (car (project-roots
+                                                             (project-current)))))
+                 :initializationOptions  []
+                 :capabilities (:workspace (:executeCommand (:dynamicRegistration t))
+                                           :textDocument (:synchronization (:didSave t))))
+   (lambda (&key capabilities)
+     (cl-destructuring-bind
+         (&rest all
+                &key
+                ;; capabilities reported by server
+                _textDocumentSync
+                _hoverProvider
+                _completionProvider
+                _definitionProvider
+                _referencesProvider
+                _documentHighlightProvider
+                _documentSymbolProvider
+                _workspaceSymbolProvider
+                _codeActionProvider
+                _documentFormattingProvider
+                _documentRangeFormattingProvider
+                _renameProvider
+                _executeCommandProvider
+                )
+         capabilities
+       (when interactive
+         (eglot--message
+          "So yeah I got lots (%d) of capabilities"
+          (length all)))))))
 
 (defun eglot--debug (format &rest args)
   (display-warning 'eglot