mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-03 12:27:26 -05:00
feat(nix): add treesit support
This commit is contained in:
@ -19,20 +19,18 @@ Includes:
|
|||||||
[[doom-contrib-maintainer:][Become a maintainer?]]
|
[[doom-contrib-maintainer:][Become a maintainer?]]
|
||||||
|
|
||||||
** Module flags
|
** Module flags
|
||||||
|
- +lsp ::
|
||||||
|
Enable an LSP hook for ~nix-mode~. Requires [[doom-module::tools lsp]] and a
|
||||||
|
language server (one of either ~nil~ or ~rnix-lsp~).
|
||||||
- +tree-sitter ::
|
- +tree-sitter ::
|
||||||
Leverages tree-sitter for better syntax highlighting and structural text
|
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]].
|
||||||
- +lsp ::
|
|
||||||
Enable an LSP hook for ~nix-mode~. Requires [[doom-module::tools lsp]] and a language
|
|
||||||
server (one of either ~nil~ or ~rnix-lsp~).
|
|
||||||
|
|
||||||
You can still start a nix lsp manually without this flag, this just adds
|
|
||||||
a hook to always start the lsp when loading ~nix-mode~.
|
|
||||||
|
|
||||||
** Packages
|
** Packages
|
||||||
- [[doom-package:company-nixos-options]] if [[doom-module::completion company]]
|
- [[doom-package:company-nixos-options]] if [[doom-module::completion company]]
|
||||||
- [[doom-package:helm-nixos-options]] if [[doom-module::completion helm]]
|
- [[doom-package:helm-nixos-options]] if [[doom-module::completion helm]]
|
||||||
- [[doom-package:nix-mode]]
|
- [[doom-package:nix-mode]]
|
||||||
|
- [[doom-package:nix-ts-mode]] if [[doom-module:+tree-sitter]]
|
||||||
- [[doom-package:nix-update]]
|
- [[doom-package:nix-update]]
|
||||||
|
|
||||||
** Hacks
|
** Hacks
|
||||||
|
@ -7,33 +7,25 @@
|
|||||||
;;
|
;;
|
||||||
;;; Plugins
|
;;; Plugins
|
||||||
|
|
||||||
(use-package! nix-mode
|
(add-to-list 'auto-mode-alist
|
||||||
:interpreter ("\\(?:cached-\\)?nix-shell" . +nix-shell-init-mode)
|
(cons "/flake\\.lock\\'"
|
||||||
:mode "\\.nix\\'"
|
(if (modulep! :lang json)
|
||||||
:init
|
'json-mode
|
||||||
(add-to-list 'auto-mode-alist
|
'js-mode)))
|
||||||
(cons "/flake\\.lock\\'"
|
|
||||||
(if (modulep! :lang json)
|
|
||||||
'json-mode
|
(defun +nix-common-config (mode)
|
||||||
'js-mode)))
|
(set-repl-handler! mode #'+nix/open-repl)
|
||||||
:config
|
(set-company-backend! mode 'company-nixos-options)
|
||||||
(set-repl-handler! 'nix-mode #'+nix/open-repl)
|
(set-lookup-handlers! mode
|
||||||
(set-company-backend! 'nix-mode 'company-nixos-options)
|
|
||||||
(set-lookup-handlers! 'nix-mode
|
|
||||||
:documentation '(+nix/lookup-option :async t))
|
:documentation '(+nix/lookup-option :async t))
|
||||||
(set-popup-rule! "^\\*nixos-options-doc\\*$" :ttl 0 :quit t)
|
(set-popup-rule! "^\\*nixos-options-doc\\*$" :ttl 0 :quit t)
|
||||||
|
|
||||||
;; Fix #3927: disable idle completion because `company-nixos-options' is
|
|
||||||
;; dreadfully slow. It can still be invoked manually..
|
|
||||||
(setq-hook! 'nix-mode-hook company-idle-delay nil)
|
|
||||||
|
|
||||||
(when (modulep! +lsp)
|
(when (modulep! +lsp)
|
||||||
(add-hook 'nix-mode-local-vars-hook #'lsp! 'append))
|
(add-hook (intern (format "%s-local-vars-hook" mode)) #'lsp! 'append))
|
||||||
(when (modulep! +tree-sitter)
|
|
||||||
(add-hook 'nix-mode-local-vars-hook #'tree-sitter! 'append))
|
|
||||||
|
|
||||||
(map! :localleader
|
(map! :localleader
|
||||||
:map nix-mode-map
|
:map ,(symbol-value (intern (format "%s-map" mode)))
|
||||||
"f" #'nix-update-fetch
|
"f" #'nix-update-fetch
|
||||||
"p" #'nix-format-buffer
|
"p" #'nix-format-buffer
|
||||||
"r" #'nix-repl-show
|
"r" #'nix-repl-show
|
||||||
@ -43,6 +35,32 @@
|
|||||||
"o" #'+nix/lookup-option))
|
"o" #'+nix/lookup-option))
|
||||||
|
|
||||||
|
|
||||||
|
(use-package! nix-mode
|
||||||
|
:interpreter ("\\(?:cached-\\)?nix-shell" . +nix-shell-init-mode)
|
||||||
|
:mode "\\.nix\\'"
|
||||||
|
:config
|
||||||
|
(+nix-common-config 'nix-mode))
|
||||||
|
|
||||||
|
|
||||||
|
(use-package! nix-ts-mode
|
||||||
|
:when (modulep! +tree-sitter)
|
||||||
|
:when (fboundp 'treesit-available-p)
|
||||||
|
:defer t
|
||||||
|
:init
|
||||||
|
(set-tree-sitter! 'nix-mode 'nix-ts-mode
|
||||||
|
'((nix :url "https://github.com/nix-community/tree-sitter-nix")))
|
||||||
|
:config
|
||||||
|
(+nix-common-config 'nix-ts-mode))
|
||||||
|
|
||||||
|
|
||||||
|
(use-package! company-nixos-options
|
||||||
|
:defer t
|
||||||
|
:init
|
||||||
|
;; Fix #3927: disable idle completion because `company-nixos-options' is
|
||||||
|
;; dreadfully slow. It can still be invoked manually..
|
||||||
|
(setq-hook! '(nix-mode-hook nix-ts-mode-hook) company-idle-delay nil))
|
||||||
|
|
||||||
|
|
||||||
(use-package! nix-update
|
(use-package! nix-update
|
||||||
:commands nix-update-fetch)
|
:commands nix-update-fetch)
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
;; -*- lexical-binding: t; no-byte-compile: t; -*-
|
;; -*- lexical-binding: t; no-byte-compile: t; -*-
|
||||||
;;; lang/nix/doctor.el
|
;;; lang/nix/doctor.el
|
||||||
|
|
||||||
|
(assert! (or (modulep! -tree-sitter)
|
||||||
|
(modulep! :tools tree-sitter))
|
||||||
|
"This module requires (:tools tree-sitter)")
|
||||||
|
|
||||||
(unless (executable-find "nix")
|
(unless (executable-find "nix")
|
||||||
(warn! "Couldn't find the nix package manager. nix-mode won't work."))
|
(warn! "Couldn't find the nix package manager. nix-mode won't work."))
|
||||||
|
|
||||||
(when (require 'nix-mode nil t)
|
(when (require 'nix-mode nil t)
|
||||||
(unless (executable-find nix-nixfmt-bin)
|
(unless (executable-find nix-nixfmt-bin)
|
||||||
(warn! (concat "Couldn't find " nix-nixfmt-bin ". nix-format-buffer won't work."))))
|
(warn! (concat "Couldn't find " nix-nixfmt-bin ". nix-format-buffer won't work."))))
|
||||||
|
|
||||||
(assert! (or (modulep! -tree-sitter)
|
|
||||||
(modulep! :tools tree-sitter))
|
|
||||||
"This module requires (:tools tree-sitter)")
|
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
(package! nix-mode :pin "719feb7868fb567ecfe5578f6119892c771ac5e5")
|
(package! nix-mode :pin "719feb7868fb567ecfe5578f6119892c771ac5e5")
|
||||||
(package! nix-update :pin "77022ccd918d665acbb519b243e7e3dc5eae1c47")
|
(package! nix-update :pin "77022ccd918d665acbb519b243e7e3dc5eae1c47")
|
||||||
|
|
||||||
|
(when (and (modulep! +tree-sitter)
|
||||||
|
(fboundp 'treesit-available-p))
|
||||||
|
(package! nix-ts-mode :pin "62ce3a2dc39529c5db3516427e84b2c96b8efcfd"))
|
||||||
|
|
||||||
(when (modulep! :completion company)
|
(when (modulep! :completion company)
|
||||||
(package! company-nixos-options :pin "053a2d5110ce05b7f99bcc2ac4804b70cbe87916"))
|
(package! company-nixos-options :pin "053a2d5110ce05b7f99bcc2ac4804b70cbe87916"))
|
||||||
|
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
(javascript "https://github.com/tree-sitter/tree-sitter-javascript" "master" "src" nil nil)
|
(javascript "https://github.com/tree-sitter/tree-sitter-javascript" "master" "src" nil nil)
|
||||||
(latex "https://github.com/latex-lsp/tree-sitter-latex" nil nil nil nil)
|
(latex "https://github.com/latex-lsp/tree-sitter-latex" nil nil nil nil)
|
||||||
(make "https://github.com/tree-sitter-grammars/tree-sitter-make" nil nil nil nil)
|
(make "https://github.com/tree-sitter-grammars/tree-sitter-make" nil nil nil nil)
|
||||||
(nix "https://github.com/nix-community/tree-sitter-nix" nil nil nil nil)
|
|
||||||
(nu "https://github.com/nushell/tree-sitter-nu" nil nil nil nil)
|
(nu "https://github.com/nushell/tree-sitter-nu" nil nil nil nil)
|
||||||
(org "https://github.com/milisims/tree-sitter-org" nil nil nil nil)
|
(org "https://github.com/milisims/tree-sitter-org" nil nil nil nil)
|
||||||
(perl "https://github.com/ganezdragon/tree-sitter-perl" nil nil nil nil)
|
(perl "https://github.com/ganezdragon/tree-sitter-perl" nil nil nil nil)
|
||||||
|
Reference in New Issue
Block a user