replaced typescript layer
fixed docs Better docs, added linter and tsx mode fixed typo made TSX optional
This commit is contained in:
parent
2ff22934e7
commit
7a80049fa4
3 changed files with 123 additions and 29 deletions
|
@ -6,42 +6,79 @@
|
||||||
* Table of Contents :TOC_4_org:noexport:
|
* Table of Contents :TOC_4_org:noexport:
|
||||||
- [[Description][Description]]
|
- [[Description][Description]]
|
||||||
- [[Install][Install]]
|
- [[Install][Install]]
|
||||||
- [[Layer][Layer]]
|
- [[Layer][Layer]]
|
||||||
- [[Prerequisites][Prerequisites]]
|
- [[Notes][Notes]]
|
||||||
- [[Key bindings][Key bindings]]
|
- [[Key bindings][Key bindings]]
|
||||||
|
|
||||||
* Description
|
* Description
|
||||||
|
|
||||||
This layer adds support for TypeScript editing via [[https://github.com/clausreinke/typescript-tools][typescript-tools]] and
|
This layer adds support for TypeScript and TSX editing.
|
||||||
[[https://github.com/aki2o/emacs-tss][emacs-tss]].
|
|
||||||
|
|
||||||
This layer provides:
|
This layer provides:
|
||||||
- syntax coloring
|
- ElDoc
|
||||||
- error highlighting
|
- Auto complete
|
||||||
- auto-completion via Flymake
|
- Flycheck
|
||||||
- jump-to-definition
|
- Jump to definition, Jump to type definition
|
||||||
|
- Find occurrences
|
||||||
|
- Rename symbol
|
||||||
|
- Imenu
|
||||||
|
- linting
|
||||||
|
- tsx mode
|
||||||
|
|
||||||
* Install
|
* Install
|
||||||
|
** Pre-requisites
|
||||||
|
You will need =node.js v0.12.0= or greater
|
||||||
|
|
||||||
|
If you want linting run: =npm instell -g typescript= =npm install -g tslint=
|
||||||
|
|
||||||
|
For best results, make sure that the =auto-completion= (company) and =html= layers are enabled.
|
||||||
|
|
||||||
** Layer
|
** Layer
|
||||||
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
|
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
|
||||||
add =typescript= to the existing =dotspacemacs-configuration-layers= list in this
|
add =typescript= to the existing =dotspacemacs-configuration-layers= list in this
|
||||||
file.
|
file.
|
||||||
|
|
||||||
** Prerequisites
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(setq-default dotspacemacs-configuration-layers '(typescript))
|
||||||
You'll need [[https://github.com/clausreinke/typescript-tools][typescript-tools]] and fairly obviously also the TypeScript
|
|
||||||
compiler:
|
|
||||||
|
|
||||||
#+BEGIN_SRC sh
|
|
||||||
$ npm install typescript
|
|
||||||
$ git clone git://github.com/clausreinke/typescript-tools.git
|
|
||||||
$ cd typescript-tools/
|
|
||||||
$ npm install -g
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
or if you don't need linting.
|
||||||
|
|
||||||
|
#+BEGIN_SRC emacs-lisp
|
||||||
|
(setq-default dotspacemacs-configuration-layers '(
|
||||||
|
(typescript :variables
|
||||||
|
typescript-use-tslint nil))
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** Notes
|
||||||
|
|
||||||
|
This layer uses [[https://github.com/ananthakumaran/tide][tide]] and [[https://github.com/Simplify/flycheck-typescript-tslint/][flycheck-typescript-tslint]]
|
||||||
|
|
||||||
|
Make sure to add [[https://github.com/Microsoft/TypeScript/wiki/tsconfig.json][tsconfig.json]] in the project root folder.
|
||||||
|
|
||||||
|
tsserver mangles output sometimes [[https://github.com/Microsoft/TypeScript/issues/2758][issue - #2758]], which will result in json parse error. Try node version 0.12.x if you get this error
|
||||||
|
|
||||||
|
Currently tsserver doesn't pickup tsconfig.json file changes. You might need to restart server after editing it.
|
||||||
|
|
||||||
* Key bindings
|
* Key bindings
|
||||||
|
|
||||||
|
** Typescript Major Mode
|
||||||
|
|
||||||
| Key Binding | Description |
|
| Key Binding | Description |
|
||||||
|-------------+----------------------------------|
|
|-------------+----------------------------------|
|
||||||
| ~SPC m g g~ | Jump to definition |
|
| ~SPC g b~ | jump back |
|
||||||
| ~SPC m h h~ | Show popup help (with type info) |
|
| ~SPC g m~ | jump to entity's type definition |
|
||||||
|
| ~SPC g g~ | jump to entity's definition |
|
||||||
|
| ~SPC h d~ | documentation at point |
|
||||||
|
| ~SPC n r~ | rename symbol |
|
||||||
|
| ~SPC r~ | references |
|
||||||
|
| ~SPC s~ | restart server |
|
||||||
|
|
||||||
|
|
||||||
|
** Reference Major Mode
|
||||||
|
|
||||||
|
| Key Binding | Description |
|
||||||
|
|-------------+----------------------------------|
|
||||||
|
| ~C-j~ | find previous reference |
|
||||||
|
| ~C-k~ | find next reference |
|
||||||
|
| ~C-l~ | goto reference |
|
||||||
|
|
2
layers/+lang/typescript/config.el
Normal file
2
layers/+lang/typescript/config.el
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
(defvar typescript-use-tslint t
|
||||||
|
"Use flycheck linter if not nil")
|
|
@ -9,14 +9,69 @@
|
||||||
;;
|
;;
|
||||||
;;; License: GPLv3
|
;;; License: GPLv3
|
||||||
|
|
||||||
(setq typescript-packages '(tss))
|
(setq typescript-packages '(tide
|
||||||
|
flycheck-typescript-tslint
|
||||||
|
web-mode))
|
||||||
|
|
||||||
(defun typescript/init-tss ()
|
(defun typescript/init-tide ()
|
||||||
"Initialize my package"
|
(use-package tide
|
||||||
(use-package tss
|
|
||||||
:defer t
|
:defer t
|
||||||
:mode ("\\.ts\\'" . typescript-mode)
|
:commands (typescript/jump-to-type-def)
|
||||||
:init (spacemacs/set-leader-keys-for-major-mode 'typescript-mode
|
:init (progn
|
||||||
"gg" 'tss-jump-to-definition
|
(evilified-state-evilify tide-references-mode tide-references-mode-map
|
||||||
"hh" 'tss-popup-help)
|
(kbd "C-j") 'tide-find-previous-reference
|
||||||
:config (tss-config-default)))
|
(kbd "C-k") 'tide-find-next-reference
|
||||||
|
(kbd "C-l") 'tide-goto-reference)
|
||||||
|
|
||||||
|
(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)))))
|
||||||
|
:config (progn
|
||||||
|
|
||||||
|
(when typescript-use-tslint
|
||||||
|
(use-package flycheck-typescript-tslint)
|
||||||
|
(flycheck-add-next-checker 'typescript-tide
|
||||||
|
'typescript-tslint 'append))
|
||||||
|
|
||||||
|
(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")
|
||||||
|
|
||||||
|
(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
|
||||||
|
"gm" 'typescript/jump-to-type-def
|
||||||
|
"gg" 'tide-jump-to-definition
|
||||||
|
"hd" 'tide-documentation-at-point
|
||||||
|
"nr" 'tide-rename-symbol
|
||||||
|
"r" 'tide-references
|
||||||
|
"s" 'tide-restart-server))))
|
||||||
|
|
||||||
|
|
||||||
|
(when (configuration-layer/package-usedp 'web-mode)
|
||||||
|
(defun typescript/init-web-mode ()
|
||||||
|
(use-package web-mode
|
||||||
|
:defer t
|
||||||
|
:mode ("\\.tsx\\'" . web-mode)
|
||||||
|
:config (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))))))))
|
||||||
|
|
||||||
|
(when typescript-use-tslint
|
||||||
|
(defun typescript/init-flycheck-typescript-tslint ()
|
||||||
|
(use-package flycheck-typescript-tslint
|
||||||
|
:defer t)))
|
||||||
|
|
Reference in a new issue