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
|
2016-10-04 12:39:30 +00:00
|
|
|
flycheck
|
2018-06-02 22:11:47 +00:00
|
|
|
lsp-javascript-typescript
|
2018-03-31 10:52:00 +00:00
|
|
|
smartparens
|
2016-05-30 02:39:21 +00:00
|
|
|
tide
|
|
|
|
typescript-mode
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
(with-eval-after-load 'tide
|
2018-06-11 06:07:23 +00:00
|
|
|
(with-eval-after-load 'flycheck
|
|
|
|
(flycheck-add-mode 'typescript-tide 'typescript-tsx-mode)
|
|
|
|
(flycheck-add-mode 'typescript-tslint 'typescript-tsx-mode))))
|
2016-10-04 12:39:30 +00:00
|
|
|
|
2018-06-02 22:11:47 +00:00
|
|
|
(defun typescript/post-init-lsp-javascript-typescript ()
|
2018-06-17 13:46:41 +00:00
|
|
|
(when (eq typescript-backend 'lsp)
|
|
|
|
(spacemacs//setup-lsp-jump-handler 'typescript-mode
|
|
|
|
'typescript-tsx-mode)))
|
2018-06-11 04:28:11 +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
|
|
|
|
(add-to-list 'spacemacs-jump-handlers '(tide-jump-to-definition :async t))
|
|
|
|
'(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")
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-tsx-mode)))
|
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
|
|
|
|
(spacemacs/add-to-hooks #'spacemacs//typescript-setup-backend
|
|
|
|
'(typescript-mode-local-vars-hook
|
|
|
|
typescript-tsx-mode-local-vars-hook))
|
|
|
|
;; safe values for backend to be used in directory file variables
|
|
|
|
(dolist (value '(lsp tide))
|
|
|
|
(add-to-list 'safe-local-variable-values
|
|
|
|
(cons 'typescript-backend value))))
|
2016-08-13 13:43:37 +00:00
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(when typescript-fmt-on-save
|
2018-05-12 04:19:59 +00:00
|
|
|
(spacemacs/add-to-hooks 'spacemacs/typescript-fmt-before-save-hook
|
|
|
|
'(typescript-mode-hook typescript-tsx-mode-hook)))
|
2016-08-13 13:43:37 +00:00
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'typescript-mode
|
2018-02-18 04:38:41 +00:00
|
|
|
"=" 'spacemacs/typescript-format
|
|
|
|
"sp" 'spacemacs/typescript-open-region-in-playground)
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'typescript-tsx-mode
|
2017-07-14 20:50:34 +00:00
|
|
|
"=" 'spacemacs/typescript-format
|
|
|
|
"sp" 'spacemacs/typescript-open-region-in-playground))))
|