aboutsummaryrefslogtreecommitdiff
path: root/editors/emacs/ra-emacs-lsp.el
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-20 19:45:57 +0000
committerGitHub <[email protected]>2019-11-20 19:45:57 +0000
commita025303ca686ed3e54164a04319a028931f54284 (patch)
tree339938eb7633bbce9c756ffaee0878757f71321a /editors/emacs/ra-emacs-lsp.el
parent2cb2fb1a4807b4e53390c5f88c85106454706b64 (diff)
parentc079d9b63b995c37f0de500e4232a8303fc8a291 (diff)
Merge #2334
2334: Add rust-analyzer-expand-macro function for Emacs r=flodiebold a=flodiebold Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'editors/emacs/ra-emacs-lsp.el')
-rw-r--r--editors/emacs/ra-emacs-lsp.el28
1 files changed, 28 insertions, 0 deletions
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