[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/eglot a46f003 17/26: Fix #164: handle CodeAction/Comman
From: |
João Távora |
Subject: |
[elpa] externals/eglot a46f003 17/26: Fix #164: handle CodeAction/Command polymorphism with eglot--dcase |
Date: |
Sun, 9 Dec 2018 19:11:28 -0500 (EST) |
branch: externals/eglot
commit a46f0032ec4bb6d5e7faea1c5c8d1592649703cc
Author: João Távora <address@hidden>
Commit: Michał Krzywkowski <address@hidden>
Fix #164: handle CodeAction/Command polymorphism with eglot--dcase
* eglot-tests.el (eglot-dcase): Augment test.
* eglot.el (eglot--lsp-interface-alist): Add Command interface.
(eglot--dcase): Fix indentation. When given interface, always
assume strict mode.
(eglot-code-actions): Use eglot--dcase.
---
eglot-tests.el | 25 ++++++++++++++++++++++---
eglot.el | 40 ++++++++++++++++++++++------------------
2 files changed, 44 insertions(+), 21 deletions(-)
diff --git a/eglot-tests.el b/eglot-tests.el
index 37184d0..8a9aba6 100644
--- a/eglot-tests.el
+++ b/eglot-tests.el
@@ -648,13 +648,31 @@ Pass TIMEOUT to `eglot--with-timeout'."
(ert-deftest eglot-dcase ()
(let ((eglot--lsp-interface-alist
- `((FooObject . ((:foo :bar) (:baz))))))
+ `((FooObject . ((:foo :bar) (:baz)))
+ (CodeAction (:title) (:kind :diagnostics :edit :command))
+ (Command (:title :command) (:arguments)))))
(should
(equal
"foo"
(eglot--dcase `(:foo "foo" :bar "bar")
- (((FooObject) foo)
- foo))))))
+ (((FooObject) foo)
+ foo))))
+ (should
+ (equal
+ (list "foo" "some command" "some edit")
+ (eglot--dcase '(:title "foo" :command "some command" :edit "some edit")
+ (((Command) _title _command _arguments)
+ (ert-fail "Shouldn't have destructured this object as a Command"))
+ (((CodeAction) title edit command)
+ (list title command edit)))))
+ (should
+ (equal
+ (list "foo" "some command" nil)
+ (eglot--dcase '(:title "foo" :command "some command")
+ (((Command) title command arguments)
+ (list title command arguments))
+ (((CodeAction) _title _edit _command)
+ (ert-fail "Shouldn't have destructured this object as a
CodeAction")))))))
(provide 'eglot-tests)
;;; eglot-tests.el ends here
@@ -662,3 +680,4 @@ Pass TIMEOUT to `eglot--with-timeout'."
;; Local Variables:
;; checkdoc-force-docstrings-flag: nil
;; End:
+
diff --git a/eglot.el b/eglot.el
index e4547c5..578a90d 100644
--- a/eglot.el
+++ b/eglot.el
@@ -204,13 +204,12 @@ let the buffer grow forever."
;;; Message verification helpers
;;;
(defvar eglot--lsp-interface-alist
- `(
- (CodeAction (:title) (:kind :diagnostics :edit :command))
+ `((CodeAction (:title) (:kind :diagnostics :edit :command))
+ (Command (:title :command) (:arguments))
(FileSystemWatcher (:globPattern) (:kind))
(Registration (:id :method) (:registerOptions))
(TextDocumentEdit (:textDocument :edits) ())
- (WorkspaceEdit () (:changes :documentChanges))
- )
+ (WorkspaceEdit () (:changes :documentChanges)))
"Alist (INTERFACE-NAME . INTERFACE) of known external LSP interfaces.
INTERFACE-NAME is a symbol designated by the spec as
@@ -294,6 +293,7 @@ Honour `eglot-strict-mode'."
"Like `pcase', but for the LSP object OBJ.
CLAUSES is a list (DESTRUCTURE FORMS...) where DESTRUCTURE is
treated as in `eglot-dbind'."
+ (declare (indent 1))
(let ((obj-once (make-symbol "obj-once")))
`(let ((,obj-once ,obj))
(cond
@@ -306,19 +306,21 @@ treated as in `eglot-dbind'."
(car (pop vars)))
for condition =
(if interface-name
+ ;; In this mode, we assume `eglot-strict-mode' is fully
+ ;; on, otherwise we can't disambiguate between certain
+ ;; types.
`(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)))))))
+ (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.
+ ;; `eglot-strict-mode' at all: just check that the object
+ ;; has all the keys the user wants to destructure.
`(null (cl-set-difference
',vars-as-keywords
(eglot--plist-keys ,obj-once))))
@@ -2100,9 +2102,8 @@ If SKIP-SIGNATURE, don't try to send
textDocument/signatureHelp."
(eglot--diag-data diag))))
(flymake-diagnostics beg end))]))))
(menu-items
- (or (mapcar (eglot--lambda ((CodeAction) title edit command
arguments)
- `(,title . (:command ,command :arguments ,arguments
- :edit ,edit)))
+ (or (mapcar (jsonrpc-lambda (&rest all &key title &allow-other-keys)
+ (cons title all))
actions)
(eglot--error "No code actions here")))
(menu `("Eglot code actions:" ("dummy" ,@menu-items)))
@@ -2114,11 +2115,14 @@ If SKIP-SIGNATURE, don't try to send
textDocument/signatureHelp."
(if (eq (setq retval (tmm-prompt menu)) never-mind)
(keyboard-quit)
retval)))))
- (cl-destructuring-bind (&key _title command arguments edit) action
- (when edit
- (eglot--apply-workspace-edit edit))
- (when command
- (eglot-execute-command server (intern command) arguments)))))
+ (eglot--dcase action
+ (((Command) command arguments)
+ (eglot-execute-command server (intern command) arguments))
+ (((CodeAction) edit command)
+ (when edit (eglot--apply-workspace-edit edit))
+ (when command
+ (eglot--dbind ((Command) command arguments) command
+ (eglot-execute-command server (intern command) arguments)))))))
- [elpa] externals/eglot 8140be5 07/26: Touch up last commit, (continued)
- [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, 2018/12/09
- [elpa] externals/eglot a46f003 17/26: Fix #164: handle CodeAction/Command polymorphism with eglot--dcase,
João Távora <=
- [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