Created
February 17, 2021 13:01
-
-
Save caioaao/0fdfa0fc2d86ef1fbdfc39f509d62319 to your computer and use it in GitHub Desktop.
Example snippet using Eglot code-actions with Helm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun helm-eglot--build-code-actions-source (menu-items) | |
(let* ((execute-selected-action (lambda (action) (eglot--code-actions-execute-action (cdr (assoc action menu-items)))))) | |
(helm-build-sync-source "Eglot Code actions" | |
:candidates | |
(lambda () (mapcar #'car menu-items)) | |
:action `(("Execute action" . ,execute-selected-action))))) | |
(defun helm-eglot-code-actions (beg &optional end action-kind) | |
"Offer to execute code actions between BEG and END using helm. | |
Interactively, if a region is active, BEG and END are its bounds, | |
else BEG is point and END is nil, which results in a request for | |
code actions at point" | |
(interactive | |
`(,@(eglot--region-bounds) | |
,(and current-prefix-arg | |
(completing-read "[eglot] Action kind: " | |
'("quickfix" "refactor.extract" "refactor.inline" | |
"refactor.rewrite" "source.organizeImports"))))) | |
(unless (eglot--server-capable :codeActionProvider) | |
(eglot--error "Server can't execute code actions!")) | |
(let* ((menu-items (eglot-code-actions-menu-items beg end))) | |
(helm :sources (helm-eglot--build-code-actions-source menu-items) | |
:buffer "*helm Eglot Code Actions*"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment