feat(graphql): add treesit support

This commit is contained in:
Henrik Lissner
2025-08-28 14:17:38 +02:00
parent 64b4e565c3
commit f782b79797
4 changed files with 41 additions and 13 deletions

View File

@@ -26,10 +26,14 @@ It includes:
- +lsp :: - +lsp ::
Enable LSP support for ~graphql-mode~. Requires [[doom-module::tools lsp]] and a langserver Enable LSP support for ~graphql-mode~. Requires [[doom-module::tools lsp]] and a langserver
([[https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli#readme][graphql-language-service-cli]]). ([[https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli#readme][graphql-language-service-cli]]).
- +tree-sitter ::
Leverages tree-sitter for better syntax highlighting and structural text
editing. Requires [[doom-module::tools tree-sitter]].
** Packages ** Packages
- [[doom-package:company-graphql]] unless [[doom-module:+lsp]] - [[doom-package:company-graphql]] unless [[doom-module:+lsp]]
- [[doom-package:graphql-mode]] - [[doom-package:graphql-mode]]
- [[doom-package:graphql-ts-mode]] if [[doom-module:+tree-sitter]]
- [[doom-package:graphql-doc]] - [[doom-package:graphql-doc]]
** Hacks ** Hacks

View File

@@ -1,22 +1,18 @@
;;; lang/graphql/config.el -*- lexical-binding: t; -*- ;;; lang/graphql/config.el -*- lexical-binding: t; -*-
(after! graphql-mode ;;
(defface nerd-icons-rhodamine ;;; Packages
'((t (:foreground "#E10098")))
"Face for GraphQL icon." (defun +graphql-common-config (mode)
:group 'nerd-icons-faces)
(if (modulep! +lsp) (if (modulep! +lsp)
(add-hook 'graphql-mode-local-vars-hook #'lsp! 'append) (add-hook (intern (format "%s-local-vars-hook" mode)) #'lsp! 'append)
(set-company-backend! 'graphql-mode 'company-graphql)) (set-company-backend! mode 'company-graphql))
(add-hook 'graphql-mode-hook #'rainbow-delimiters-mode) (set-docsets! mode :add "GraphQL Specification")
(set-docsets! 'graphql-mode :add "GraphQL Specification") (set-electric! mode
(set-electric! 'graphql-mode
:chars '(?\} ?\)) :chars '(?\} ?\))
:words '("or" "and")) :words '("or" "and"))
(set-ligatures! mode
(set-ligatures! 'graphql-mode
:null "null" :null "null"
:true "true" :false "false" :true "true" :false "false"
:int "Int" :str "String" :int "Int" :str "String"
@@ -26,5 +22,26 @@
:not "not" :not "not"
:and "and" :or "or")) :and "and" :or "or"))
(after! graphql-mode
(defface nerd-icons-rhodamine
'((t (:foreground "#E10098")))
"Face for GraphQL icon."
:group 'nerd-icons-faces)
(add-hook 'graphql-mode-hook #'rainbow-delimiters-mode)
(+graphql-common-config 'graphql-mode))
(use-package! graphql-ts-mode
:when (modulep! +tree-sitter)
:when (fboundp 'treesit-available-p)
:defer t
:init
(set-tree-sitter! 'graphql-mode 'graphql-ts-mode
'((graphql :url "https://github.com/bkegley/tree-sitter-graphql")))
:config
(+graphql-common-config 'graphql-ts-mode))
(use-package! graphql-doc (use-package! graphql-doc
:after graphql-mode) :after graphql-mode)

View File

@@ -0,0 +1,5 @@
;;; lang/graphql/doctor.el -*- lexical-binding: t; -*-
(assert! (or (not (modulep! +tree-sitter))
(modulep! :tools tree-sitter))
"This module requires (:tools tree-sitter)")

View File

@@ -7,3 +7,5 @@
(package! company-graphql (package! company-graphql
:recipe (:host github :repo "thaenalpha/company-graphql") :recipe (:host github :repo "thaenalpha/company-graphql")
:pin "aed9f5109e877944a895d08fc08bad103f03096b")) :pin "aed9f5109e877944a895d08fc08bad103f03096b"))
(when (modulep! +tree-sitter)
(package! graphql-ts-mode :pin "e933f235408ea195762700fd07c2d828e8f09aac"))