Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add flow language server #42

Closed
entropitor opened this issue Sep 21, 2017 · 7 comments
Closed

How to add flow language server #42

entropitor opened this issue Sep 21, 2017 · 7 comments

Comments

@entropitor
Copy link

How can I use the flow language server together with vim-lsp?

(https://github.com/flowtype/flow-language-server)

@prabirshrestha
Copy link
Owner

It should be similar to typescript. https://github.com/prabirshrestha/vim-lsp/wiki/Servers-TypeScript

@prabirshrestha
Copy link
Owner

Added a wiki page on how to use flow language server at https://github.com/prabirshrestha/vim-lsp/wiki/Servers-Flow

@entropitor
Copy link
Author

entropitor commented Sep 21, 2017

You're the best @prabirshrestha ! 💯

@TrySound
Copy link

@prabirshrestha There's also native lsp support in latest versions via flow lsp. Could you provide an example with using it with nearest node_modules/.bin/flow?

@prabirshrestha
Copy link
Owner

I have updated the docs to use flow lsp.

@TrySound As for the local flow bin, you can write a custom function to return cmd.

function! s:get_flowbin(server_info) 
    let l:nodemodules_dir = lsp#utils#find_nearest_parent_directory(lsp#utils#get_buffer_path(), 'node_modules')
    if !empty(nodemodules_dir)
        " you might also want to verify if flow binary actually exists
        return [&shell, &shellcmdflag, l:nodemodules_dir . '/.bin/flow lsp']
    endif
    " instead of returning empty you could also return ['flow', 'lsp] to tell it to use global flow.
    return []
endfunction

Then update the cmd to point to the function you created above.

'cmd': function('s:get_flowbin')

I personally use typescript every day and prefer to use global which I keep up to date so that when I'm cleaning the git repro or switching branches I always have the binary there.

@TrySound
Copy link

TrySound commented Oct 15, 2018

@prabirshrestha This is not the case with flow because a few different projects may use different flow versions and produce different errors. I'm sure this is also true for typescript.

@TrySound
Copy link

For some reason asyncomplete just doesn't work with vim-lsp. This is my config

let g:lsp_preview_keep_focus = 0
let g:asyncomplete_smart_completion = 1
let g:asyncomplete_force_refresh_on_context_changed = 1
let g:asyncomplete_auto_popup = 0

function! s:check_back_space() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1]  =~ '\s'
endfunction

inoremap <silent><expr> <TAB>
  \ pumvisible() ? "\<C-n>" :
  \ <SID>check_back_space() ? "\<TAB>" :
  \ asyncomplete#force_refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:get_flowbin(server_info) 
    let l:nodemodules_dir = lsp#utils#find_nearest_parent_directory(lsp#utils#get_buffer_path(), 'node_modules')
    if !empty(nodemodules_dir)
        " you might also want to verify if flow binary actually exists
        return [&shell, &shellcmdflag, l:nodemodules_dir . '/.bin/flow lsp']
    endif
    " instead of returning empty you could also return ['flow', 'lsp] to tell it to use global flow.
    return []
endfunction

au User lsp_setup call lsp#register_server({
    \ 'name': 'flow',
    \ 'cmd': function('s:get_flowbin'),
    \ 'root_uri':{server_info->lsp#utils#path_to_uri(lsp#utils#find_nearest_parent_file_directory(lsp#utils#get_buffer_path(), '.flowconfig'))},
    \ 'whitelist': ['javascript', 'javascript.jsx'],
    \ })

au User asyncomplete_setup call asyncomplete#register_source(asyncomplete#sources#file#get_source_options({
    \ 'name': 'file',
    \ 'whitelist': ['*'],
    \ 'priority': 10,
    \ 'completor': function('asyncomplete#sources#file#completor')
    \ }))

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

No branches or pull requests

3 participants