[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot 6de3d9c 10/26: Per #171, #156: Introduce eglot--d
From: |
João Távora |
Subject: |
[elpa] externals/eglot 6de3d9c 10/26: Per #171, #156: Introduce eglot--dcase |
Date: |
Sun, 9 Dec 2018 19:11:26 -0500 (EST) |
branch: externals/eglot
commit 6de3d9cf9cdf9f21fb4bf637d98f97738dbb12e5
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Per #171,#156: Introduce eglot--dcase
* eglot.el (eglot--dcase): New macro.
* eglot-tests.el (eglot-dcase-with-interface)
(eglot-dcase-no-interface): New tests.
---
eglot-tests.el | 10 ++++++++++
eglot.el | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/eglot-tests.el b/eglot-tests.el
index 8b91317..37184d0 100644
--- a/eglot-tests.el
+++ b/eglot-tests.el
@@ -646,6 +646,16 @@ Pass TIMEOUT to `eglot--with-timeout'."
(eglot--dbind ((FooObject) foo bar) `(:foo "foo" :baz bargh)
(cons foo bar))))))
+(ert-deftest eglot-dcase ()
+ (let ((eglot--lsp-interface-alist
+ `((FooObject . ((:foo :bar) (:baz))))))
+ (should
+ (equal
+ "foo"
+ (eglot--dcase `(:foo "foo" :bar "bar")
+ (((FooObject) foo)
+ foo))))))
+
(provide 'eglot-tests)
;;; eglot-tests.el ends here
diff --git a/eglot.el b/eglot.el
index 594a638..61f9b70 100644
--- a/eglot.el
+++ b/eglot.el
@@ -281,6 +281,47 @@ Honour `eglot-strict-mode'."
(let ((e (cl-gensym "jsonrpc-lambda-elem")))
`(lambda (,e) (eglot--dbind ,cl-lambda-list ,e ,@body))))
+(cl-defmacro eglot--dcase (obj &rest clauses)
+ "Like `pcase', but for the LSP object OBJ.
+CLAUSES is a list (DESTRUCTURE FORMS...) where DESTRUCTURE is
+treated as in `eglot-dbind'."
+ (let ((obj-once (make-symbol "obj-once")))
+ `(let ((,obj-once ,obj))
+ (cond
+ ,@(cl-loop
+ for (vars . body) in clauses
+ for vars-as-keywords = (mapcar (lambda (var)
+ (intern (format ":%s" var)))
+ vars)
+ for interface-name = (if (consp (car vars))
+ (car (pop vars)))
+ for condition =
+ (if interface-name
+ `(let* ((interface
+ (or (assoc ',interface-name eglot--lsp-interface-alist)
+ (eglot--error "Unknown interface %s")))
+ (object-keys (eglot--plist-keys ,obj-once))
+ (required-keys (car (cdr interface))))
+ (and (null (cl-set-difference required-keys object-keys))
+ (or (null (memq 'disallow-non-standard-keys
+ eglot-strict-mode))
+ (null (cl-set-difference
+ (cl-set-difference object-keys required-keys)
+ (cadr (cdr interface)))))))
+ ;; In this interface-less mode we don't check
+ ;; `eglot-strict-mode' at all.
+ `(null (cl-set-difference
+ ',vars-as-keywords
+ (eglot--plist-keys ,obj-once))))
+ collect `(,condition
+ (cl-destructuring-bind (&key ,@vars &allow-other-keys)
+ ,obj-once
+ ,@body)))
+ (t
+ (eglot--error "%s didn't match any of %s"
+ ,obj-once
+ ',(mapcar #'car clauses)))))))
+
;;; API (WORK-IN-PROGRESS!)
;;;
- [elpa] externals/eglot 3922cf3 01/26: Per #144, #156: control strictness towards incoming LSP messages, (continued)
- [elpa] externals/eglot 3922cf3 01/26: Per #144, #156: control strictness towards incoming LSP messages, João Távora, 2018/12/09
- [elpa] externals/eglot 8140be5 07/26: Touch up last commit, João Távora, 2018/12/09
- [elpa] externals/eglot 95ef9e1 08/26: Robustify tests against (M)ELPA eglot installations, João Távora, 2018/12/09
- [elpa] externals/eglot 38da3d3 15/26: Fix #159: Properly clear old diagnostics when making new ones, João Távora, 2018/12/09
- [elpa] externals/eglot 444a8c3 16/26: Per #173: robustify previous fix against non-standard insertion bindings, João Távora, 2018/12/09
- [elpa] externals/eglot 1d42be4 13/26: Close #173: support completionContext to help servers like ccls, João Távora, 2018/12/09
- [elpa] externals/eglot e2200ce 09/26: Simplify interface of eglot--dbind macro, João Távora, 2018/12/09
- [elpa] externals/eglot c1848c3 23/26: Handle array params to server notification or requests, João Távora, 2018/12/09
- [elpa] externals/eglot 23accee 26/26: * eglot.el (Version): Bump to 1.3, João Távora, 2018/12/09
- [elpa] externals/eglot 37706af 21/26: Warn about suspicious interface usage at compile-time, João Távora, 2018/12/09
- [elpa] externals/eglot 6de3d9c 10/26: Per #171, #156: Introduce eglot--dcase,
João Távora <=
- [elpa] externals/eglot a46f003 17/26: Fix #164: handle CodeAction/Command polymorphism with eglot--dcase, João Távora, 2018/12/09
- [elpa] externals/eglot 6b0b1b7 24/26: Be lenient by default to unknown methods or notifications, João Távora, 2018/12/09
- [elpa] externals/eglot 973cd81 25/26: Close #180: Add preamble to comparison to lsp-mode.el, João Távora, 2018/12/09
- [elpa] externals/eglot a1f2033 12/26: Fix #116, #150: don't break in indirect buffers, João Távora, 2018/12/09