mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
Merge #2334
2334: Add rust-analyzer-expand-macro function for Emacs r=flodiebold a=flodiebold Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
commit
a025303ca6
2 changed files with 29 additions and 1 deletions
|
@ -127,7 +127,7 @@ Installation:
|
||||||
[ra-emacs-lsp.el](https://github.com/rust-analyzer/rust-analyzer/blob/69ee5c9c5ef212f7911028c9ddf581559e6565c3/editors/emacs/ra-emacs-lsp.el)
|
[ra-emacs-lsp.el](https://github.com/rust-analyzer/rust-analyzer/blob/69ee5c9c5ef212f7911028c9ddf581559e6565c3/editors/emacs/ra-emacs-lsp.el)
|
||||||
to load path and require it in `init.el`
|
to load path and require it in `init.el`
|
||||||
* run `lsp` in a rust buffer
|
* run `lsp` in a rust buffer
|
||||||
* (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
|
* (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
|
||||||
|
|
||||||
|
|
||||||
## Vim and NeoVim
|
## Vim and NeoVim
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
;; - implements joinLines (you need to bind rust-analyzer-join-lines to a key)
|
;; - implements joinLines (you need to bind rust-analyzer-join-lines to a key)
|
||||||
;; - implements selectionRanges (either bind lsp-extend-selection to a key, or use expand-region)
|
;; - implements selectionRanges (either bind lsp-extend-selection to a key, or use expand-region)
|
||||||
;; - provides rust-analyzer-inlay-hints-mode for inline type hints
|
;; - provides rust-analyzer-inlay-hints-mode for inline type hints
|
||||||
|
;; - provides rust-analyzer-expand-macro to expand macros
|
||||||
|
|
||||||
;; What's missing:
|
;; What's missing:
|
||||||
;; - file system changes in apply-source-change
|
;; - file system changes in apply-source-change
|
||||||
|
@ -247,5 +248,32 @@
|
||||||
(remove-hook 'after-change-functions #'rust-analyzer--inlay-hints-change-handler t))))
|
(remove-hook 'after-change-functions #'rust-analyzer--inlay-hints-change-handler t))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
;; expand macros
|
||||||
|
(defun rust-analyzer-expand-macro ()
|
||||||
|
"Expands the macro call at point recursively."
|
||||||
|
(interactive)
|
||||||
|
(when (eq 'rust-mode major-mode)
|
||||||
|
(let* ((workspace (lsp-find-workspace 'rust-analyzer (buffer-file-name)))
|
||||||
|
(params (list :textDocument (lsp--text-document-identifier)
|
||||||
|
:position (lsp--cur-position))))
|
||||||
|
(when workspace
|
||||||
|
(let* ((response (with-lsp-workspace workspace
|
||||||
|
(lsp-send-request (lsp-make-request
|
||||||
|
"rust-analyzer/expandMacro"
|
||||||
|
params))))
|
||||||
|
(result (when response (ht-get response "expansion"))))
|
||||||
|
(if result
|
||||||
|
(let ((buf (get-buffer-create (concat "*rust-analyzer macro expansion " (with-lsp-workspace workspace (lsp-workspace-root)) "*"))))
|
||||||
|
(with-current-buffer buf
|
||||||
|
(let ((inhibit-read-only t))
|
||||||
|
(erase-buffer)
|
||||||
|
(insert result)
|
||||||
|
(setq buffer-read-only t)
|
||||||
|
(special-mode)))
|
||||||
|
(pop-to-buffer buf))
|
||||||
|
(message "No macro found at point, or it could not be expanded")))))))
|
||||||
|
|
||||||
|
|
||||||
(provide 'ra-emacs-lsp)
|
(provide 'ra-emacs-lsp)
|
||||||
;;; ra-emacs-lsp.el ends here
|
;;; ra-emacs-lsp.el ends here
|
||||||
|
|
Loading…
Reference in a new issue