Skip to content

Commit 2586cf9

Browse files
committed
Implement support for selectAndApplySourceChange (auto import) in Emacs
1 parent ba45c60 commit 2586cf9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

editors/emacs/rust-analyzer.el

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838

3939
(defconst rust-analyzer--action-handlers
4040
'(("rust-analyzer.applySourceChange" .
41-
(lambda (p) (rust-analyzer--apply-source-change-command p)))))
41+
(lambda (p) (rust-analyzer--apply-source-change-command p)))
42+
("rust-analyzer.selectAndApplySourceChange" .
43+
(lambda (p) (rust-analyzer--select-and-apply-source-change-command p)))))
4244

4345
(defun rust-analyzer--uri-filename (text-document)
4446
(lsp--uri-to-path (gethash "uri" text-document)))
@@ -71,6 +73,12 @@
7173
(let ((data (-> p (ht-get "arguments") (lsp-seq-first))))
7274
(rust-analyzer--apply-source-change data)))
7375

76+
(defun rust-analyzer--select-and-apply-source-change-command (p)
77+
(let* ((options (-> p (ht-get "arguments") (lsp-seq-first)))
78+
(chosen-option (lsp--completing-read "Select option:" options
79+
(-lambda ((&hash "label")) label))))
80+
(rust-analyzer--apply-source-change chosen-option)))
81+
7482
(lsp-register-client
7583
(make-lsp-client
7684
:new-connection (lsp-stdio-connection (lambda () rust-analyzer-command))

0 commit comments

Comments
 (0)