-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TSX (web-mode) tree-sitter-hl not working #23
Comments
Can you provide more details to reproduce the issue? For example:
|
Sorry that I'm just now responding to this. It still doesn't seem to work on the latest commit.
Here's the relevant part of my config: (use-package tree-sitter
:hook ((rustic-mode python-mode json-mode js-mode js2-mode typescript-mode go-mode sh-mode) . tree-sitter-mode)
:config
(require 'tree-sitter-langs)
(push '(typescript-tsx-mode . typescript) tree-sitter-major-mode-language-alist)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)) Here's (t
(web-mode-fontify
(whitespace-point--flush-used)
("\\( +\\)" 1 whitespace-tab t))
(web-mode-fontify
(0 font-lock-keyword-face))
(whitespace-point--flush-used
(0 nil))
("\\( +\\)"
(1 whitespace-tab t))) Here's ('(web-mode-fontify)
t) EDIT 2: I just tried it with plain |
typescript and typescript-tsx have different syntax see tree-sitter-typescript It's a conflict between I think the fix is to have separate mode, grammar, and HL queries for typescript-tsx I also get parsing errors from a normal TSX file using typescript-mode, even though it compiles correctly. |
Turns out tree-sitter-langs already comes with the TSX grammar, you can set it up with a typescript-tsx mode. Still missing TSX highlighting queries I think. but this is a pretty good start. Here's my config that lets me parse TSX ;; Typescript
(setq typescript-indent-level 2)
;; you can also use the DOOM one if you wish
(define-derived-mode typescript-tsx-mode typescript-mode "TSX"
"Major mode for editing TSX files.
Refer to Typescript documentation for syntactic differences between normal and TSX
variants of Typescript.")
(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescript-tsx-mode))
(use-package tree-sitter
:ensure t)
(use-package tree-sitter-langs
:ensure t
:after tree-sitter
:config
(tree-sitter-require 'tsx)
(add-to-list 'tree-sitter-major-mode-language-alist '(typescript-tsx-mode . tsx))) With this config, if I open a typescript file and check
|
@srcreigh I wonder if a very small MELPA package that sets up the derived mode as a target for hooks wouldn't be such a bad idea. |
https://github.com/tree-sitter/tree-sitter-javascript/blob/master/queries/highlights-jsx.scm simple jsx highlights.scm, can be used with existed typescript and javascript query. Update: the query for typescript may need some changes since the grammer for typescript and tsx are different. |
This is a crude workaround, but if you set (setq tree-sitter-hl-use-font-lock-keywords nil) then you'll bypass the logic in My value of (("\\_<[[:digit:]]+\\(?:\\.[0-9]*\\)?\\_>" quote highlight-numbers-number)
web-mode-fontify
((lambda
(bound)
(hl-todo--search nil bound))
(1
(hl-todo--get-face)
t t))
(whitespace-point--flush-used)
("\\( +\\)" 1 whitespace-tab t)) Unlike what @loafofpiecrust posted, this does include |
Thanks @sangaline for the workaround. Oh It seems my concern below actually has been handled well. The problem came on the Previously: I'm exploring a bit and found this bug is mainly due to this construct, right? ;; In web-mode
(setq font-lock-defaults '('(web-mode-fontify) t))
;; In emacs-tree-sitter
(setq keywords-spec (car font-lock-defaults))
(car (cdr keywords-spec)))
;; Which led to an equivalent
(car (car '('(web-mode-fontify)))) ;; => quote If |
Perhaps, related to this issue? |
Yes, albeit not a solution. I remember started using this after reading the post. |
In case anyone else comes across this - The following pattern works well enough for me as a workaround for tree-sitter in a derived web-mode. (defun typescript-tsx-mode-fix-tree-sitter()
(set (make-local-variable 'tree-sitter-hl-use-font-lock-keywords) nil))
(add-hook 'typescript-tsx-mode-hook #'typescript-tsx-mode-fix-tree-sitter) |
I've been using
tree-sitter-hl-mode
forrustic-mode
andjs2-mode
and it seems to be working great. When I try to enable it in a.tsx
file (typescript-tsx-mode
), however, I get an error and the mode fails to start.Here's the backtrace:
The text was updated successfully, but these errors were encountered: