Commit graph

148 commits

Author SHA1 Message Date
Andrew Peck
15d5525915 tweak(tree-sitter): use maintained systemverilog grammar
tree-sitter-verilog has unfortunately not been maintained for years.

Gonzalo maintains tree-sitter-systemverilog which boasts

- Full implementation of the latest SystemVerilog standard (IEEE 1800-2023)
- Robust and reliable: sv-tests results
- Actively maintained
- Implements node fields
- Supports parsing of code snippets (e.g., always block outside of a module)
- Basic preprocessing capabilities
- Thoroughly tested (~3000 tests) including:

verilog is strictly a subset of systemverilog so the systemverilog
grammar is backwards compatible with verilog features.

tree-sitter-verilog has significant issues and fails parsing many basic
verilog files.

I use tree-sitter-systemverilog daily and have had no issues since switching.
2026-03-06 02:46:23 -05:00
Henrik Lissner
6f40ad55f5
docs: discourage after! and use-package! use
There's little reason for users to use these macros in their private
configs over plain ol' `with-eval-after-load` and `use-package`, unless
they're writing their own modules.

It's my fault for signal boosting them in documentation and whenever I'm
asked for help, because beginners now believe they are somehow
required for Doom to work correctly (there are guides out there
telling beginners that migrating to Doom involves replacing all
instances of `with-eval-after-load` and `use-package` in their
pre-existing configs with `after!` and `use-package!` -- which was never
true).

