-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Typescript tsx improvements #15895
Typescript tsx improvements #15895
Conversation
@lebensterben - Changes made. Thanks for the quick feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Please wait on merging this. I am experiencing some strange effects of the tree-sitter tsx highlighting. |
Default is nil, to leave existing behavior unchanged.
Ok. I threw the new tree-sitter related behind an opt-in feature flag / custom variable, so I now consider this safe to merge. Users can enable/disable tree-sitter tsx highlighting as they wish. |
additional note:
|
the question is, should we add an extra layer config variable to toggle tree-sitter highlight? or can we teach user to modify the two aforementioned variables? |
My feeling is that this using tree-sitter for tsx should be opt-in rather than opt-out. For 2 reasons:
In spacemacs, we inherit our And after thinking about this some more, the potential behavior issues of the tree-sitter highlighting and the workarounds are only needed because we are deriving our tsx mode from web-mode, when deriving it from typescript mode may yield much better results. My initial test is working well enough, and perhaps adding back some web mode nice-to-haves like emmet and such to a typescript-mode derived tsx-mode would solve all of these issues at once. |
See https://github.com/emacs-typescript/typescript.el/blob/master/README.md#good-news-though It seems that we may not need |
Actually this line tells Emacs to open I've never developed in TSX so I don't know what are the goodies from web-mode that we will want to keep for TSX. |
That is great news. Thanks for the research. But then, I read this in the official tree-sitter typescript definition repo, which leads me to think that we really should be using different modes, or at least this is important if we want to use tree-sitter:
|
Ok! After researching this a bunch more, I wan't to proceed with the following plan: We have excellent new modes that are included with emacs 29. I want to update this mode to simply use these packages if they are available. I am using emacs-29 anyway, so this is certainly the best solution for me. Questions on best implementation:
Thank again for your time with this. |
I think using an option like this would be best: (defvar typescript-use-treesitter-modes nil
"Use the emacs-29 provided typescript-ts-mode and tsx-ts-mode rather then typescript-mode. Setting this option to non-nil requires emacs-29.") Let me know what you think. |
since the unofficial typescript-mode has hit a halt: https://github.com/emacs-typescript/typescript.el#a-short-note-on-development-halt we eventually need to step away from it. but that cannot be done before For the time being, we can use
Otherwise, we simply use the major-modes of TS or TSX provided by Emacs. And they will have native support for tree-sitter highlighting. (see https://github.com/emacs-mirror/emacs/blob/d0d34514097c03d787012478d5217449481cfc04/lisp/progmodes/typescript-ts-mode.el#L360-L361 and https://github.com/emacs-mirror/emacs/blob/d0d34514097c03d787012478d5217449481cfc04/lisp/progmodes/typescript-ts-mode.el#L384-L385). As for discrepancies in symbol names, we can also use the same version checks. This is the most straightforward way. |
Ok. Thanks. I'll proceed with using just the version check and no defvar to specify. |
@lebensterben - After looking into this issue a bunch more, I'm concluding that this work is just too early to get this into spacemacs, and should be added whenever spacemacs approaches full emacs 29 support. Spacemacs should support automatic bootstrapping of tree-sitter language grammars, if it is going to use the new emacs29 language modes that leverage tree-sitter. This project and issue is looking to support this eventually, and I would think should be used in spacemacs eventually to DL tree-sitter language grammars: emacs-tree-sitter/tree-sitter-langs#144. In the meantime, I opened up #15920, with the non tree-sitter related improvements in this PR. |
A few improvements for typescript-tsx mode.