Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
improve typescript tsx support #8387
Conversation
|
Awesome work! I found an issue, it looks like if the first and only file you open is a tsx file the tsserver is not started which causes company-tide to not work. |
|
Do you see any warning or error in the messages buffer? |
|
No, but I think the issue is that the hook to start the server maybe isn't added until after the typescript package is loaded which doesn't happen until the first file is open. So it's not actually tsx that's the problem, it's the first ts or tsx file after starting emacs. |
| +(defun typescript/post-init-rainbow-identifiers () | ||
| + (add-to-list 'rainbow-identifiers-faces-to-override 'web-mode-variable-name-face) | ||
| + (typescript||iterate-modes | ||
| + (add-hook 'hook 'rainbow-identifiers-mode))) |
aaronjensen
Mar 20, 2017
Contributor
| + :post-config | ||
| + (typescript||iterate-modes | ||
| + (flycheck-add-mode 'typescript-tide 'mode) | ||
| + (flycheck-add-mode 'typescript-tslint 'mode) |
aaronjensen
Mar 20, 2017
Contributor
I haven't tested it yet, but this might also run too late to get added to the first file. Is there a reason this got added to tide's post-config hook?
| + "rr" 'tide-rename-symbol | ||
| + "Sr" 'tide-restart-server) | ||
| + | ||
| + (add-hook 'hook 'tide-setup))))) |
aaronjensen
Mar 20, 2017
Contributor
this needs to go back in :init so that the first file opened will start tide.
|
@ksjogo Did you fix the review comments from @aaronjensen ? |
|
@syl20bnr The ordering was improved. Any recommendations on adding the rainbow-identifiers support? Should that be moved to that layer? |
|
@ksjogo The layer still does not work for the first file opened.
To test, restart emacs and open a ts or tsx file. |
|
The pull request did not pick up the latest changes. Just pushed again. |
Sorry, it is still the same result for me. |
|
I am editing tsx? files daily with it so am a bit surprised about that. What's your calculated load order of packages? |
|
The problem is not w/ editing them daily, it is with the very first tsx file that is loaded after emacs is started. Try How do I tell you my calculated load order of packages? My package-selected-packages
|
|
Indeed, but using it often means I often open first files and have flycheck and tide running for these buffers. |
|
Here's some debug info:
The |
|
My modified packages.el so you can see where I put messages: ;;; packages.el --- typescript Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors
;;
;; Author: Chris Bowdon <c.bowdon@bath.edu>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq typescript-packages
'(
company
eldoc
flycheck
rainbow-identifiers
tide
typescript-mode
web-mode
))
(defmacro typescript||iterate-modes (&rest body)
`(progn
,@(loop for mode in (if typescript-use-web-mode-for-ts '(web-typescript-mode) '(typescript-mode web-typescript-mode))
collect (let ((hook (intern (format "%S-hook" mode)))
(jump-handlers (intern (concat "spacemacs-jump-handlers-" (symbol-name mode)))))
`(progn
,@(subst mode 'mode (subst hook 'hook (subst jump-handlers 'jump-handlers body))))))))
(defun typescript/post-init-company ()
(when (configuration-layer/package-usedp 'tide)
(typescript||iterate-modes
(spacemacs|add-company-backends
:backends company-tide
:modes mode))))
(defun typescript/post-init-rainbow-identifiers ()
(when (or (eq colors-colorize-identifiers 'all) (eq colors-colorize-identifiers 'variables))
(add-to-list 'rainbow-identifiers-faces-to-override 'web-mode-variable-name-face)
(typescript||iterate-modes
(add-hook 'hook 'rainbow-identifiers-mode))))
(defun typescript/post-init-eldoc ()
(typescript||iterate-modes
(add-hook 'hook 'eldoc-mode)))
(defun typescript/post-init-flycheck ()
(message "XXX typescript/post-init-flycheck")
(spacemacs|use-package-add-hook tide
:post-config
(message "XXX ADDING FLYCHECK HOOKS")
(typescript||iterate-modes
(flycheck-add-mode 'typescript-tide 'mode)
(flycheck-add-mode 'typescript-tslint 'mode)
(spacemacs/enable-flycheck 'mode))))
(with-eval-after-load 'tide
(message "XXX LOADED tide"))
(with-eval-after-load 'flycheck
(message "XXX LOADED flycheck"))
(with-eval-after-load 'web-mode
(message "XXX LOADED web-mode"))
(defun typescript/init-tide ()
(use-package tide
:defer t
:commands (typescript/jump-to-type-def)
:init
(progn
(evilified-state-evilify tide-references-mode tide-references-mode-map
(kbd "C-k") 'tide-find-previous-reference
(kbd "C-j") 'tide-find-next-reference
(kbd "C-l") 'tide-goto-reference))
:config
(message "XXX typescript/init-tide CONFIG")
(progn
(defun typescript/jump-to-type-def()
(interactive)
(tide-jump-to-definition t))
(typescript||iterate-modes
(spacemacs/declare-prefix-for-mode 'mode "mg" "goto")
(spacemacs/declare-prefix-for-mode 'mode "mh" "help")
(spacemacs/declare-prefix-for-mode 'mode "mn" "name")
(spacemacs/declare-prefix-for-mode 'mode "mr" "rename")
(spacemacs/declare-prefix-for-mode 'mode "mS" "server")
(spacemacs/declare-prefix-for-mode 'mode "ms" "send")
(spacemacs/set-leader-keys-for-major-mode 'mode
"gb" 'tide-jump-back
"gt" 'typescript/jump-to-type-def
"gu" 'tide-references
"hh" 'tide-documentation-at-point
"rr" 'tide-rename-symbol
"Sr" 'tide-restart-server)
(message "XXX ADDING TIDE HOOK")
(add-hook 'hook 'tide-setup)))))
(defun typescript/post-init-tide ()
(message "XXX typescript/post-init-tide")
(setf (flycheck-checker-get 'typescript-tide 'modes) '(typescript-mode web-typescript-mode))
(typescript||iterate-modes
(spacemacs|define-jump-handlers mode)
(add-to-list 'jump-handlers 'tide-jump-to-definition)))
(defun typescript--prettify-symbols ()
(push '("function" . ?λ) prettify-symbols-alist)
(push '("React.createElement" . ?Ʀ) prettify-symbols-alist)
(push '("return" . ?⏎) prettify-symbols-alist)
(push '("async." . ?Թ) prettify-symbols-alist)
(push '("this.props.store." . ?Σ) prettify-symbols-alist)
(prettify-symbols-mode))
;; we need to (re)use the init-web-mode here as our mode needs to be defined before the misc post-init functions
(defun typescript/init-web-mode ()
(define-derived-mode web-typescript-mode web-mode "web-typescript")
(typescript||iterate-modes
(add-hook 'hook 'typescript--prettify-symbols)
(add-hook 'hook (lambda () (yas-minor-mode -1)))
(when typescript-fmt-on-save
(add-hook 'hook 'typescript/fmt-before-save-hook))
(spacemacs/set-leader-keys-for-major-mode 'mode
"=" 'typescript/format
"sp" 'typescript/open-region-in-playground)))
(defun typescript/post-init-web-mode ()
(when typescript-use-web-mode-for-ts
(add-to-list 'auto-mode-alist '("\\.ts\\'" . web-typescript-mode)))
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-typescript-mode)))
(defun typescript/init-typescript-mode ()
(use-package typescript-mode
:defer t)) |
| +(defun typescript/init-web-mode () | ||
| + (define-derived-mode web-typescript-mode web-mode "web-typescript") | ||
| + (typescript||iterate-modes | ||
| + (add-hook 'hook 'typescript--prettify-symbols) |
aaronjensen
May 18, 2017
Contributor
Please add a configuration variable for this, it's likely to be divisive.
|
I'm looking to make some improvements to the typescript layer as well. I'm not sure how I should proceed since this looks to have been abandoned. Should I make my own fork with the changes above and attempt the fixes that aaronjensen suggested? I'm not super familiar with github procedure... |
|
@Kethku Added you to my repo. Feel free to add commits to the develop branch, they should show up here automatically. |
|
Awesome. I will take a look at this sometime this week |
ksjogo commentedFeb 16, 2017
No description provided.