From 7e7a9483a62be14bb62e7c4af1ccbfae81421002 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Fri, 7 Dec 2018 22:51:40 +0000 Subject: [PATCH] Be lenient by default to unknown methods or notifications * eglot.el (eglot-strict-mode): Describe meaning of disallow-non-standard-keys. (eglot-handle-notification, eglot-handle-request): Check eglot-strict-mode. --- lisp/progmodes/eglot.el | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 05971e13cd2..f442b2fb244 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -260,7 +260,8 @@ Here's what an element of this alist might look like: )) "How strictly to check LSP interfaces at compile- and run-time. -Value is a list of symbols: +Value is a list of symbols (if the list is empty, no checks are +performed). If the symbol `disallow-non-standard-keys' is present, an error is raised if any extraneous fields are sent by the server. At @@ -276,9 +277,9 @@ If the symbol `enforce-optional-keys' is present, nothing special happens at run-time. At compile-time, a warning is raised if a destructuring spec doesn't use all optional fields. -If the list is empty, any non-standard fields sent by the server -and missing required fields are accepted (which may or may not -cause problems in Eglot's functioning later on).")) +If the symbol `disallow-unknown-methods' is present, Eglot warns +on unknown notifications and errors on unknown requests. +")) (defun eglot--plist-keys (plist) (cl-loop for (k _v) on plist by #'cddr collect k)) @@ -1316,13 +1317,15 @@ Uses THING, FACE, DEFS and PREPEND." (cl-defmethod eglot-handle-notification (_server method &key &allow-other-keys) "Handle unknown notification" - (unless (string-prefix-p "$" (format "%s" method)) + (unless (or (string-prefix-p "$" (format "%s" method)) + (not (memq 'disallow-unknown-methods eglot-strict-mode))) (eglot--warn "Server sent unknown notification method `%s'" method))) (cl-defmethod eglot-handle-request (_server method &key &allow-other-keys) "Handle unknown request" - (jsonrpc-error "Unknown request method `%s'" method)) + (when (memq 'disallow-unknown-methods eglot-strict-mode) + (jsonrpc-error "Unknown request method `%s'" method))) (cl-defmethod eglot-execute-command (server command arguments) -- 2.39.2