diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/emacs/ra-emacs-lsp.el | 28 |
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 |