acanimal · 2022-12-18 08:34
Hi everyone,
I'm new in the emacs world and after practicing a bit with doomemacs, I'm trying to configure vanilla emacs by myself with my own `init.el` file.
I have installer tree-sitter for syntax highlighting and works fine for JS file but not for TS files. My configuration for tree-sitter is the next:
```
(use-package tree-sitter
:ensure t
:config
(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))
(use-package tree-sitter-langs
:ensure t
:after tree-sitter)
```
Anyone has the same problem? or I'm missing something in my configuration?
Thanks!
jimehgeek · 2022-12-18 16:15
I just had a quick look at tree-sitter-langs to double check its TypeScript support. And seems to have a full set of [highlight queries](https://github.com/emacs-tree-sitter/tree-sitter-langs/blob/388dcbbc237b2b1360e5b148e67b158eecede805/queries/typescript/highlights.scm) for it.
So off the top of my head, only thing I can think of is that maybe you’re not using `typescript-mode` for `*.ts` files? As the typescript grammar is specifically bound to that mode [here](https://github.com/emacs-tree-sitter/tree-sitter-langs/blob/388dcbbc237b2b1360e5b148e67b158eecede805/tree-sitter-langs.el#L142).
redblobgames · 2022-12-18 16:21
You might need
(use-package tree-sitter-langs :ensure t
:config
(tree-sitter-require 'typescript)
)
The other thing to check is what major-mode you're using for TS files. `tree-sitter-major-mode-language-alist` assumes it's `typescript-mode`.
condor2000 · 2022-12-18 17:24
so maybe this is needed
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))
jimehgeek · 2022-12-18 17:33
Yeah, you’re basically gonna need the typescript package: https://github.com/emacs-typescript/typescript.el
It can be installed from MELPA or the Non-GNU Elpa sources.
acanimal · 2022-12-18 19:16
ah, that clarifies a lot. The thing that I don't understand is JS files are highlighted fine and I have JS mode installed 🤔
jimehgeek · 2022-12-18 19:25
Right, that should work fine if you’re using one of the JavaScript major modes that tree-sitter-langs supports for js files.
Do you use [`typescript-mode`](https://github.com/emacs-tree-sitter/tree-sitter-langs/blob/388dcbbc237b2b1360e5b148e67b158eecede805/tree-sitter-langs.el#L101) for `*.ts` files?
You can check the `tree-sitter-major-mode-language-alist` variable for a list of major mode to tree-sitter grammar mappings. Or check the source that defines the default mappings [here](https://github.com/emacs-tree-sitter/tree-sitter-langs/blob/388dcbbc237b2b1360e5b148e67b158eecede805/tree-sitter-langs.el#L101).
acanimal · 2022-12-18 20:26
Sorry I have a typo 😅 I mean I have no JS mode installed and JS files are highlighted correctly.
BTW the issue is solved once I add the typescript-mode
Thanks!
jimehgeek · 2022-12-18 20:29
Nice :)… and off the top of my head I’m pretty sure `js-mode` is part of Emacs itself, and maybe even `js2-mode` too.