emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot 31bfe21 24/45: Add support for code action litera


From: João Távora
Subject: [elpa] externals/eglot 31bfe21 24/45: Add support for code action literals
Date: Thu, 22 Nov 2018 19:15:30 -0500 (EST)

branch: externals/eglot
commit 31bfe21567c29f02b9ad3690f53aff13a22974dd
Author: Michał Krzywkowski <address@hidden>
Commit: mkcms <address@hidden>

    Add support for code action literals
    
    Code action literals allow the server to simply return a WorkspaceEdit
    for a code action, so the client does not have to execute a command.
    
    * eglot.el (eglot-client-capabilities): Add :codeActionLiteralSupport.
    (eglot--code-action-kinds): New variable.
    (eglot-code-actions): Apply provided WorkspaceEdit.
---
 eglot.el | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/eglot.el b/eglot.el
index e151704..b2e88d8 100644
--- a/eglot.el
+++ b/eglot.el
@@ -223,7 +223,12 @@ let the buffer grow forever."
              :definition         `(:dynamicRegistration :json-false)
              :documentSymbol     `(:dynamicRegistration :json-false)
              :documentHighlight  `(:dynamicRegistration :json-false)
-             :codeAction         `(:dynamicRegistration :json-false)
+             :codeAction         (list
+                                  :dynamicRegistration :json-false
+                                  :codeActionLiteralSupport
+                                  `(:codeActionKind
+                                    (:valueSet
+                                     [,@eglot--code-action-kinds])))
              :formatting         `(:dynamicRegistration :json-false)
              :rangeFormatting    `(:dynamicRegistration :json-false)
              :rename             `(:dynamicRegistration :json-false)
@@ -740,6 +745,11 @@ Doubles as an indicator of snippet support."
     (21 . "Null") (22 . "EnumMember") (23 . "Struct")
     (24 . "Event") (25 . "Operator") (26 . "TypeParameter")))
 
+(defconst eglot--code-action-kinds
+  '("quickfix" "refactor" "refactor.extract"
+    "refactor.inline" "refactor.rewrite"
+    "source" "source.organizeImports"))
+
 (defun eglot--format-markup (markup)
   "Format MARKUP according to LSP's spec."
   (pcase-let ((`(,string ,mode)
@@ -1788,8 +1798,10 @@ If SKIP-SIGNATURE, don't try to send 
textDocument/signatureHelp."
                                         (cdr (assoc 'eglot-lsp-diag
                                                     (eglot--diag-data diag))))
                                       (flymake-diagnostics beg end))]))))
-         (menu-items (mapcar (jsonrpc-lambda (&key title command arguments)
-                               `(,title . (:command ,command :arguments 
,arguments)))
+         (menu-items (mapcar (jsonrpc-lambda (&key title command arguments
+                                                   edit _kind _diagnostics)
+                               `(,title . (:command ,command :arguments 
,arguments
+                                                    :edit ,edit)))
                              actions))
          (menu (and menu-items `("Eglot code actions:" ("dummy" 
,@menu-items))))
          (command-and-args
@@ -1802,10 +1814,13 @@ 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) command-and-args
+    (cl-destructuring-bind (&key _title command arguments edit) 
command-and-args
+      (when edit
+        (eglot--apply-workspace-edit edit))
       (if command
           (eglot-execute-command server (intern command) arguments)
-        (eglot--message "No code actions here")))))
+        (unless edit
+          (eglot--message "No code actions here"))))))
 
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]