add typescript fmt
fixed typo reordered packages made formatting off by the default fixed docs fixed docs... Again fixed docs... Like 3-d time fixed docs... Did I? I CAN DO IT! hooked named function instead of lambda
This commit is contained in:
parent
4227404c29
commit
8628e45fd3
|
@ -27,12 +27,15 @@ This layer provides:
|
|||
- Imenu
|
||||
- linting
|
||||
- tsx mode
|
||||
- formatting
|
||||
|
||||
* 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=
|
||||
If you want linting run: =npm install -g typescript= =npm install -g tslint=
|
||||
|
||||
If you want formatting run: =npm install -g typescript-formatter=
|
||||
|
||||
For best results, make sure that the =auto-completion= (company) and =html= layers are enabled.
|
||||
|
||||
|
@ -45,17 +48,32 @@ file.
|
|||
(setq-default dotspacemacs-configuration-layers '(typescript))
|
||||
#+END_SRC
|
||||
|
||||
or if you don't need linting.
|
||||
If you don't need linting, you can use:
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(setq-default dotspacemacs-configuration-layers '(
|
||||
(typescript :variables
|
||||
typescript-use-tslint nil))
|
||||
(typescript :variables
|
||||
typescript-use-tslint nil)))
|
||||
|
||||
#+END_SRC
|
||||
|
||||
If you need formatting on save:
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(setq-default dotspacemacs-configuration-layers '(
|
||||
(typescript :variables
|
||||
typescript-fmt-on-save t)))
|
||||
|
||||
#+END_SRC
|
||||
|
||||
** Notes
|
||||
|
||||
This layer uses [[https://github.com/ananthakumaran/tide][tide]] and [[https://github.com/Simplify/flycheck-typescript-tslint/][flycheck-typescript-tslint]]
|
||||
This layer uses:
|
||||
- [[https://github.com/ananthakumaran/tide][tide]]
|
||||
- [[https://github.com/Simplify/flycheck-typescript-tslint][flycheck-typescript-tslint]]
|
||||
- [[https://github.com/vvakame/typescript-formatter][typescript-formatter]]
|
||||
|
||||
*Those tools use configuration files. You can learn more in their documentations.*
|
||||
|
||||
Make sure to add [[https://github.com/Microsoft/TypeScript/wiki/tsconfig.json][tsconfig.json]] in the project root folder.
|
||||
|
||||
|
@ -69,19 +87,20 @@ Currently tsserver doesn't pickup tsconfig.json file changes. You might need to
|
|||
|
||||
| Key Binding | Description |
|
||||
|-------------+----------------------------------|
|
||||
| ~SPC g b~ | jump back |
|
||||
| ~SPC g g~ | jump to entity's definition |
|
||||
| ~SPC g t~ | jump to entity's type definition |
|
||||
| ~SPC g u~ | references |
|
||||
| ~SPC h h~ | documentation at point |
|
||||
| ~SPC r r~ | rename symbol |
|
||||
| ~SPC s r~ | restart server |
|
||||
| ~SPC m =~ | Reformat the buffer |
|
||||
| ~SPC m g b~ | jump back |
|
||||
| ~SPC m g g~ | jump to entity's definition |
|
||||
| ~SPC m g t~ | jump to entity's type definition |
|
||||
| ~SPC m g u~ | references |
|
||||
| ~SPC m h h~ | documentation at point |
|
||||
| ~SPC m r r~ | rename symbol |
|
||||
| ~SPC m s r~ | restart server |
|
||||
|
||||
|
||||
** Reference Major Mode
|
||||
|
||||
| Key Binding | Description |
|
||||
|-------------+----------------------------------|
|
||||
| ~C-j~ | find previous reference |
|
||||
| ~C-k~ | find next reference |
|
||||
| ~C-l~ | goto reference |
|
||||
| Key Binding | Description |
|
||||
|-------------+-------------------------|
|
||||
| ~C-j~ | find previous reference |
|
||||
| ~C-k~ | find next reference |
|
||||
| ~C-l~ | goto reference |
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
(defvar typescript-use-tslint t
|
||||
"Use flycheck linter if not nil")
|
||||
"Use flycheck linter if not nil.")
|
||||
|
||||
(defvar typescript-fmt-on-save nil
|
||||
"Run formatter on buffer save.")
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
;;
|
||||
;;; License: GPLv3
|
||||
|
||||
(setq typescript-packages '(tide
|
||||
flycheck-typescript-tslint
|
||||
(setq typescript-packages '(flycheck-typescript-tslint
|
||||
tide
|
||||
typescript-mode
|
||||
web-mode))
|
||||
|
||||
(defun typescript/init-tide ()
|
||||
|
@ -71,6 +72,48 @@
|
|||
(when (configuration-layer/package-usedp 'company)
|
||||
(company-mode-on))))))))
|
||||
|
||||
(defun typescript/init-typescript-mode ()
|
||||
(use-package typescript-mode
|
||||
:defer t
|
||||
:commands (typescript/format-buffer)
|
||||
:config (progn
|
||||
(defun typescript/format-buffer ()
|
||||
"Format buffer with tsfmt."
|
||||
(interactive)
|
||||
(if (executable-find "tsfmt")
|
||||
(let* ((tmpfile (make-temp-file "~fmt-tmp" nil ".ts"))
|
||||
(coding-system-for-read 'utf-8)
|
||||
(coding-system-for-write 'utf-8)
|
||||
(outputbuf (get-buffer-create "*~fmt-tmp.ts*")))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(with-current-buffer outputbuf (erase-buffer))
|
||||
(write-region nil nil tmpfile)
|
||||
(if (zerop (apply 'call-process "tsfmt" nil outputbuf nil (list tmpfile)))
|
||||
(let ((p (point)))
|
||||
(save-excursion
|
||||
(with-current-buffer (current-buffer)
|
||||
(erase-buffer)
|
||||
(insert-buffer-substring outputbuf)))
|
||||
(goto-char p)
|
||||
(message "formatted.")
|
||||
(kill-buffer outputbuf))
|
||||
(progn
|
||||
(message "Formatting failed!")
|
||||
(display-buffer outputbuf)))
|
||||
(progn
|
||||
(delete-file tmpfile)))))
|
||||
(message "tsfmt not found. Run \"npm install -g typescript-formatter\"")))
|
||||
|
||||
(spacemacs/set-leader-keys-for-major-mode 'typescript-mode "=" 'typescript/format-buffer)
|
||||
|
||||
(when typescript-fmt-on-save
|
||||
|
||||
(defun typescript/before-save-hook ()
|
||||
(add-hook 'before-save-hook 'typescript/format-buffer t t))
|
||||
|
||||
(add-hook 'typescript-mode-hook 'typescript/before-save-hook)))))
|
||||
|
||||
(when typescript-use-tslint
|
||||
(defun typescript/init-flycheck-typescript-tslint ()
|
||||
(use-package flycheck-typescript-tslint
|
||||
|
|
Loading…
Reference in a new issue