Skip to content

Instantly share code, notes, and snippets.

@almost
Last active June 9, 2016 20:57
Show Gist options
  • Save almost/5547b7f3a79604d85ac6 to your computer and use it in GitHub Desktop.
Save almost/5547b7f3a79604d85ac6 to your computer and use it in GitHub Desktop.
Use flow.js to show type signature for value under cursor whenever the cursor is idle for more than half a second (assumes espresso-mode.el)
(defun 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 ()
(interactive)
(let* ((info (json-read-from-string
(call-process-on-buffer-to-string
(format "flow type-at-pos --json %d %d" (line-number-at-pos) (current-column)))))
(type (cdr (assoc 'type info))))
(princ info)
(if (not (string-equal type "(unknown)"))
(message type))))
(defun flow-pragma-exists ()
(save-excursion
(save-match-data
(goto-char (point-min))
(not (null (search-forward "@flow" 200 t))))))
(defun flow-espresso-mode-hook ()
(when (flow-pragma-exists)
(run-with-idle-timer 0.5 t 'flow-type)))
(add-hook 'espresso-mode-hook 'flow-espresso-mode-hook)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment