From dc7cec8cf4badddb54be03cfa187567b436dd82a Mon Sep 17 00:00:00 2001 From: zbelial Date: Sat, 29 Jun 2019 09:12:16 +0800 Subject: Add show syntax tree function to emacs --- editors/emacs/ra-emacs-lsp.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'editors') diff --git a/editors/emacs/ra-emacs-lsp.el b/editors/emacs/ra-emacs-lsp.el index 2ea106533..21a90c86b 100644 --- a/editors/emacs/ra-emacs-lsp.el +++ b/editors/emacs/ra-emacs-lsp.el @@ -204,5 +204,31 @@ "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) ;;; ra-emacs-lsp.el ends here -- cgit v1.2.3