add jdelStrother's flow-type layer with some changes

This commit is contained in:
Mike Holm 2018-03-21 13:08:52 -06:00 committed by Maximilian Wolff
parent 153990bbc8
commit 06c321d4ac
No known key found for this signature in database
GPG key ID: 2DD07025BFDBD89A
5 changed files with 144 additions and 0 deletions

View file

@ -0,0 +1,33 @@
#+TITLE: flow-type layer
* Description
This layer adds some [[https://flowtype.org/][flow]] related functionality to Emacs:
- Show the flow-type of the object under the cursor using Eldoc
- Add flow checking to flycheck (based on the flycheck-flow package)
- company-mode completion using company-flow
- "compilation" using =flow status=
* Install
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =flow-type= to the existing =dotspacemacs-configuration-layers= list in this
file. Please ensure you already have the flow binary installed, either in
node_modules or in your PATH.
The type under the cursor is shown automatically using eldoc. You may find this
a little sluggish, depending on your setup - if so, you can disable it by setting
=flow-type-enable-eldoc-type-info= to =nil=.
#+BEGIN_SRC emacs-lisp
(flow-type :variables flow-type-enable-eldoc-type-info nil)
#+END_SRC
You can always show types manually using =flow-minor-type-at-pos=,
bound to =,ft= by default.
* flow-minor-mode key bindings
| ,fb | xref-pop-marker-stack | jump back from definition |
| ,fc | flow-minor-status | run `flow status' as a compiler |
| ,fd | flow-minor-jump-to-definition | jump to the definition of the variable under the cursor |
| ,ff | flow-minor-suggest | |
| ,fo | flow-minor-coverage | print coverage information |
| ,ft | flow-minor-type-at-pos | print the type under the cursor to the message line |

View file

@ -0,0 +1,14 @@
;;; config.el --- flow-type layer configuration file for Spacemacs.
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Mike Holm <coldpour@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defvar flow-type-enable-eldoc-type-info t
"When t, automatically display the type under the cursor using eldoc.
When nil, types can be displayed manually with `flow-minor-type-at-pos'.")

View file

@ -0,0 +1,13 @@
;;; funcs.el --- flow-type layer functions file for Spacemacs.
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Mike Holm <coldpour@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defun flow-type-eldoc-hook ()
(set (make-local-variable 'eldoc-documentation-function) 'flow-minor-get-type-at-pos))

View file

@ -0,0 +1,12 @@
;;; layers.el --- flow-type Layer layers File for Spacemacs
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Holm <holmi09@holmi09mac132>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(configuration-layer/declare-layers '(node))

View file

@ -0,0 +1,72 @@
;;; packages.el --- flow-type layer packages file for Spacemacs.
;;
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
;;
;; Author: Mike Holm <coldpour@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defconst flow-type-packages
'(
flow-minor-mode
company
(company-flow :toggle (configuration-layer/package-usedp 'company))
(flycheck-flow :toggle (configuration-layer/package-usedp 'flycheck))
eldoc
))
(defun flow-type/init-flow-minor-mode()
(use-package flow-minor-mode
:defer t
:init
(progn
(add-hook 'js2-mode-hook 'flow-minor-enable-automatically)
(add-hook 'react-mode-hook 'flow-minor-enable-automatically)
)
:config
(progn
;; enable jumping with ,gg
(add-to-list 'spacemacs-jump-handlers-js2-mode 'flow-minor-jump-to-definition)
(add-to-list 'spacemacs-jump-handlers-react-mode 'flow-minor-jump-to-definition)
(spacemacs/declare-prefix-for-mode 'flow-minor-mode "mf" "flow" "flow type checker commands")
(spacemacs/set-leader-keys-for-minor-mode 'flow-minor-mode
"fb" 'xref-pop-marker-stack
"fd" 'flow-minor-jump-to-definition
"fc" 'flow-minor-status
"ff" 'flow-minor-suggest
"fo" 'flow-minor-coverage
"ft" 'flow-minor-type-at-pos
))))
(defun flow-type/post-init-eldoc()
(when flow-type-enable-eldoc-type-info
(add-hook 'js2-mode-hook 'flow-type-eldoc-hook)
(add-hook 'react-mode-hook 'flow-type-eldoc-hook)))
(defun flow-type/post-init-company()
(spacemacs|add-company-backends :backends company-flow :modes js2-mode react-mode))
(defun flow-type/init-company-flow ()
(use-package company-flow
:defer t
:config
(when (configuration-layer/layer-usedp 'react)
(push 'react-mode company-flow-modes))))
(defun flow-type/init-flycheck-flow()
(with-eval-after-load 'flycheck
(use-package flycheck-flow
:config
(progn
;; Don't run flow if there's no @flow pragma
(custom-set-variables '(flycheck-javascript-flow-args (quote ("--respect-pragma"))))
;; Run flow in react-mode files
(flycheck-add-mode 'javascript-flow 'react-mode)
;; After running js-flow, run js-eslint
;; doing this in the other order causes a lot of repeated errors!!!
(flycheck-add-next-checker 'javascript-flow 'javascript-eslint)
))))