2015-04-14 21:43:50 +00:00
|
|
|
;;; packages.el --- typescript Layer packages File for Spacemacs
|
|
|
|
;;
|
2020-09-16 21:34:40 +00:00
|
|
|
;; Copyright (c) 2012-2020 Sylvain Benner & Contributors
|
2015-04-14 21:43:50 +00:00
|
|
|
;;
|
|
|
|
;; Author: Chris Bowdon <c.bowdon@bath.edu>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2016-05-30 02:39:21 +00:00
|
|
|
(setq typescript-packages
|
|
|
|
'(
|
2017-03-31 23:38:43 +00:00
|
|
|
add-node-modules-path
|
2016-10-04 12:39:30 +00:00
|
|
|
company
|
2018-03-03 21:53:42 +00:00
|
|
|
eldoc
|
2019-05-11 02:35:19 +00:00
|
|
|
emmet-mode
|
2016-10-04 12:39:30 +00:00
|
|
|
flycheck
|
2018-03-31 10:52:00 +00:00
|
|
|
smartparens
|
2016-05-30 02:39:21 +00:00
|
|
|
typescript-mode
|
2019-04-13 01:59:47 +00:00
|
|
|
import-js
|
2016-05-30 02:39:21 +00:00
|
|
|
web-mode
|
2018-06-02 00:34:48 +00:00
|
|
|
yasnippet
|
2016-05-30 02:39:21 +00:00
|
|
|
))
|
2015-04-14 21:43:50 +00:00
|
|
|
|
2017-03-31 23:38:43 +00:00
|
|
|
(defun typescript/post-init-add-node-modules-path ()
|
2018-05-12 04:19:59 +00:00
|
|
|
(spacemacs/add-to-hooks #'add-node-modules-path '(typescript-mode-hook
|
2019-11-14 23:20:44 +00:00
|
|
|
typescript-tsx-mode-hook)))
|
2017-03-31 23:38:43 +00:00
|
|
|
|
2016-10-04 12:39:30 +00:00
|
|
|
(defun typescript/post-init-company ()
|
2018-05-12 06:33:10 +00:00
|
|
|
(spacemacs/add-to-hooks #'spacemacs//typescript-setup-company
|
2019-11-14 23:20:44 +00:00
|
|
|
'(typescript-mode-local-vars-hook
|
|
|
|
typescript-tsx-mode-local-vars-hook)))
|
2016-10-04 12:39:30 +00:00
|
|
|
|
2018-05-12 06:46:51 +00:00
|
|
|
(defun typescript/post-init-eldoc ()
|
|
|
|
(spacemacs/add-to-hooks #'spacemacs//typescript-setup-eldoc
|
2019-11-14 23:20:44 +00:00
|
|
|
'(typescript-mode-local-vars-hook
|
|
|
|
typescript-tsx-mode-local-vars-hook) t))
|
2018-03-03 21:53:42 +00:00
|
|
|
|
2019-05-11 02:35:19 +00:00
|
|
|
(defun typescript/post-init-emmet-mode ()
|
|
|
|
(add-hook 'typescript-tsx-mode-hook #'spacemacs/typescript-emmet-mode))
|
|
|
|
|
2019-04-26 01:05:13 +00:00
|
|
|
(defun typescript/set-tide-linter ()
|
|
|
|
(with-eval-after-load 'tide
|
|
|
|
(with-eval-after-load 'flycheck
|
2020-07-25 13:19:13 +00:00
|
|
|
(cond ((eq typescript-linter 'tslint)
|
2019-11-14 23:20:44 +00:00
|
|
|
(flycheck-add-mode 'typescript-tide 'typescript-tsx-mode)
|
|
|
|
(flycheck-add-mode 'typescript-tslint 'typescript-tsx-mode))
|
2020-07-25 13:19:13 +00:00
|
|
|
((eq typescript-linter 'eslint)
|
2019-11-14 23:20:44 +00:00
|
|
|
(flycheck-add-mode 'javascript-eslint 'typescript-tsx-mode)
|
|
|
|
(flycheck-add-mode 'javascript-eslint 'typescript-mode)
|
|
|
|
(add-to-list 'flycheck-disabled-checkers 'typescript-tslint)
|
|
|
|
(flycheck-disable-checker 'typescript-tslint)
|
|
|
|
(flycheck-add-mode 'tsx-tide 'typescript-tsx-mode)
|
|
|
|
(flycheck-add-next-checker 'typescript-tide 'javascript-eslint 'append)
|
|
|
|
(flycheck-add-next-checker 'tsx-tide 'javascript-eslint 'append))
|
|
|
|
(t
|
|
|
|
(message
|
|
|
|
"Invalid typescript-layer configuration, no such linter: %s" typescript-linter))))))
|
2019-04-26 01:05:13 +00:00
|
|
|
|
2019-11-11 08:17:31 +00:00
|
|
|
(defun typescript/set-lsp-linter ()
|
|
|
|
(with-eval-after-load 'lsp-ui
|
2020-08-26 22:02:37 +00:00
|
|
|
(with-eval-after-load 'lsp
|
|
|
|
(with-eval-after-load 'flycheck
|
|
|
|
(cond ((eq typescript-linter 'tslint)
|
|
|
|
(flycheck-add-mode 'typescript-tslint 'typescript-tsx-mode))
|
|
|
|
;; This sets tslint unconditionally for all lsp clients which is wrong
|
|
|
|
;; Must be set for respective modes only, see go layer for examples.
|
|
|
|
((eq typescript-linter 'eslint)
|
|
|
|
(flycheck-add-mode 'javascript-eslint 'typescript-tsx-mode)
|
|
|
|
(flycheck-add-mode 'javascript-eslint 'typescript-mode))
|
|
|
|
(t
|
|
|
|
(message
|
|
|
|
"Invalid typescript-layer configuration, no such linter: %s" typescript-linter)))))))
|
2019-11-11 08:17:31 +00:00
|
|
|
|
2016-10-04 12:39:30 +00:00
|
|
|
(defun typescript/post-init-flycheck ()
|
2017-07-14 20:47:15 +00:00
|
|
|
(spacemacs/enable-flycheck 'typescript-mode)
|
2018-02-18 04:38:41 +00:00
|
|
|
(spacemacs/enable-flycheck 'typescript-tsx-mode)
|
2020-07-25 13:19:13 +00:00
|
|
|
(cond ((eq (spacemacs//typescript-backend) 'tide)
|
2019-11-14 23:20:44 +00:00
|
|
|
(typescript/set-tide-linter))
|
2020-07-25 13:19:13 +00:00
|
|
|
((eq (spacemacs//typescript-backend) 'lsp)
|
2019-11-11 08:17:31 +00:00
|
|
|
(typescript/set-lsp-linter)))
|
|
|
|
|
|
|
|
(spacemacs/add-to-hooks #'spacemacs//typescript-setup-checkers
|
|
|
|
'(typescript-mode-hook typescript-tsx-mode-hook)
|
|
|
|
t))
|
2016-10-04 12:39:30 +00:00
|
|
|
|
2018-03-31 10:52:00 +00:00
|
|
|
(defun typescript/post-init-smartparens ()
|
|
|
|
(if dotspacemacs-smartparens-strict-mode
|
2018-05-12 04:19:59 +00:00
|
|
|
(spacemacs/add-to-hooks #'smartparens-strict-mode '(typescript-mode-hook
|
2019-11-14 23:20:44 +00:00
|
|
|
typescript-tsx-mode-hook))
|
2018-05-12 04:19:59 +00:00
|
|
|
(spacemacs/add-to-hooks #'smartparens-mode '(typescript-mode-hook
|
2019-11-14 23:20:44 +00:00
|
|
|
typescript-tsx-mode-hook))))
|
2018-03-31 10:52:00 +00:00
|
|
|
|
2016-05-30 02:39:21 +00:00
|
|
|
(defun typescript/post-init-web-mode ()
|
2018-02-18 04:38:41 +00:00
|
|
|
(define-derived-mode typescript-tsx-mode web-mode "TypeScript-tsx")
|
2019-03-13 23:55:17 +00:00
|
|
|
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-tsx-mode))
|
|
|
|
|
|
|
|
;; setup typescript backend
|
|
|
|
(add-hook 'typescript-tsx-mode-local-vars-hook 'spacemacs//typescript-setup-backend)
|
|
|
|
(spacemacs/typescript-safe-local-variables '(lsp tide))
|
|
|
|
(when typescript-fmt-on-save
|
|
|
|
(add-hook 'typescript-tsx-mode-hook 'spacemacs/typescript-fmt-before-save-hook))
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'typescript-tsx-mode
|
2020-10-17 08:17:41 +00:00
|
|
|
"p" 'spacemacs/typescript-open-region-in-playground)
|
|
|
|
(pcase (spacemacs//typescript-backend)
|
|
|
|
('lsp (spacemacs/set-leader-keys-for-major-mode 'typescript-mode
|
|
|
|
"==" 'spacemacs/typescript-format))
|
|
|
|
(_ (spacemacs/set-leader-keys-for-major-mode 'typescript-mode
|
|
|
|
"=" 'spacemacs/typescript-format))))
|
2016-01-25 16:19:39 +00:00
|
|
|
|
2018-06-02 00:34:48 +00:00
|
|
|
(defun typescript/post-init-yasnippet ()
|
|
|
|
(spacemacs/add-to-hooks #'spacemacs/typescript-yasnippet-setup '(typescript-mode-hook
|
2019-11-14 23:20:44 +00:00
|
|
|
typescript-tsx-mode-hook)))
|
2018-06-02 00:34:48 +00:00
|
|
|
|
2016-02-02 22:49:37 +00:00
|
|
|
(defun typescript/init-typescript-mode ()
|
|
|
|
(use-package typescript-mode
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2018-04-27 04:51:30 +00:00
|
|
|
:init
|
2018-05-13 06:14:09 +00:00
|
|
|
(progn
|
|
|
|
;; setup typescript backend
|
2019-03-13 23:55:17 +00:00
|
|
|
(add-hook 'typescript-mode-local-vars-hook 'spacemacs//typescript-setup-backend)
|
|
|
|
(spacemacs/typescript-safe-local-variables '(lsp tide))
|
2019-11-14 23:20:44 +00:00
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(when typescript-fmt-on-save
|
|
|
|
(add-hook 'typescript-mode-hook 'spacemacs/typescript-fmt-before-save-hook))
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'typescript-mode
|
2020-10-17 08:17:41 +00:00
|
|
|
"p" 'spacemacs/typescript-open-region-in-playground)
|
|
|
|
(pcase (spacemacs//typescript-backend)
|
|
|
|
('lsp (spacemacs/set-leader-keys-for-major-mode 'typescript-mode
|
|
|
|
"==" 'spacemacs/typescript-format))
|
|
|
|
(_ (spacemacs/set-leader-keys-for-major-mode 'typescript-mode
|
|
|
|
"=" 'spacemacs/typescript-format)))))))
|
2019-04-13 01:59:47 +00:00
|
|
|
|
|
|
|
(defun typescript/pre-init-import-js ()
|
|
|
|
(if (eq javascript-import-tool 'import-js)
|
|
|
|
(progn
|
|
|
|
(add-to-list 'spacemacs--import-js-modes (cons 'typescript-mode 'typescript-mode-hook))
|
|
|
|
(add-to-list 'spacemacs--import-js-modes (cons 'typescript-tsx-mode 'typescript-tsx-mode-hook)))))
|