feat(json): add treesit support

This commit is contained in:
Henrik Lissner
2025-05-22 19:53:10 +02:00
parent f5a1af4bf6
commit 7af7280f9e
3 changed files with 19 additions and 9 deletions

View File

@ -15,7 +15,7 @@ This module adds [[https://www.json.org/json-en.html][JSON]] support to Doom Ema
(supports [[https://github.com/vscode-langservers/vscode-json-languageserver][vscode-json-languageserver]]). (supports [[https://github.com/vscode-langservers/vscode-json-languageserver][vscode-json-languageserver]]).
- +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]].
** Packages ** Packages
- [[doom-package:counsel-jq]] if [[doom-module::completion ivy]] - [[doom-package:counsel-jq]] if [[doom-module::completion ivy]]

View File

@ -2,16 +2,12 @@
(use-package! json-mode (use-package! json-mode
:mode "\\.js\\(?:on\\|[hl]int\\(?:rc\\)?\\)\\'" :mode "\\.js\\(?:on\\|[hl]int\\(?:rc\\)?\\)\\'"
:init
(when (modulep! +lsp)
(add-hook 'json-mode-local-vars-hook #'lsp! 'append))
(when (modulep! +tree-sitter)
(add-hook! '(json-mode-local-vars-hook
jsonc-mode-local-vars-hook)
:append #'tree-sitter!))
:config :config
(set-electric! 'json-mode :chars '(?\n ?: ?{ ?})) (set-electric! 'json-mode :chars '(?\n ?: ?{ ?}))
(when (modulep! +lsp)
(add-hook 'json-mode-local-vars-hook #'lsp! 'append))
(map! :after json-mode (map! :after json-mode
:map json-mode-map :map json-mode-map
:localleader :localleader
@ -24,6 +20,21 @@
"f" #'json-mode-beautify)) "f" #'json-mode-beautify))
(use-package! json-ts-mode
:when (modulep! +tree-sitter)
:when (fboundp 'json-ts-mode) ; 29.1+ only
:defer t
:init
(set-tree-sitter! 'json-mode 'json-ts-mode
'((json :url "https://github.com/tree-sitter/tree-sitter-json"
:rev "v0.24.8")))
:config
;; HACK: Rely on `major-mode-remap-defaults'.
(cl-callf2 assq-delete-all 'json-ts-mode auto-mode-alist)
(when (modulep! +lsp)
(add-hook 'json-ts-mode-local-vars-hook #'lsp! 'append)))
(use-package! counsel-jq (use-package! counsel-jq
:when (modulep! :completion ivy) :when (modulep! :completion ivy)

View File

@ -31,7 +31,6 @@
(html "https://github.com/tree-sitter/tree-sitter-html" nil nil nil nil) (html "https://github.com/tree-sitter/tree-sitter-html" nil nil nil nil)
(java "https://github.com/tree-sitter/tree-sitter-java" nil nil nil nil) (java "https://github.com/tree-sitter/tree-sitter-java" nil nil nil nil)
(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)
(json "https://github.com/tree-sitter/tree-sitter-json" nil nil 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) (nix "https://github.com/nix-community/tree-sitter-nix" nil nil nil nil)