What's more, I plan to replace `use-package`, internally, so the
`use-package!` macro won't exist for much longer.
2026-02-09 04:29:47 -05:00
Henrik Lissner
1a943aea69
refactor: cut down on pseudo-features
Way back, I added these three pseudo-features:

  (featurep 'dynamic-modules)
  (featurep 'harfbuzz)
  (featurep 'jansson)

Why? Because some build features have pseudo features (like
`tty-child-frames`, `pgtk`, and `threads`), but others don't, and I
wanted more consistency around build feature detection. Years later, I
realized it wasn't used much internally and only ended up confusing
readers who didn't realize these were Doom's additions and not built
into Emacs. Emacs' idiosyncrasies may not be nice or elegant, but
they're less surprising to elisp beginners and veterans alike.
2026-01-23 20:26:28 -05:00
Henrik Lissner
deaf794ccf
fix(tree-sitter): pre-30 compatibility
0d2f10d introduced a regression that broke the arity check in
`set-tree-sitter!` for pre-30 compatibility, because `func-arity`
returned the arity of the advice, not the advised function, so the
`commit` argument was always stored in `treesit-language-source-alist`,
even before it was supported, resulting in wrong-number-of-args errors
for users on Emacs <=29.

Amend: 0d2f10dcab
2025-12-04 04:42:04 -05:00
Henrik Lissner
0d2f10dcab
fix(tree-sitter): arity error installing grammars on <=29 2025-12-03 03:58:30 -05:00
Henrik Lissner
281e3069a7
fix(tree-sitter): always install grammars to profile data dir
Fix: #8578
Co-authored-by: falloutphil <falloutphil@users.noreply.github.com>
2025-12-01 01:14:54 -05:00
Henrik Lissner
4c9dee2c78
fix(tree-sitter): treesit-extra-load-path: use file-name-concat
In case doom-profile-data-dir doesn't end with a slash (which is a
stipulation I won't be enforcing for Doom's dir variables in v3 and
beyond).

Fix: #8511
2025-09-17 17:49:22 -04:00
Henrik Lissner
4a6f9f741d
feat(tree-sitter): add +tree-sitter/doctor command
For a quick diagnosis of the state of tree-sitter support in the current
buffer.
2025-09-17 01:23:45 -04:00
Henrik Lissner
5614faca7a
docs(tree-sitter): revise installation docs
To clarify how to enable tree-sitter, fully.
2025-09-17 01:23:45 -04:00
Henrik Lissner
35d2934727
refactor(tree-sitter): dynamic-modules doctor check 2025-09-15 18:53:31 -04:00
Henrik Lissner
71ec9a9733
fix: backport treesit-available-p sooner
This fixes Doom for Emacs 27-28 users (or builds without treesit).
2025-09-15 18:53:31 -04:00
Henrik Lissner
d6cdbb4d22
docs(tree-sitter): document treesit-font-lock-level
Close: #8487
2025-09-11 23:37:14 -04:00
Henrik Lissner
1adec8b10c
fix(tree-sitter): add derived-mode parents to ts-modes
ts-modes do this already in 30/31+ (`derived-mode-add-parents` was added
in 30), but is still needed for 29.x users and any ts-modes that haven't
adapted (many of them).

Fix: doomemacs/community#29
2025-09-07 10:58:45 -04:00
Henrik Lissner
ddc447d9d5
tweak(tree-sitter): treesit-font-lock-level = 4
Fix: #8494
Close: #8487
2025-09-05 15:10:57 -04:00
Henrik Lissner
5ca9b7a37a
fix(tree-sitter): autodef treesit-available-p
This way, whether the module is enabled or not, `treesit-available-p`
will exist, even in Emacs build without treesit.

Amend: a51690f033
2025-09-03 16:29:16 +02:00
Henrik Lissner
78068a8f31
fix(tree-sitter): more verbosity in debug mode
And slightly better logged message if the grammar is missing.
2025-09-03 16:28:45 +02:00
Henrik Lissner
d1289bf8cf
fix(tree-sitter): remove *-ts-mode-maybe from {auto,interpreter}-mode-alist
Again, removing more over-eager entries.

Also fixes `set-tree-sitter!` not accepting multiple MODEs before.
2025-09-03 14:44:51 +02:00
Henrik Lissner
8dab364e46
fix(tree-sitter): suppress changes to {auto,interpreter}-mode-alist
...when auto-loading a ts-mode package.
2025-09-03 14:42:28 +02:00
Henrik Lissner
bbed615f17
feat(tree-sitter): batch grammar installs
Instead of being prompted 2-4 times to install each missing grammar,
batches them together into one prompt.
2025-09-02 16:16:02 +02:00
Henrik Lissner
79a9418cba
fix(tree-sitter): backport treesit-*-abi-version
So we don't have to litter these checks with feature/fboundp
checks (there will potentially be many of them).
2025-09-02 03:28:40 +02:00
Henrik Lissner
a51690f033
fix(:lang): add treesit-available-p checks to *-ts-mode packages
Otherwise package installation will throw Emacs version errors for users
on 28 and under.
2025-09-01 20:11:02 +02:00
Henrik Lissner
84e8ae58d1
refactor(:lang): remove fboundp checks for *-ts-modes
The major-mode-remap advice will handle undefined modes, so all these
extra checks aren't needed.
2025-09-01 20:11:02 +02:00
Henrik Lissner
1dae2bf916
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.
2025-08-31 16:20:14 +02:00
Henrik Lissner
94a1fe64a8
fix(tree-sitter): suppress "Can't find grammar" warnings
In Emacs <=30, top-level `treesit-ready-p` calls in various *-ts-mode
packages (like lua-ts-mode or ruby-ts-mode) are commonplace, and they
throw up a warning popup if the grammar isn't available at load time.
This is intrusive. Instead, this forces it to log to *Messages* instead
before falling back to the normal major mode.

Fortunately, these top-level `treesit-ready-p` calls have been removed
in most *-ts-mode packages in 31+, but this still impacts users on <=30
or using third party *-ts-modes that haven't adapted.

However, this doesn't suppress the warning when opening a *-ts-mode.el
file (thanks to the byte-compiler).
2025-08-31 14:41:40 +02:00
Henrik Lissner
d545fccf47
fix(:lang): missing grammar recipes
I removed the grammar recipes in 3b58741 to avoid redundancy with the
upstream recipes, but didn't realize that those upstream recipes weren't
added until Emacs 31, so users on 30 and older would get errors when
trying to install any missing grammars.

This also establishes a hard dependency between :lang (php +tree-sitter)
and :lang ({javascript,web} +tree-sitter).

Amend: 3b58741522
2025-08-31 14:39:38 +02:00
Henrik Lissner
d9fd5cb8f3
fix(tree-sitter): treesit-enabled-modes: sort arity in <30
`sort`s signature changed in Emacs 30 from:

  (sort SEQ PREDICATE)

To

  (sort SEQ &key KEY LESSP REVERSE IN-PLACE)

Amend: 6009c2b838
2025-08-31 14:34:45 +02:00
Henrik Lissner
7dcedc16b5
refactor(tree-sitter): major mode remapping
This approach simplifies the hacks and uses fewer moving parts to be
less error prone (or prone to potentially overwriting user/module
configuration).
2025-08-30 09:41:25 +02:00
Henrik Lissner
702d976665
docs(tree-sitter): document module hacks 2025-08-29 14:37:10 +02:00
Henrik Lissner
cd5dd5279e
fix(tree-sitter): major mode remapping on first-load
Also refactors +tree-sitter--major-mode-remaps-alist to be lighter.
2025-08-29 14:35:49 +02:00
Henrik Lissner
bd0bee92cc
feat!(javascript): add treesit support
BREAKING CHANGE: This commit removes a number of core packages and
features from this module and only replaces a handful of them, so that
we can lean more on LSP and tree-sitter. To be specific:

- We used to rely on `rjsx-mode` (derived from js2-mode) for total
  JS/JSX support (though imperfect; Emacs was starved for options at the
  time). This has now been replaced with `js-ts-mode` (built-in after
  Emacs 29), falling back to `js-mode` (very rudimentary, but a decent
  fallback).
- This also meant the removal of `js2-mode`, which `skewer-mode`,
  `js2-refactor`, and `xref-js2` depended on, so those were removed
  too, and have *somewhat* been replaced with LSP integration (offers
  jump-to-definition/references and *some* refactoring actions, but no
  replacement for skewer's functionality).
- Typescript support no longer relies on the jury-rigged, web-mode-derived
  major mode (because TSX support in the upstream `typescript-mode`
  isn't great). We now use `typescript-ts-mode` (built-in into Emacs
  29.1+), falling back to `typescript-mode`.
- JSX/TSX support now *requires* tree-sitter (and Emacs 29.1+), where
  `tsx-ts-mode` is available and outshines all the alternatives (at the
  time of writing).

Due to the absolute chaos that is webdev, this module sacrifices some of
the graceful-degradation I've implemented for other modules and creates
a hard requirement on tree-sitter and Emacs 29.1+ for JSX/TSX. It still
tries to degrade gracefully for plain JS and TS, but the module's doctor
and docs will actively recommend tree-sitter.

Close: #5278
Fix: #6172
Fix: #7042
Close: #8447
Co-authored-by: ribaricplusplus <ribaricplusplus@users.noreply.github.com>
2025-08-29 14:35:49 +02:00
Henrik Lissner
64b4e565c3
refactor(tree-sitter): remove redundant grammars
Already registered by csharp and web module packages.

Amend: 5bf132a80f
Amend: c403bb5e2f
2025-08-28 14:32:08 +02:00
Henrik Lissner
3b58741522
refactor(tree-sitter): centralize grammar config & hacks
Easier to track and maintain.
2025-08-27 16:57:28 +02:00
Henrik Lissner
6009c2b838
fix(tree-sitter): backport treesit-{enabled-modes,major-mode-remap-alist}
And ignore `treesit-major-mode-remap-alist`, because they could
interfere with our UX improvements.
2025-08-23 18:43:14 +02:00
Henrik Lissner
2adbdf1360
feat(clojure): add treesit support 2025-06-30 15:16:26 +02:00
Henrik Lissner
7949d1bf27
fix(tree-sitter): void-variable +tree-sitter--major-mode-remaps-alist
This is a temporary solution and will be polished up before the treesit
branch is merged into master.

Ref: #7623
Amend: 617d8411e6
2025-06-30 14:48:54 +02:00
Henrik Lissner
a8ccd2d47a
fix(tree-sitter): unable to find local grammars (part 2)
Ref: #7623
Amend: 4df993d683
2025-06-30 14:47:35 +02:00
Henrik Lissner
0d9cf54c84
refactor(tree-sitter): remove redundant dart grammar
Amend: a287a96aca
2025-06-28 21:17:15 +02:00
Henrik Lissner
7c6e1950e8
feat(go): add treesit support 2025-06-28 20:10:08 +02:00
Henrik Lissner
617d8411e6
fix(tree-sitter): ignore major-mode-remap-defaults for ts modes
...registered with `set-tree-sitter!`. Then we don't have to chase after
packages inconsistently modifying `major-mode-remap-defaults`.
2025-06-28 19:32:27 +02:00
Henrik Lissner
4df993d683
fix(tree-sitter): unable to find local grammars
Ref: #7623
2025-06-28 17:37:24 +02:00
Henrik Lissner
5b37bfee23
feat(nix): add treesit support 2025-05-24 17:27:30 +02:00
Henrik Lissner
3b2caa7dcd
feat(docker): add treesit support 2025-05-24 17:11:40 +02:00
Henrik Lissner
7af7280f9e
feat(json): add treesit support 2025-05-22 19:53:10 +02:00
Henrik Lissner
f5a1af4bf6
feat(kotlin): add treesit support 2025-05-22 19:50:29 +02:00
Henrik Lissner
c5dd2847ff
feat(scala): add treesit support 2025-05-22 19:50:29 +02:00
Henrik Lissner
5db361b474
fix(tree-sitter): remove redundant yaml source
Amend: 2556cb58f2
2025-05-22 18:32:04 +02:00
Henrik Lissner
0c311a5172
feat(elixir): add treesit support 2025-05-22 18:32:03 +02:00
Henrik Lissner
a329d63f7d
fix(tree-sitter): discard COMMIT recipe argument on <=30.x
Otherwise `treesit--install-language-grammar-1` will throw an arity
error on Emacs <=30.x when installing grammars.

Fix: #8393
2025-05-16 08:49:20 +02:00
Henrik Lissner
b546522257
docs(tree-sitter): revise doctor output 2025-05-15 18:58:29 +02:00
Henrik Lissner
1670ce2767
feat!(cc): add treesit support
BREAKING CHANGE: Besides treesit support, this removes a few
fontification enhancements (in favor of tree-sitter).
2025-05-15 13:01:40 +02:00