2015-04-14 21:43:50 +00:00
|
|
|
;;; packages.el --- typescript Layer packages File for Spacemacs
|
|
|
|
;;
|
2021-03-22 20:11:29 +00:00
|
|
|
;; Copyright (c) 2012-2021 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.
|
|
|
|
;;
|
2021-03-24 03:31:44 +00:00
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-04-14 21:43:50 +00:00
|
|
|
|
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
|
2021-03-16 17:47:15 +00:00
|
|
|
yasnippet))
|
|
|
|
|
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
|
2021-03-18 05:06:24 +00:00
|
|
|
(pcase typescript-linter
|
|
|
|
('tslint (flycheck-add-mode 'typescript-tide 'typescript-tsx-mode)
|
|
|
|
(flycheck-add-mode 'typescript-tslint 'typescript-tsx-mode))
|
|
|
|
('eslint (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))
|
|
|
|
(_ (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
|
2021-04-21 15:04:51 +00:00
|
|
|
(with-eval-after-load 'flycheck
|
|
|
|
(pcase 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.
|
|
|
|
('eslint (flycheck-add-mode 'javascript-eslint 'typescript-tsx-mode)
|
|
|
|
(flycheck-add-mode 'javascript-eslint 'typescript-mode))
|
|
|
|
(_ (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)
|
2021-03-18 05:06:24 +00:00
|
|
|
(pcase typescript-backend
|
|
|
|
('tide (typescript/set-tide-linter))
|
|
|
|
('lsp (typescript/set-lsp-linter)))
|
2019-11-11 08:17:31 +00:00
|
|
|
(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 ()
|
2021-03-16 17:47:15 +00:00
|
|
|
(spacemacs/add-to-hooks #'spacemacs//activate-smartparens '(typescript-mode-hook
|
|
|
|
typescript-tsx-mode-hook)))
|
2018-03-31 10:52:00 +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
|
|
|
|
2021-02-23 21:17:44 +00:00
|
|
|
(defun typescript/post-init-web-mode ()
|
|
|
|
(define-derived-mode typescript-tsx-mode web-mode "TypeScript-tsx")
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-tsx-mode))
|
|
|
|
(spacemacs/typescript-mode-init 'typescript-tsx-mode-local-vars-hook)
|
|
|
|
(spacemacs/typescript-mode-config 'typescript-tsx-mode))
|
|
|
|
|
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
|
2021-02-23 21:17:44 +00:00
|
|
|
(spacemacs/typescript-safe-local-variables '(lsp tide))
|
|
|
|
(spacemacs/typescript-mode-init 'typescript-mode-local-vars-hook))
|
|
|
|
:config (spacemacs/typescript-mode-config 'typescript-mode)))
|
2019-04-13 01:59:47 +00:00
|
|
|
|
|
|
|
(defun typescript/pre-init-import-js ()
|
2021-03-18 05:06:24 +00:00
|
|
|
(when (eq javascript-import-tool 'import-js)
|
|
|
|
(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))))
|