From cb63ab4b1f466736f045c32b64abbfccbaa0fb98 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 27 May 2023 00:22:26 -0400 Subject: [PATCH] Use treesitter for rust. --- ansible/roles/emacs/files/base.el | 1 + ansible/roles/emacs/files/lang-rust.el | 10 ++++--- ansible/roles/emacs/files/util-tree-sitter.el | 27 +++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/ansible/roles/emacs/files/base.el b/ansible/roles/emacs/files/base.el index c26ab0e..743db2f 100644 --- a/ansible/roles/emacs/files/base.el +++ b/ansible/roles/emacs/files/base.el @@ -1,3 +1,4 @@ +(package-initialize) (use-package use-package) (add-to-list 'package-archives diff --git a/ansible/roles/emacs/files/lang-rust.el b/ansible/roles/emacs/files/lang-rust.el index 4b6ce88..b2e29eb 100644 --- a/ansible/roles/emacs/files/lang-rust.el +++ b/ansible/roles/emacs/files/lang-rust.el @@ -24,14 +24,17 @@ ) ) +(add-to-list 'major-mode-remap-alist '(rust-mode . rust-ts-mode)) + (use-package rust-mode + :pin nongnu :mode "\\.rs\\'" :hook ( - (rust-mode . (lambda () + (rust-ts-mode . (lambda () (eglot-ensure) (let ((rust-analyzer-command (locate-rust-analyzer))) (when rust-analyzer-command - (add-to-list 'eglot-server-programs (cons 'rust-mode (list rust-analyzer-command))) + (add-to-list 'eglot-server-programs (cons 'rust-ts-mode (list rust-analyzer-command))) ) ) (when-linux @@ -41,9 +44,10 @@ )) ) :config + (treesit-install-language-grammar 'rust) ;; Add keybindings for interacting with Cargo (use-package cargo - :hook (rust-mode . cargo-minor-mode)) + :hook (rust-ts-mode . cargo-minor-mode)) ) (provide 'lang-rust) diff --git a/ansible/roles/emacs/files/util-tree-sitter.el b/ansible/roles/emacs/files/util-tree-sitter.el index 630f2b6..2bda527 100644 --- a/ansible/roles/emacs/files/util-tree-sitter.el +++ b/ansible/roles/emacs/files/util-tree-sitter.el @@ -1,7 +1,24 @@ -;; (use-package tree-sitter -;; :commands (tree-sitter-hl-mode) -;; :config -;; (use-package tree-sitter-langs) -;; ) +(setq treesit-language-source-alist + '( + (bash "https://github.com/tree-sitter/tree-sitter-bash") + (c "https://github.com/tree-sitter/tree-sitter-c") + (common-lisp "https://github.com/theHamsta/tree-sitter-commonlisp") + (css "https://github.com/tree-sitter/tree-sitter-css") + (elisp "https://github.com/Wilfred/tree-sitter-elisp") + (go "https://github.com/tree-sitter/tree-sitter-go") + (go-mod "https://github.com/camdencheek/tree-sitter-go-mod") + (html "https://github.com/tree-sitter/tree-sitter-html") + (js . ("https://github.com/tree-sitter/tree-sitter-javascript" "master" "src")) + (json "https://github.com/tree-sitter/tree-sitter-json") + (lua "https://github.com/Azganoth/tree-sitter-lua") + (make "https://github.com/alemuller/tree-sitter-make") + (markdown "https://github.com/ikatyang/tree-sitter-markdown") + (python "https://github.com/tree-sitter/tree-sitter-python") + (rust "https://github.com/tree-sitter/tree-sitter-rust") + (toml "https://github.com/tree-sitter/tree-sitter-toml") + (tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src")) + (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")) + (yaml "https://github.com/ikatyang/tree-sitter-yaml")) + ) (provide 'util-tree-sitter)