]> git.lizzy.rs Git - rust.git/commitdiff
Add show syntax tree function to emacs
authorzbelial <zjytj@qq.com>
Sat, 29 Jun 2019 01:12:16 +0000 (09:12 +0800)
committerzbelial <zjytj@qq.com>
Sat, 29 Jun 2019 01:12:16 +0000 (09:12 +0800)
editors/emacs/ra-emacs-lsp.el

index 2ea106533416815248e28a10f421f007c26c77e7..21a90c86b469ab22b8fe4f0d2c830e9ab2cb3f5a 100644 (file)
                                    "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