Skip to content

Commit

Permalink
Introduce new API methods for experimental clients to use
Browse files Browse the repository at this point in the history
Should help Josh Elsasser implement pull request joaotavora/eglot#6.

* eglot.el (eglot--obj): Move upwards in file.
(eglot-server-ready-p): Tweak comment.
(eglot-initialization-options): New API defgeneric..
(eglot-client-capabilities): New API defgeneric.
(eglot--client-capabilities): Remove.
(eglot--connect): Call new API methods here.
  • Loading branch information
joaotavora committed May 22, 2018
1 parent 62b8cf3 commit a9b192d
Showing 1 changed file with 44 additions and 41 deletions.
85 changes: 44 additions & 41 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,19 @@ lasted more than that many seconds."

;;; API
;;;
(defmacro eglot--obj (&rest what)
"Make WHAT a JSON object suitable for `json-encode'."
(declare (debug (&rest form)))
;; FIXME: not really API. Should it be?
;; FIXME: maybe later actually do something, for now this just fixes
;; the indenting of literal plists.
`(list ,@what))

(cl-defgeneric eglot-server-ready-p (server what) ;; API
"Tell if SERVER is ready for WHAT in current buffer.
If it isn't, a deferrable `eglot--async-request' *will* be
deferred to the future."
(:method (_s _what)
"Normally not ready if outstanding changes."
(:method (_s _what) "Normally ready if no outstanding changes."
(not (eglot--outstanding-edits-p))))

(cl-defgeneric eglot-handle-request (server method id &rest params)
Expand All @@ -129,6 +136,35 @@ deferred to the future."
(cl-defgeneric eglot-handle-notification (server method id &rest params)
"Handle SERVER's METHOD notification with PARAMS.")

(cl-defgeneric eglot-initialization-options (server)
"JSON object to send under `initializationOptions'"
(:method (_s) nil)) ; blank default

(cl-defgeneric eglot-client-capabilities (server)
"What the EGLOT LSP client supports for SERVER."
(:method (_s)
(eglot--obj
:workspace (eglot--obj
:applyEdit t
:workspaceEdit `(:documentChanges :json-false)
:didChangeWatchesFiles `(:dynamicRegistration t)
:symbol `(:dynamicRegistration :json-false))
:textDocument
(eglot--obj
:synchronization (eglot--obj
:dynamicRegistration :json-false
:willSave t :willSaveWaitUntil t :didSave t)
:completion `(:dynamicRegistration :json-false)
:hover `(:dynamicRegistration :json-false)
:signatureHelp `(:dynamicRegistration :json-false)
:references `(:dynamicRegistration :json-false)
:definition `(:dynamicRegistration :json-false)
:documentSymbol `(:dynamicRegistration :json-false)
:documentHighlight `(:dynamicRegistration :json-false)
:rename `(:dynamicRegistration :json-false)
:publishDiagnostics `(:relatedInformation :json-false))
:experimental (eglot--obj))))


;;; Process management
(defvar eglot--servers-by-project (make-hash-table :test #'equal)
Expand Down Expand Up @@ -223,13 +259,6 @@ CONTACT is in `eglot'. Returns a process object."
(let ((inhibit-read-only t)) (erase-buffer) (read-only-mode t)))
proc))

(defmacro eglot--obj (&rest what)
"Make WHAT a suitable argument for `json-encode'."
(declare (debug (&rest form)))
;; FIXME: maybe later actually do something, for now this just fixes
;; the indenting of literal plists.
`(list ,@what))

(defun eglot--all-major-modes ()
"Return all know major modes."
(let ((retval))
Expand All @@ -238,29 +267,6 @@ CONTACT is in `eglot'. Returns a process object."
(push sym retval))))
retval))

(defun eglot--client-capabilities ()
"What the EGLOT LSP client supports."
(eglot--obj
:workspace (eglot--obj
:applyEdit t
:workspaceEdit `(:documentChanges :json-false)
:didChangeWatchesFiles `(:dynamicRegistration t)
:symbol `(:dynamicRegistration :json-false))
:textDocument (eglot--obj
:synchronization (eglot--obj
:dynamicRegistration :json-false
:willSave t :willSaveWaitUntil t :didSave t)
:completion `(:dynamicRegistration :json-false)
:hover `(:dynamicRegistration :json-false)
:signatureHelp `(:dynamicRegistration :json-false)
:references `(:dynamicRegistration :json-false)
:definition `(:dynamicRegistration :json-false)
:documentSymbol `(:dynamicRegistration :json-false)
:documentHighlight `(:dynamicRegistration :json-false)
:rename `(:dynamicRegistration :json-false)
:publishDiagnostics `(:relatedInformation :json-false))
:experimental (eglot--obj)))

(defvar eglot-connect-hook nil "Hook run after connecting in `eglot--connect'.")

(defun eglot--connect (project managed-major-mode contact server-class)
Expand Down Expand Up @@ -294,15 +300,12 @@ class SERVER-CLASS."
(eglot--request
server
:initialize
(eglot--obj :processId (unless (eq (process-type proc)
'network)
(emacs-pid))
:capabilities(eglot--client-capabilities)
:rootPath (expand-file-name
(car (project-roots project)))
:rootUri (eglot--path-to-uri
(car (project-roots project)))
:initializationOptions []))
(eglot--obj
:processId (unless (eq (process-type proc) 'network) (emacs-pid))
:capabilities (eglot-client-capabilities)
:rootPath (expand-file-name (car (project-roots project)))
:rootUri (eglot--path-to-uri (car (project-roots project)))
:initializationOptions (eglot-initialization-options server)))
(setf (eglot--capabilities server) capabilities)
(setf (eglot--status server) nil)
(dolist (buffer (buffer-list))
Expand Down

0 comments on commit a9b192d

Please sign in to comment.