Skip to content

Commit 0e1912d

Browse files
bors[bot]zbelial
andcommitted
Merge #1453
1453: Add show syntax tree function to emacs r=matklad a=zbelial This PR adds preliminary support for showing syntax tree. Co-authored-by: zbelial <[email protected]>
2 parents 1512ab3 + dc7cec8 commit 0e1912d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

editors/emacs/ra-emacs-lsp.el

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,31 @@
204204
"rust-analyzer/analyzerStatus")))))))
205205

206206

207+
(defun rust-analyzer--syntax-tree-params ()
208+
"Syntax tree params."
209+
(list :textDocument (lsp--text-document-identifier)
210+
:range (if (use-region-p)
211+
(lsp--region-to-range (region-beginning) (region-end))
212+
(lsp--region-to-range (point-min) (point-max)))))
213+
214+
(defun rust-analyzer-syntax-tree ()
215+
"Displays syntax tree for current buffer."
216+
(interactive)
217+
(when (eq 'rust-mode major-mode)
218+
(let* ((workspace (lsp-find-workspace 'rust-analyzer (buffer-file-name)))
219+
(buf (get-buffer-create (concat "*rust-analyzer syntax tree " (with-lsp-workspace workspace (lsp-workspace-root)) "*"))))
220+
(when workspace
221+
(let ((parse-result (with-lsp-workspace workspace
222+
(lsp-send-request (lsp-make-request
223+
"rust-analyzer/syntaxTree"
224+
(rust-analyzer--syntax-tree-params))))))
225+
(with-current-buffer buf
226+
(let ((inhibit-read-only t))
227+
(erase-buffer)
228+
(insert parse-result))
229+
)
230+
(pop-to-buffer buf))))))
231+
232+
207233
(provide 'ra-emacs-lsp)
208234
;;; ra-emacs-lsp.el ends here

0 commit comments

Comments
 (0)