Skip to content

Instantly share code, notes, and snippets.

@jsatk
Created September 8, 2018 00:36
Show Gist options
  • Save jsatk/50d72465f26302d48edfb28bb571c743 to your computer and use it in GitHub Desktop.
Save jsatk/50d72465f26302d48edfb28bb571c743 to your computer and use it in GitHub Desktop.
" Uses Dispatch to print the flow type of the variable under the cursor.
"
" Example:
"
" ```javascript
"
" type Person = {age: number, name: string, sex: 'male' | 'female'}
" const person: Person = {age: 35, name: 'Bob', sex: 'male'};
" const {a|ge, sex} = person;
" ^
" cursor
"
" // Would print `number`.
"
" const {age, s|ex} = person;
" ^
" cursor
"
" // Would print `'male' | 'female'`.
" ```
function! GetFlowType()
let cursorcolumn = col('.')
let cursorline = line('.')
let localflow = "~/khan/webapp/node_modules/.bin/flow"
execute "Dispatch " . localflow . " type-at-pos --quiet " . expand('%:p') . " " . cursorline. " " .cursorcolumn
endfunction
nnoremap <leader>t :call GetFlowType()<cr>
@jsatk
Copy link
Author

jsatk commented Sep 8, 2018

This line could use some love. We should probably check for the flow binary in a safer way but 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment