Skip to content

Commit 05d5271

Browse files
committed
Add a macro to expose base kinds as commands
Similar to `lsp-make-interactive-code-action', `lsp-make-interactive-code-action-by-type' defines a function to execute a given base type (using `lsp-execute-code-action-by-type'). Use it to define `lsp-quickfix' and `lsp-refactor'.
1 parent 980144d commit 05d5271

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lsp-mode.el

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5275,15 +5275,20 @@ is in contrast with the spec's recommended behavior."
52755275
lsp--select-action
52765276
lsp-execute-code-action))
52775277

5278-
(defun lsp-quickfix ()
5279-
"Execute a \"quickfix\" code action at point."
5280-
(interactive)
5281-
(lsp-execute-code-action-by-type "quickfix"))
5278+
(defmacro lsp-make-interactive-code-action-by-type (name kind)
5279+
"Make interactive function NAME to execute a KIND code action.
5280+
Like `lsp-make-interactive-code-action' but using
5281+
`lsp-execute-code-action-by-type'."
5282+
`(defun ,name ()
5283+
,(format "Execute a %S code action at point." kind)
5284+
(interactive)
5285+
(condition-case nil
5286+
(lsp-execute-code-action-by-kind ,kind)
5287+
(lsp-no-code-actions
5288+
(user-error "No %S actions available")))))
52825289

5283-
(defun lsp-refactor ()
5284-
"Execute a \"refactor\" code action at point."
5285-
(interactive)
5286-
(lsp-execute-code-action-by-type "refactor"))
5290+
(lsp-make-interactive-code-action-by-type lsp-quickfix "quickfix")
5291+
(lsp-make-interactive-code-action-by-type lsp-refactor "refactor")
52875292

52885293
(defun lsp-auto-fix ()
52895294
"Execute a preferred code action at point."

0 commit comments

Comments
 (0)