-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff95f2a
commit c8b1b67
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#+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 | ||
|
||
* 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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(defun flow-type/call-process-on-buffer-to-string (command) | ||
(with-output-to-string | ||
(call-process-region (point-min) (point-max) shell-file-name nil standard-output nil shell-command-switch command))) | ||
|
||
(defun flow-type/type-description (info) | ||
(let ((type (alist-get 'type info))) | ||
(if (string-equal type "(unknown)") | ||
(let ((reasons (alist-get 'reasons info))) | ||
(if (> (length reasons) 0) (alist-get 'desc (aref reasons 0)))) | ||
type))) | ||
|
||
(defun flow-type/type-at-cursor () | ||
(let ((output (flow-type/call-process-on-buffer-to-string | ||
(format "flow type-at-pos --retry-if-init=false --json %d %d" (line-number-at-pos) (+ (current-column) 1))))) | ||
(unless (string-match "\w*flow is still initializing" output) | ||
(flow-type/type-description (json-read-from-string output))))) | ||
|
||
(defun flow-type/init-mode () | ||
(set (make-local-variable 'eldoc-documentation-function) 'flow-type/type-at-cursor)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
;;; packages.el --- flow-type layer packages file for Spacemacs. | ||
;; | ||
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors | ||
;; | ||
;; Author: Jonathan del Strother <jdelStrother@gmail.com> | ||
;; URL: https://github.com/syl20bnr/spacemacs | ||
;; | ||
;; This file is not part of GNU Emacs. | ||
;; | ||
;;; License: GPLv3 | ||
|
||
(defconst flow-type-packages | ||
'(company | ||
(company-flow :toggle (configuration-layer/package-usedp 'company)) | ||
(flycheck-flow :toggle (configuration-layer/package-usedp 'flycheck)) | ||
js2-mode | ||
web-mode)) | ||
|
||
(defun flow-type/post-init-js2-mode() | ||
(push 'flow-type/init-mode js2-mode-hook)) | ||
|
||
(defun flow-type/post-init-web-mode() | ||
(push 'flow-type/init-mode react-mode-hook)) | ||
|
||
(defun flow-type/post-init-company() | ||
(spacemacs|add-company-hook js2-mode) | ||
(when (configuration-layer/layer-usedp 'react) | ||
(spacemacs|add-company-hook react-mode))) | ||
|
||
(defun flow-type/init-company-flow () | ||
(use-package company-flow | ||
:defer t | ||
:init | ||
(progn | ||
(push 'company-flow company-backends-js2-mode) | ||
(when (configuration-layer/package-usedp 'web-mode) | ||
(push 'company-flow company-backends-react-mode)) | ||
) | ||
:config | ||
(when (configuration-layer/package-usedp 'web-mode) | ||
(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 | ||
(flycheck-add-next-checker 'javascript-flow 'javascript-eslint) | ||
)))) |