From 1dae2bf916ea631ab0d129218cf69ece94a11e4f Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 31 Aug 2025 16:12:00 +0200 Subject: [PATCH] fix(tree-sitter): remap to ts-mode w/o base mode If the base major mode doesn't exist, let's assume we want no fallthrough for this major mode (in the event the grammar isn't ready) and simply push forward anyway, even if a missing grammar results in a broken state. This will particularly affect major modes like `typescript-mode` (which simply won't be installed if +tree-sitter is enabled) and `go-{mod,work}-ts-mode` (for which no base major modes exist). The difference (generally) between most base and ts-modes is performance, not features, so "gracefully failing back to the base mode" makes sense UX-wise, but `typescript-mode` notably inferior to `typescript-ts-mode` (particularly in its TSX support). Beginners may misidentify its shortcomings as bugs, so it's better to simply error out early so the user can be made aware of the problem sooner and less ambiguously. --- modules/lang/javascript/packages.el | 4 +--- modules/tools/tree-sitter/config.el | 7 ++++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/lang/javascript/packages.el b/modules/lang/javascript/packages.el index 5a61a437a..d64255af2 100644 --- a/modules/lang/javascript/packages.el +++ b/modules/lang/javascript/packages.el @@ -2,9 +2,7 @@ ;;; lang/javascript/packages.el ;; Major modes -(unless (or (modulep! +tree-sitter) - (fboundp 'treesit-available-p) - (treesit-available-p)) +(unless (modulep! +tree-sitter) (package! typescript-mode :pin "481df3ad2cdf569d8e6697679669ff6206fbd2f9")) ;; Extensions diff --git a/modules/tools/tree-sitter/config.el b/modules/tools/tree-sitter/config.el index d45aa88c9..8203147d0 100644 --- a/modules/tools/tree-sitter/config.el +++ b/modules/tools/tree-sitter/config.el @@ -60,7 +60,12 @@ (or (not (autoloadp fn)) (autoload-do-load fn mode))) ;; Only prompt once, and log other times. - (or (null (cdr ts)) + (or (null (cdr ts)) ; no grammars, no problem! + ;; If the base/fallback mode doesn't exist, let's + ;; assume we want no fallthrough for this major mode + ;; and push forward anyway, even if a missing grammar + ;; results in a broken state. + (not (fboundp fallback-mode)) (cl-every (if (get mode '+tree-sitter-ensured) (doom-rpartial #'treesit-ready-p 'message) #'treesit-ensure-installed)