aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/user/README.md2
-rw-r--r--editors/emacs/ra-emacs-lsp.el28
2 files changed, 29 insertions, 1 deletions
diff --git a/docs/user/README.md b/docs/user/README.md
index 1861c69ab..bfb190449 100644
--- a/docs/user/README.md
+++ b/docs/user/README.md
@@ -127,7 +127,7 @@ Installation:
127[ra-emacs-lsp.el](https://github.com/rust-analyzer/rust-analyzer/blob/69ee5c9c5ef212f7911028c9ddf581559e6565c3/editors/emacs/ra-emacs-lsp.el) 127[ra-emacs-lsp.el](https://github.com/rust-analyzer/rust-analyzer/blob/69ee5c9c5ef212f7911028c9ddf581559e6565c3/editors/emacs/ra-emacs-lsp.el)
128to load path and require it in `init.el` 128to load path and require it in `init.el`
129* run `lsp` in a rust buffer 129* run `lsp` in a rust buffer
130* (Optionally) bind commands like `rust-analyzer-join-lines` or `rust-analyzer-extend-selection` to keys, and enable `rust-analyzer-inlay-hints-mode` to get inline type hints 130* (Optionally) bind commands like `rust-analyzer-join-lines`, `rust-analyzer-extend-selection` and `rust-analyzer-expand-macro` to keys, and enable `rust-analyzer-inlay-hints-mode` to get inline type hints
131 131
132 132
133## Vim and NeoVim 133## Vim and NeoVim
diff --git a/editors/emacs/ra-emacs-lsp.el b/editors/emacs/ra-emacs-lsp.el
index 79822c8ce..fafb9cbe7 100644
--- a/editors/emacs/ra-emacs-lsp.el
+++ b/editors/emacs/ra-emacs-lsp.el
@@ -16,6 +16,7 @@
16;; - implements joinLines (you need to bind rust-analyzer-join-lines to a key) 16;; - implements joinLines (you need to bind rust-analyzer-join-lines to a key)
17;; - implements selectionRanges (either bind lsp-extend-selection to a key, or use expand-region) 17;; - implements selectionRanges (either bind lsp-extend-selection to a key, or use expand-region)
18;; - provides rust-analyzer-inlay-hints-mode for inline type hints 18;; - provides rust-analyzer-inlay-hints-mode for inline type hints
19;; - provides rust-analyzer-expand-macro to expand macros
19 20
20;; What's missing: 21;; What's missing:
21;; - file system changes in apply-source-change 22;; - file system changes in apply-source-change
@@ -247,5 +248,32 @@
247 (remove-hook 'after-change-functions #'rust-analyzer--inlay-hints-change-handler t)))) 248 (remove-hook 'after-change-functions #'rust-analyzer--inlay-hints-change-handler t))))
248 249
249 250
251
252;; expand macros
253(defun rust-analyzer-expand-macro ()
254 "Expands the macro call at point recursively."
255 (interactive)
256 (when (eq 'rust-mode major-mode)
257 (let* ((workspace (lsp-find-workspace 'rust-analyzer (buffer-file-name)))
258 (params (list :textDocument (lsp--text-document-identifier)
259 :position (lsp--cur-position))))
260 (when workspace
261 (let* ((response (with-lsp-workspace workspace
262 (lsp-send-request (lsp-make-request
263 "rust-analyzer/expandMacro"
264 params))))
265 (result (when response (ht-get response "expansion"))))
266 (if result
267 (let ((buf (get-buffer-create (concat "*rust-analyzer macro expansion " (with-lsp-workspace workspace (lsp-workspace-root)) "*"))))
268 (with-current-buffer buf
269 (let ((inhibit-read-only t))
270 (erase-buffer)
271 (insert result)
272 (setq buffer-read-only t)
273 (special-mode)))
274 (pop-to-buffer buf))
275 (message "No macro found at point, or it could not be expanded")))))))
276
277
250(provide 'ra-emacs-lsp) 278(provide 'ra-emacs-lsp)
251;;; ra-emacs-lsp.el ends here 279;;; ra-emacs-lsp.el ends here