From: João Távora Date: Sat, 5 Jan 2019 13:32:13 +0000 (+0000) Subject: Handle (un)registercapability requests via generic functions X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~346 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a47618f19f6dec030b08e04717e10a573a1ce14f;p=emacs.git Handle (un)registercapability requests via generic functions * eglot.el (Version): Bump to 1.4 (eglot-register-capability, eglot-unregister-capability): New generic functions. (eglot--register-unregister): Call eglot-register-capability, eglot-unregister-capability. (eglot-register-capability s (eql workspace/didChangeWatchedFiles)): Rename from eglot--register-workspace/didChangeWatchedFiles. (eglot-unregister-capability s (eql workspace/didChangeWatchedFiles)): Rename from eglot--unregister-workspace/didChangeWatchedFiles. --- diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 53e60fd6ef0..031a657fe90 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2018 Free Software Foundation, Inc. -;; Version: 1.3 +;; Version: 1.4 ;; Author: João Távora ;; Maintainer: João Távora ;; URL: https://github.com/joaotavora/eglot @@ -440,6 +440,20 @@ treated as in `eglot-dbind'." "JSON object to send under `initializationOptions'" (:method (_s) nil)) ; blank default +(cl-defgeneric eglot-register-capability (server method id &rest params) + "Ask SERVER to register capability METHOD marked with ID." + (:method + (_s method _id &rest _params) + (eglot--warn "Server tried to register unsupported capability `%s'" + method))) + +(cl-defgeneric eglot-unregister-capability (server method id &rest params) + "Ask SERVER to register capability METHOD marked with ID." + (:method + (_s method _id &rest _params) + (eglot--warn "Server tried to unregister unsupported capability `%s'" + method))) + (cl-defgeneric eglot-client-capabilities (server) "What the EGLOT LSP client supports for SERVER." (:method (_s) @@ -1423,12 +1437,14 @@ COMMAND is a symbol naming the command." (cl-defun eglot--register-unregister (server things how) "Helper for `registerCapability'. -THINGS are either registrations or unregisterations." +THINGS are either registrations or unregisterations (sic)." (cl-loop for thing in (cl-coerce things 'list) do (eglot--dbind ((Registration) id method registerOptions) thing - (apply (intern (format "eglot--%s-%s" how method)) - server :id id registerOptions)))) + (apply (cl-ecase how + (register 'eglot-register-capability) + (unregister 'eglot-unregister-capability)) + server (intern method) id registerOptions)))) (cl-defmethod eglot-handle-request (server (_method (eql client/registerCapability)) &key registrations) @@ -2243,9 +2259,10 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp." for result = (replace-regexp-in-string pattern rep target) finally return result)) -(cl-defun eglot--register-workspace/didChangeWatchedFiles (server &key id watchers) +(cl-defmethod eglot-register-capability + (server (method (eql workspace/didChangeWatchedFiles)) id &key watchers) "Handle dynamic registration of workspace/didChangeWatchedFiles" - (eglot--unregister-workspace/didChangeWatchedFiles server :id id) + (eglot-unregister-capability server method id) (let* (success (globs (mapcar (eglot--lambda ((FileSystemWatcher) globPattern) globPattern) @@ -2280,9 +2297,10 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp." `(:message ,(format "OK, watching %s watchers" (length watchers))))) (unless success - (eglot--unregister-workspace/didChangeWatchedFiles server :id id)))))) + (eglot-unregister-capability server method id)))))) -(cl-defun eglot--unregister-workspace/didChangeWatchedFiles (server &key id) +(cl-defmethod eglot-unregister-capability + (server (_method (eql workspace/didChangeWatchedFiles)) id) "Handle dynamic unregistration of workspace/didChangeWatchedFiles" (mapc #'file-notify-rm-watch (gethash id (eglot--file-watches server))) (remhash id (eglot--file-watches server))