2015-04-14 21:43:50 +00:00
|
|
|
;;; packages.el --- typescript Layer packages File for Spacemacs
|
|
|
|
;;
|
2018-01-04 07:00:25 +00:00
|
|
|
;; Copyright (c) 2012-2018 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
|
|
|
tide
|
|
|
|
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
|
|
|
|
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
|
|
|
|
'(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
|
|
|
|
'(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
|
|
|
|
(cond ((eq typescript-linter `tslint)
|
|
|
|
(progn
|
|
|
|
(flycheck-add-mode 'typescript-tide 'typescript-tsx-mode)
|
|
|
|
(flycheck-add-mode 'typescript-tslint 'typescript-tsx-mode)))
|
|
|
|
((eq typescript-linter `eslint)
|
|
|
|
(progn
|
|
|
|
(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))))))
|
|
|
|
|
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)
|
2019-04-26 01:05:13 +00:00
|
|
|
(cond ((eq typescript-backend `tide)
|
|
|
|
(progn (typescript/set-tide-linter)))
|
|
|
|
((eq typescript-backend `lsp)
|
|
|
|
(with-eval-after-load 'lsp-ui
|
|
|
|
(with-eval-after-load 'flycheck
|
|
|
|
(progn
|
|
|
|
(flycheck-add-mode 'javascript-eslint 'typescript-tsx-mode)
|
|
|
|
(flycheck-add-mode 'javascript-eslint 'typescript-mode)
|
|
|
|
(flycheck-add-next-checker 'lsp-ui 'javascript-eslint 'append)
|
|
|
|
))))))
|
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
|
|
|
|
typescript-tsx-mode-hook))
|
|
|
|
(spacemacs/add-to-hooks #'smartparens-mode '(typescript-mode-hook
|
|
|
|
typescript-tsx-mode-hook))))
|
2018-03-31 10:52:00 +00:00
|
|
|
|
2016-01-25 16:19:39 +00:00
|
|
|
(defun typescript/init-tide ()
|
|
|
|
(use-package tide
|
2018-03-04 04:37:53 +00:00
|
|
|
:defer t
|
2016-01-25 16:19:39 +00:00
|
|
|
:commands (typescript/jump-to-type-def)
|
2016-08-13 13:43:37 +00:00
|
|
|
:config
|
|
|
|
(progn
|
2018-03-03 21:44:16 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mE" "errors")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-tsx-mode "mE" "errors")
|
2016-08-13 13:43:37 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mg" "goto")
|
2018-02-18 04:38:41 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-tsx-mode "mg" "goto")
|
2016-08-13 13:43:37 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mh" "help")
|
2018-02-18 04:38:41 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-tsx-mode "mh" "help")
|
2016-08-13 13:43:37 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mn" "name")
|
2018-02-18 04:38:41 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-tsx-mode "mn" "name")
|
2018-03-01 10:00:28 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mr" "refactor")
|
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-tsx-mode "mr" "refactor")
|
2016-08-13 13:43:37 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mS" "server")
|
2018-02-18 04:38:41 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-tsx-mode "mS" "server")
|
2016-08-13 13:43:37 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "ms" "send")
|
2018-02-18 04:38:41 +00:00
|
|
|
(spacemacs/declare-prefix-for-mode 'typescript-tsx-mode "ms" "send")
|
2016-01-25 16:19:39 +00:00
|
|
|
|
2018-03-03 21:44:16 +00:00
|
|
|
(setq keybindingList '("Ee" tide-fix
|
2018-07-03 21:31:31 +00:00
|
|
|
"Ed" tide-add-tslint-disable-next-line
|
2018-03-03 21:44:16 +00:00
|
|
|
"gb" tide-jump-back
|
2018-06-20 03:42:55 +00:00
|
|
|
"gg" tide-jump-to-definition
|
|
|
|
"gt" spacemacs/typescript-jump-to-type-def
|
2016-11-16 19:07:31 +00:00
|
|
|
"gu" tide-references
|
|
|
|
"hh" tide-documentation-at-point
|
2018-10-13 19:15:47 +00:00
|
|
|
"ri" tide-organize-imports
|
2016-11-16 19:07:31 +00:00
|
|
|
"rr" tide-rename-symbol
|
2018-10-13 19:15:47 +00:00
|
|
|
"rf" tide-rename-file
|
2017-07-14 20:47:15 +00:00
|
|
|
"sr" tide-restart-server)
|
2016-11-16 19:07:31 +00:00
|
|
|
typescriptList (cons 'typescript-mode keybindingList)
|
2018-02-18 04:38:41 +00:00
|
|
|
typescriptTsxList (cons 'typescript-tsx-mode
|
|
|
|
(cons "gg" (cons 'tide-jump-to-definition
|
2017-07-14 20:47:15 +00:00
|
|
|
keybindingList ))))
|
2016-11-16 19:07:31 +00:00
|
|
|
(apply 'spacemacs/set-leader-keys-for-major-mode typescriptList)
|
2018-06-17 13:46:41 +00:00
|
|
|
(apply 'spacemacs/set-leader-keys-for-major-mode typescriptTsxList)))
|
|
|
|
|
|
|
|
(add-to-list 'spacemacs-jump-handlers-typescript-tsx-mode
|
|
|
|
'(tide-jump-to-definition :async t))
|
|
|
|
(add-to-list 'spacemacs-jump-handlers-typescript-mode
|
|
|
|
'(tide-jump-to-definition :async t)))
|
2016-01-25 16:19:39 +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
|
|
|
|
"=" 'spacemacs/typescript-format
|
|
|
|
"sp" 'spacemacs/typescript-open-region-in-playground))
|
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
|
|
|
|
typescript-tsx-mode-hook)))
|
|
|
|
|
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))
|
2016-08-13 13:43:37 +00:00
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(when typescript-fmt-on-save
|
2019-03-13 23:55:17 +00:00
|
|
|
(add-hook 'typescript-mode-hook 'spacemacs/typescript-fmt-before-save-hook))
|
2016-08-13 13:43:37 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'typescript-mode
|
2019-04-13 01:59:47 +00:00
|
|
|
"=" 'spacemacs/typescript-format
|
|
|
|
"sp" 'spacemacs/typescript-open-region-in-playground)
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'typescript-tsx-mode
|
2018-02-18 04:38:41 +00:00
|
|
|
"=" 'spacemacs/typescript-format
|
2019-03-13 23:55:17 +00:00
|
|
|
"sp" 'spacemacs/typescript-open-region-in-playground)))))
|
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)))))
|