Skip to content

Improve typescript-tsx-mode #6172

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

Open
otavioschwanck opened this issue Mar 3, 2022 · 7 comments
Open

Improve typescript-tsx-mode #6172

otavioschwanck opened this issue Mar 3, 2022 · 7 comments
Labels
is:upstream Originates from outside the project and cannot be fully addressed here module:lang/javascript Pertains to Doom's :lang javascript module status:waiting Waiting for a followup or progress elsewhere.

Comments

@otavioschwanck
Copy link
Contributor

Describe your request

Today, the rjsx mode is far superior than typescript-tsx-mode. Typescript is super popular and have a lot of flaws on doom:

Must do:

  • The tag system from rjsx is billion times superior than the typescript-tsx-mode (that is the same of web-mode). The divergence in how to manage tags in the two modes is very bad. compare rjsx and typescript-tsx-mode to see.

  • If you have any snippet on web-mode with the same name on typescript-tsx-mode, you just can use the web-mode snippet.

Good to do:

  • LSP is very slow in typescript for some reason. i compare to neovim with CoC, to show a argument on autocomplete, took less the 0.3s on neovim, in emacs, took 2~5s.

Briefly explain its use-case

Just a javascript and typescript developer

@otavioschwanck otavioschwanck added 1. request needs-triage Issue hasn't been assessed yet labels Mar 3, 2022
@hlissner hlissner added module:lang/javascript Pertains to Doom's :lang javascript module is:upstream Originates from outside the project and cannot be fully addressed here status:waiting Waiting for a followup or progress elsewhere. and removed needs-triage Issue hasn't been assessed yet 1. request labels Mar 31, 2022
@hlissner
Copy link
Member

hlissner commented Mar 31, 2022

Unfortunately, a fix won't come from Doom. You'll need to poke the typescript-mode project for TSX support (see emacs-typescript/typescript.el#4), or rjsx-mode for Typescript support. Doom only uses what's available and web-mode was the only game in town.

tsx-mode.el did recently appear, however. You could try that. It's hacky and over-dependent design makes it less than ideal, but I may end up using it for Doom as a stopgap.

@hlissner hlissner added this to Triage May 9, 2022
@hlissner hlissner moved this to Unreviewed in Triage May 9, 2022
@hlissner hlissner moved this from Unreviewed to Blocked in Triage May 9, 2022
@jacksonludwig
Copy link

Is there any plan to implement tsx-mode.el as an option for js/ts at this point? It's been a while but I think it is still the best option, even though it is not ideal.

Thanks.

@Smona
Copy link

Smona commented Oct 17, 2022

I have been using tsx-mode with doom for several weeks now, and with the exception of auto-formatting with prettier everything has worked fantastically. It's a big improvement over the current typescript-tsx-mode.

Many of the dependencies are for commands that I haven't used and tsx-mode works just fine without them if you don't trigger those commands. Perhaps the module could be included with a limited interface if introducing too many dependencies is the main concern?

@JulienTant
Copy link

JulienTant commented Nov 3, 2022

I have been using tsx-mode with doom for several weeks now, and with the exception of auto-formatting with prettier everything has worked fantastically. It's a big improvement over the current typescript-tsx-mode.

Many of the dependencies are for commands that I haven't used and tsx-mode works just fine without them if you don't trigger those commands. Perhaps the module could be included with a limited interface if introducing too many dependencies is the main concern?

Hey @Smona would you mind sharing how you've set this up? 💙

@Smona
Copy link

Smona commented Nov 3, 2022

@JulienTant sure!

;; In packages.el

;; Set up tsx-mode
(package! tsi :recipe (:host github :repo "orzechowskid/tsi.el" :branch "main"))
(package! coverlay)
(package! origami)
(package! tsx-mode :recipe (:host github :repo "orzechowskid/tsx-mode.el" :branch "master"))
;; In config.el

(use-package! tsx-mode
        :config
        (setq auto-mode-alist (delete '("\\.tsx\\'" . typescript-tsx-mode) auto-mode-alist))
        (add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-mode)))

I am not sure if coverlay and origami are absolutely required; I haven't tested without them. But tsi should be a hard requirement.

I also tried the following to get formatting working, without success. I'm certainly no expert with doom or elisp, so any help getting that working would be much appreciated.

(setq-hook! 'tsx-mode-hook +format-with 'prettier)

@cmetz
Copy link

cmetz commented May 29, 2023

I also tried the following to get formatting working, without success. I'm certainly no expert with doom or elisp, so any help getting that working would be much appreciated.

(setq-hook! 'tsx-mode-hook +format-with 'prettier)

I also was struggling to get this working. using +format-with is broken like mentioned here #6218

i fixed that issue locally so i can use +format-with, maybe I'll create a pull request that will address this. however, you can also do something like this and define your own formatter:

(use-package! tsx-mode
  :config
  (setq auto-mode-alist (delete '("\\.tsx\\'" . typescript-tsx-mode) auto-mode-alist))
  (add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-mode))
  (set-formatter! 'tsx-prettier '("prettier" "--parser" "typescript") :modes '(tsx-mode)))

I'm quite new to the emacs / elisp world, but it seems that doom emacs is using an old format-all-the-code version which is not aware of the tsx-mode and it seems that newer version of that lib now handle language detection differently and not only via major modes.

@dschrempf
Copy link
Contributor

Not sure if this helps, but I think there has been a lot of change with respect to TypeScript support in Emacs. I recommend having a look at https://merrick.luois.me/posts/typescript-in-emacs-29.

tl;dr: Use typescript-ts-mode with built-in tree sitter. Easy to set up and works quite well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:upstream Originates from outside the project and cannot be fully addressed here module:lang/javascript Pertains to Doom's :lang javascript module status:waiting Waiting for a followup or progress elsewhere.
Projects
Status: Blocked
Development

No branches or pull requests

7 participants