Skip to content

Instantly share code, notes, and snippets.

@caioaao
Created February 17, 2021 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caioaao/0fdfa0fc2d86ef1fbdfc39f509d62319 to your computer and use it in GitHub Desktop.
Save caioaao/0fdfa0fc2d86ef1fbdfc39f509d62319 to your computer and use it in GitHub Desktop.
Example snippet using Eglot code-actions with Helm
(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