928983da47
This commit defines: - spacemacs-default-jump-handlers: a list of functions that can jump to definition in ALL modes. - spacemacs-jump-handlers-MODE: a list of functions that can jump to definition in MODE. - spacemacs-jump-handlers: a buffer-local list of functions that can jump to definition. This is made up of the values of the two previous variables whenever a given major mode is activated. - spacemacs/jump-to-definition: a function that tries each function in spacemacs-jump-handlers in order, and stops when one of them takes us somewhere new. - spacemacs|define-jump-handlers: a macro that * defines spacemacs-jump-handlers-MODE, possibly filled with initial functions * defines a function that is added to the hook of the given MODE * binds “SPC m g g” of that MODE to spacemacs/jump-to-definition This is an attempt to harmonize all the different approaches to jumping. Specifically, - Existing intelligent jump packages that work for only a single mode should go to the beginning of spacemacs-jump-handlers-MODE. E.g. anaconda for python, ensime for scala, etc. - Packages like gtags that work for several modes (but potentially not all) and which is dumber than the intelligent jumpers should go the the END of spacemacs-jump-handlers-MODE. - Packages like dumb-jump that work for all modes should go to spacemacs-default-jump-handlers. In all cases the order of the jump handlers in each list should be from most to least intelligent. Fixes #6619
87 lines
3 KiB
EmacsLisp
87 lines
3 KiB
EmacsLisp
;;; packages.el --- typescript Layer packages File for Spacemacs
|
|
;;
|
|
;; Copyright (c) 2012-2016 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
|
|
'(
|
|
tide
|
|
typescript-mode
|
|
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)
|
|
|
|
;; FIXME -- this is not good!
|
|
(add-hook 'typescript-mode-hook
|
|
(lambda ()
|
|
(tide-setup)
|
|
(flycheck-mode t)
|
|
(setq flycheck-check-syntax-automatically '(save mode-enabled))
|
|
(eldoc-mode t)
|
|
(when (configuration-layer/package-usedp 'company)
|
|
(company-mode-on))))
|
|
|
|
(add-hook 'spacemacs-jump-handlers-typescript-mode 'tide-jump-to-definition))
|
|
:config
|
|
(progn
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mg" "goto")
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mh" "help")
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mn" "name")
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mr" "rename")
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "mS" "server")
|
|
(spacemacs/declare-prefix-for-mode 'typescript-mode "ms" "send")
|
|
|
|
(defun typescript/jump-to-type-def()
|
|
(interactive)
|
|
(tide-jump-to-definition t))
|
|
|
|
(spacemacs/set-leader-keys-for-major-mode 'typescript-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))))
|
|
|
|
(defun typescript/post-init-web-mode ()
|
|
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
|
|
;; FIXME -- this is not good!
|
|
(add-hook 'web-mode-hook
|
|
(lambda ()
|
|
(when (string-equal "tsx" (file-name-extension buffer-file-name))
|
|
(tide-setup)
|
|
(flycheck-mode +1)
|
|
(setq flycheck-check-syntax-automatically '(save mode-enabled))
|
|
(eldoc-mode +1)
|
|
(when (configuration-layer/package-usedp 'company)
|
|
(company-mode-on))))))
|
|
|
|
(defun typescript/init-typescript-mode ()
|
|
(use-package typescript-mode
|
|
:defer t
|
|
:init
|
|
(spacemacs|define-jump-handlers typescript-mode)
|
|
:config
|
|
(progn
|
|
(when typescript-fmt-on-save
|
|
(add-hook 'typescript-mode-hook 'typescript/fmt-before-save-hook))
|
|
(spacemacs/set-leader-keys-for-major-mode 'typescript-mode
|
|
"=" 'typescript/format
|
|
"sp" 'typescript/open-region-in-playground))))
|