mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
feat(scala): add treesit support
This commit is contained in:
@ -30,11 +30,12 @@ Through the power of [[https://scalameta.org/metals/docs/editors/overview.html][
|
||||
(supports metals).
|
||||
- +tree-sitter ::
|
||||
Leverages tree-sitter for better syntax highlighting and structural text
|
||||
editing. Requires [[doom-module::tools tree-sitter]].
|
||||
editing. Requires Emacs 29.1+ and [[doom-module::tools tree-sitter]].
|
||||
|
||||
** Packages
|
||||
- [[doom-package:sbt-mode]]
|
||||
- [[doom-package:scala-mode]]
|
||||
- [[doom-package:scala-ts-mode]] if [[doom-module:+tree-sitter]]
|
||||
- [[doom-package:lsp-metals]] if [[doom-module:+lsp]]
|
||||
|
||||
** Hacks
|
||||
|
@ -7,24 +7,12 @@
|
||||
;;
|
||||
;;; Packages
|
||||
|
||||
(after! scala-mode
|
||||
(setq scala-indent:align-parameters t
|
||||
;; indent block comments to first asterix, not second
|
||||
scala-indent:use-javadoc-style t)
|
||||
|
||||
(setq-hook! 'scala-mode-hook
|
||||
comment-line-break-function #'+scala-comment-indent-new-line-fn)
|
||||
|
||||
(when (modulep! +lsp)
|
||||
(setq-hook! 'scala-mode-hook lsp-enable-indentation nil)
|
||||
(add-hook 'scala-mode-local-vars-hook #'lsp! 'append))
|
||||
|
||||
(when (modulep! +tree-sitter)
|
||||
(add-hook 'scala-mode-local-vars-hook #'tree-sitter! 'append))
|
||||
|
||||
(set-formatter! 'scalafmt '("scalafmt" "--stdin") :modes '(scala-mode))
|
||||
|
||||
(set-ligatures! 'scala-mode
|
||||
(defun +scala-common-config (mode)
|
||||
(set-formatter! 'scalafmt '("scalafmt" "--stdin")
|
||||
:modes (list mode))
|
||||
(set-repl-handler! mode #'+scala/open-repl
|
||||
:persist t)
|
||||
(set-ligatures! mode
|
||||
;; Functional
|
||||
:def "def"
|
||||
:composition "compose"
|
||||
@ -49,9 +37,43 @@
|
||||
;; Other
|
||||
:union "union"
|
||||
:intersect "intersect"
|
||||
:diff "diff"))
|
||||
:diff "diff")
|
||||
|
||||
(when (modulep! +lsp)
|
||||
(add-hook (intern (format "%s-local-vars-hook" mode)) #'lsp! 'append)))
|
||||
|
||||
|
||||
(after! scala-mode
|
||||
(setq scala-indent:align-parameters t
|
||||
;; indent block comments to first asterix, not second
|
||||
scala-indent:use-javadoc-style t)
|
||||
|
||||
(setq-hook! 'scala-mode-hook
|
||||
comment-line-break-function #'+scala-comment-indent-new-line-fn
|
||||
lsp-enable-indentation nil)
|
||||
|
||||
(+scala-common-config 'scala-mode))
|
||||
|
||||
|
||||
(use-package! scala-ts-mode
|
||||
:when (modulep! +tree-sitter)
|
||||
:when (fboundp 'treesit-available-p)
|
||||
:defer t
|
||||
:init
|
||||
(set-tree-sitter! 'scala-mode 'scala-ts-mode
|
||||
'((scala :url "https://github.com/tree-sitter/tree-sitter-scala")))
|
||||
|
||||
:config
|
||||
(when (modulep! +lsp)
|
||||
(setq-hook! 'scala-ts-mode-hook lsp-enable-indentation nil)
|
||||
(add-hook 'scala-ts-mode-local-vars-hook #'lsp! 'append))
|
||||
|
||||
;; HACK: Rely on `major-mode-remap-defaults'.
|
||||
(cl-callf2 assq-delete-all 'scala-ts-mode auto-mode-alist)
|
||||
|
||||
(+scala-common-config 'scala-ts-mode))
|
||||
|
||||
|
||||
(use-package! sbt-mode
|
||||
:after scala-mode
|
||||
:config (set-repl-handler! 'scala-mode #'+scala/open-repl :persist t))
|
||||
:config (set-repl-handler! '(scala-mode scala-ts-mode) #'+scala/open-repl :persist t))
|
||||
|
@ -8,6 +8,10 @@
|
||||
(modulep! :tools tree-sitter))
|
||||
"This module requires (:tools tree-sitter)")
|
||||
|
||||
(assert! (or (not (modulep! +tree-sitter))
|
||||
(version< emacs-version "29.1"))
|
||||
"Emacs 29.1+ is required for tree-sitter support")
|
||||
|
||||
(if (and (modulep! +lsp)
|
||||
(not (executable-find "metals")))
|
||||
(warn! "metals isn't installed"))
|
||||
|
@ -4,6 +4,10 @@
|
||||
(package! sbt-mode :pin "cc68728a6ef0600aad369157b3a2d0ce56afba9b")
|
||||
(package! scala-mode :pin "661337d8aa0a0cb418184c83757661603de3b2e3")
|
||||
|
||||
(when (and (modulep! +tree-sitter)
|
||||
(fboundp 'treesit-available-p))
|
||||
(package! scala-ts-mode :pin "c7671e10419261ef70b1820d3b970ad39f6fcfe2"))
|
||||
|
||||
(when (and (modulep! +lsp)
|
||||
(modulep! :tools lsp -eglot))
|
||||
(package! lsp-metals :pin "e1d9d04f3bab7e6e74916054b36ab1a87e831367"))
|
||||
|
@ -42,7 +42,6 @@
|
||||
(proto "https://github.com/mitchellh/tree-sitter-proto" nil nil nil nil)
|
||||
(r "https://github.com/r-lib/tree-sitter-r" nil nil nil nil)
|
||||
(rust "https://github.com/tree-sitter/tree-sitter-rust" nil nil nil nil)
|
||||
(scala "https://github.com/tree-sitter/tree-sitter-scala" nil nil nil nil)
|
||||
(sql "https://github.com/DerekStride/tree-sitter-sql" "gh-pages" nil nil nil)
|
||||
(surface "https://github.com/connorlay/tree-sitter-surface" nil nil nil nil)
|
||||
(toml "https://github.com/tree-sitter/tree-sitter-toml" nil nil nil nil)
|
||||
|
Reference in New Issue
Block a user