Ale: Feature request: Go To Definition for flow

Created on 29 Mar 2018  路  11Comments  路  Source: dense-analysis/ale

Would be sweet if Go To Definition - :ALEGoToDefinition - worked for flow as it does for typescript

p.s. thanks for adding this for typescript, it is very helpful!

LSP enhancement

Most helpful comment

There will be lsp support in flow out of the box soon.

All 11 comments

The first step for this would be to implement support for flow-language-server. Then the existing LSP support should enable using ALEgoToDefinition for a file. One problem we'd need to fix is deciding _which_ server should be used for getting the definition of something. Currently ALE just looks for the first one available.

There will be lsp support in flow out of the box soon.

Okay, good to know.

I tried using flow-language-server briefly, but I just kept getting this message, found using ch_logfile.

  3.761513 RECV on 0: '{"jsonrpc":"2.0","id":1,"error":{"code":-32603,"message":"Request initialize failed with message: ENOENT: no such file or directory, chmod '/home/w0rp/.local/share/flow/bin/0.74.0/flow'"}}'

I don't know what that means. It looks like it tried and failed to download some kind of file. Here were the previous messages with some noise cut out.

  0.789343 RECV on 0: '{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":4,"message":"[2018-06-20 23:51:36.988] [INFO] flow-versions - Determining the version of flow for your project..."}}'
  0.808649 RECV on 0: '{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":4,"message":"[2018-06-20 23:51:37.008] [INFO] flow-versions - Found flow version requirement ^0.74.0 in your package.json"}}'
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":4,"message":"[2018-06-20 23:51:37.010] [INFO] flow-versions - Looking for a version of flow matching ^0.74.0..."}}'
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":4,"message":"[2018-06-20 23:51:37.036] [INFO] nuclide-commons/process - 13ms: which flow"}}'
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":4,"message":"[2018-06-20 23:51:37.038] [INFO] flow-versions - Checking the disk cache for a local copy of flow..."}}'
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":4,"message":"[2018-06-20 23:51:37.040] [INFO] flow-versions - No suitable flow found on disk"}}'
{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":4,"message":"[2018-06-20 23:51:37.619] [INFO] flow-versions - Found a match with version v0.74.0 on GitHub. Downloading..."}}'
  3.760651 RECV on 0: '{"jsonrpc":"2.0","method":"window/logMessage","params":{"type":4,"message":"[2018-06-20 23:51:39.960] [INFO] flow-versions - Successfully downloaded and installed flow version v0.74.0 from GitHub"}}'

Here's the VimL code I was testing with.

" Author: w0rp <[email protected]>
" Description: Integrate ALE with flow-language-server.

call ale#Set('javascript_flow_ls_executable', 'flow-language-server')
call ale#Set('javascript_flow_ls_use_global', 
\    get(g:, 'ale_use_global_executables', 0)
\)

function! ale_linters#javascript#flow_ls#GetExecutable(buffer) abort
    return ale#node#FindExecutable(a:buffer, 'javascript_flow_ls', [
    \   'node_modules/.bin/flow-language-server',
    \])
endfunction

function! ale_linters#javascript#flow_ls#GetCommand(buffer) abort
    let l:executable = ale_linters#javascript#flow_ls#GetExecutable(a:buffer)

    return ale#Escape(l:executable) . ' --stdio'
endfunction

function! ale_linters#javascript#flow_ls#FindProjectRoot(buffer) abort
    let l:flow_config = ale#path#FindNearestFile(a:buffer, '.flowconfig')

    if !empty(l:flow_config)
        return fnamemodify(l:flow_config, ':h')
    endif

    return ''
endfunction

call ale#linter#Define('javascript', {
\   'name': 'flow-language-server',
\   'lsp': 'stdio',
\   'executable_callback': 'ale_linters#javascript#flow_ls#GetExecutable',
\   'command_callback': 'ale_linters#javascript#flow_ls#GetCommand',
\   'project_root_callback': 'ale_linters#javascript#flow_ls#FindProjectRoot',
\   'language': 'javascript',
\})

Maybe someone else can figure out how to get it to work later.

Sure, that might work better. I'll give that a go later.

Awesome!! So stoked to see this come together thanks for the hard work all!

1703 Added support for running the flow language server. I'll see about adding some version detection for automatically preferring that over the regular old server.

I'll close this now. Disabling the other flow server if the language server is available can be handled later.

@w0rp Is there a way to disable the duplication of messages in the loclist?

@zeorin You might just have to disable the old flow linter if you're using the language server. See :help b:ale_linters_ignore.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trevordmiller picture trevordmiller  路  3Comments

trevordmiller picture trevordmiller  路  4Comments

garand picture garand  路  4Comments

glepnir picture glepnir  路  3Comments

amerov picture amerov  路  4Comments