Skip to content

Commit 226df20

Browse files
authored
lsp-code-actions: display actions of the current diagnostics (#4848)
1 parent 1aa4740 commit 226df20

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

lsp-mode.el

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6111,12 +6111,28 @@ It will show up only if current point has signature help."
61116111

61126112
(defun lsp--text-document-code-action-params (&optional kind)
61136113
"Code action params."
6114-
(list :textDocument (lsp--text-document-identifier)
6115-
:range (if (use-region-p)
6116-
(lsp--region-to-range (region-beginning) (region-end))
6117-
(lsp--region-to-range (point) (point)))
6118-
:context `( :diagnostics ,(lsp-cur-possition-diagnostics)
6119-
,@(when kind (list :only (vector kind))))))
6114+
(let* ((diags (lsp-cur-possition-diagnostics))
6115+
(range (cond ((use-region-p)
6116+
(lsp--region-to-range (region-beginning) (region-end)))
6117+
(diags
6118+
(let* ((start (point))
6119+
(end (point)))
6120+
(seq-doseq (diag diags)
6121+
(when-let* ((diag-range (gethash "range" diag))
6122+
(diag-start (gethash "start" diag-range))
6123+
(l1 (gethash "line" diag-start))
6124+
(c1 (gethash "character" diag-start))
6125+
(diag-end (gethash "end" diag-range))
6126+
(l2 (gethash "line" diag-end))
6127+
(c2 (gethash "character" diag-end)))
6128+
(setq start (min (lsp--line-character-to-point l1 c1) start))
6129+
(setq end (max (lsp--line-character-to-point l2 c2) end))))
6130+
(lsp--region-to-range start end)))
6131+
(t (lsp--region-to-range (point) (point))))))
6132+
(list :textDocument (lsp--text-document-identifier)
6133+
:range range
6134+
:context `( :diagnostics ,diags
6135+
,@(when kind (list :only (vector kind)))))))
61206136

61216137
(defun lsp-code-actions-at-point (&optional kind)
61226138
"Retrieve the code actions for the active region or the current line.

0 commit comments

Comments
 (0)