feat(docker): add treesit support

This commit is contained in:
Henrik Lissner
2025-05-24 16:56:48 +02:00
parent 7af7280f9e
commit 3b2caa7dcd
4 changed files with 24 additions and 1 deletions

View File

@ -18,6 +18,9 @@ functions allow images to be built easily.
** Module flags
- +lsp ::
Enable integration for the Dockerfile Language Server.
- +tree-sitter ::
Leverages tree-sitter for better syntax highlighting and structural text
editing. Requires Emacs 29.1+ and [[doom-module::tools tree-sitter]].
** Packages
- [[doom-package:docker]]

View File

@ -6,3 +6,16 @@
(when (modulep! +lsp)
(add-hook 'dockerfile-mode-local-vars-hook #'lsp! 'append)))
(use-package! dockerfile-ts-mode
:when (modulep! +tree-sitter)
:when (fboundp 'dockerfile-ts-mode) ; 29.1+ only
:defer t
:init
(set-tree-sitter! 'dockerfile-mode 'dockerfile-ts-mode
'((dockerfile :url "https://github.com/camdencheek/tree-sitter-dockerfile"
:rev "v0.2.0")))
:config
;; HACK: Rely on `major-mode-remap-defaults' instead
(cl-callf2 rassq-delete-all 'dockerfile-ts-mode auto-mode-alist))

View File

@ -1,5 +1,13 @@
;;; tools/docker/doctor.el -*- lexical-binding: t; -*-
(assert! (or (not (modulep! +tree-sitter))
(modulep! :tools tree-sitter))
"This module requires (:tools tree-sitter)")
(assert! (or (not (modulep! +tree-sitter))
(fboundp 'dockerfile-ts-mode))
"Can't find `dockerfile-ts-mode'; Emacs 29.1+ is required")
(when (modulep! :editor format)
(unless (executable-find "dockfmt")
(warn! "Couldn't find dockfmt. Formatting will be disabled.")))

View File

@ -25,7 +25,6 @@
(commonlisp "https://github.com/tree-sitter-grammars/tree-sitter-commonlisp" nil nil nil nil)
(css "https://github.com/tree-sitter/tree-sitter-css" nil nil nil nil)
(dart "https://github.com/ast-grep/tree-sitter-dart" nil nil nil nil)
(dockerfile "https://github.com/camdencheek/tree-sitter-dockerfile" nil nil nil nil)
(go "https://github.com/tree-sitter/tree-sitter-go" nil nil nil nil)
(gomod "https://github.com/camdencheek/tree-sitter-go-mod" nil nil nil nil)
(html "https://github.com/tree-sitter/tree-sitter-html" nil nil nil nil)