mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
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 <zjytj@qq.com>
This commit is contained in:
commit
0e1912de52
1 changed files with 26 additions and 0 deletions
|
@ -204,5 +204,31 @@
|
||||||
"rust-analyzer/analyzerStatus")))))))
|
"rust-analyzer/analyzerStatus")))))))
|
||||||
|
|
||||||
|
|
||||||
|
(defun rust-analyzer--syntax-tree-params ()
|
||||||
|
"Syntax tree params."
|
||||||
|
(list :textDocument (lsp--text-document-identifier)
|
||||||
|
:range (if (use-region-p)
|
||||||
|
(lsp--region-to-range (region-beginning) (region-end))
|
||||||
|
(lsp--region-to-range (point-min) (point-max)))))
|
||||||
|
|
||||||
|
(defun rust-analyzer-syntax-tree ()
|
||||||
|
"Displays syntax tree for current buffer."
|
||||||
|
(interactive)
|
||||||
|
(when (eq 'rust-mode major-mode)
|
||||||
|
(let* ((workspace (lsp-find-workspace 'rust-analyzer (buffer-file-name)))
|
||||||
|
(buf (get-buffer-create (concat "*rust-analyzer syntax tree " (with-lsp-workspace workspace (lsp-workspace-root)) "*"))))
|
||||||
|
(when workspace
|
||||||
|
(let ((parse-result (with-lsp-workspace workspace
|
||||||
|
(lsp-send-request (lsp-make-request
|
||||||
|
"rust-analyzer/syntaxTree"
|
||||||
|
(rust-analyzer--syntax-tree-params))))))
|
||||||
|
(with-current-buffer buf
|
||||||
|
(let ((inhibit-read-only t))
|
||||||
|
(erase-buffer)
|
||||||
|
(insert parse-result))
|
||||||
|
)
|
||||||
|
(pop-to-buffer buf))))))
|
||||||
|
|
||||||
|
|
||||||
(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