diff options
34 files changed, 610 insertions, 270 deletions
diff --git a/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index 587bb372..587bb372 100644 --- a/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md diff --git a/CONTRIBUTING.md b/.github/CONTRIBUTING.md index e59f8326..e59f8326 100644 --- a/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md diff --git a/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 8e1b5c57..8e1b5c57 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,6 +1,7 @@ FROM tweekmonster/vim-testbed:latest RUN install_vim -tag v8.0.0027 -build \ + -tag v8.1.0204 -build \ -tag neovim:v0.2.0 -build \ -tag neovim:v0.3.0 -build @@ -97,7 +97,7 @@ formatting. | Awk | [gawk](https://www.gnu.org/software/gawk/)| | Bash | [language-server](https://github.com/mads-hartmann/bash-language-server), shell [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) | | Bourne Shell | shell [-n flag](http://linux.die.net/man/1/sh), [shellcheck](https://www.shellcheck.net/), [shfmt](https://github.com/mvdan/sh) | -| C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [clang](http://clang.llvm.org/), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/) | +| C | [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint), [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html), [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/) | | C++ (filetype cpp) | [clang](http://clang.llvm.org/), [clangcheck](http://clang.llvm.org/docs/ClangCheck.html) !!, [clangtidy](http://clang.llvm.org/extra/clang-tidy/) !!, [clang-format](https://clang.llvm.org/docs/ClangFormat.html), [cppcheck](http://cppcheck.sourceforge.net), [cpplint](https://github.com/google/styleguide/tree/gh-pages/cpplint) !!, [cquery](https://github.com/cquery-project/cquery), [flawfinder](https://www.dwheeler.com/flawfinder/), [gcc](https://gcc.gnu.org/) | | CUDA | [nvcc](http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html) | | C# | [mcs](http://www.mono-project.com/docs/about-mono/languages/csharp/) see:`help ale-cs-mcs` for details, [mcsc](http://www.mono-project.com/docs/about-mono/languages/csharp/) !! see:`help ale-cs-mcsc` for details and configuration| @@ -128,7 +128,7 @@ formatting. | GraphQL | [eslint](http://eslint.org/), [gqlint](https://github.com/happylinks/gqlint), [prettier](https://github.com/prettier/prettier) | | Haml | [haml-lint](https://github.com/brigade/haml-lint) | | Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) | -| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt) | +| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [cabal-ghc](https://www.haskell.org/cabal/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt) | | HTML | [alex](https://github.com/wooorm/alex) !!, [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/), [write-good](https://github.com/btford/write-good) | | Idris | [idris](http://www.idris-lang.org/) | | Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/) | diff --git a/ale_linters/apiblueprint/drafter.vim b/ale_linters/apiblueprint/drafter.vim index 9cded359..198709f9 100644 --- a/ale_linters/apiblueprint/drafter.vim +++ b/ale_linters/apiblueprint/drafter.vim @@ -31,6 +31,6 @@ call ale#linter#Define('apiblueprint', { \ 'name': 'drafter', \ 'output_stream': 'stderr', \ 'executable': 'drafter', -\ 'command': 'drafter --use-line-num --validate %t', +\ 'command': 'drafter --use-line-num --validate', \ 'callback': 'ale_linters#apiblueprint#drafter#HandleErrors', \}) diff --git a/ale_linters/c/clangd.vim b/ale_linters/c/clangd.vim new file mode 100644 index 00000000..5aa2e221 --- /dev/null +++ b/ale_linters/c/clangd.vim @@ -0,0 +1,29 @@ +" Author: Andrey Melentyev <andrey.melentyev@protonmail.com> +" Description: Clangd language server + +call ale#Set('c_clangd_executable', 'clangd') +call ale#Set('c_clangd_options', '') + +function! ale_linters#c#clangd#GetProjectRoot(buffer) abort + let l:project_root = ale#path#FindNearestFile(a:buffer, 'compile_commands.json') + return !empty(l:project_root) ? fnamemodify(l:project_root, ':h') : '' +endfunction + +function! ale_linters#c#clangd#GetExecutable(buffer) abort + return ale#Var(a:buffer, 'c_clangd_executable') +endfunction + +function! ale_linters#c#clangd#GetCommand(buffer) abort + let l:executable = ale_linters#c#clangd#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'c_clangd_options') + + return ale#Escape(l:executable) . (!empty(l:options) ? ' ' . l:options : '') +endfunction + +call ale#linter#Define('c', { +\ 'name': 'clangd', +\ 'lsp': 'stdio', +\ 'executable_callback': 'ale_linters#c#clangd#GetExecutable', +\ 'command_callback': 'ale_linters#c#clangd#GetCommand', +\ 'project_root_callback': 'ale_linters#c#clangd#GetProjectRoot', +\}) diff --git a/ale_linters/haskell/cabal_ghc.vim b/ale_linters/haskell/cabal_ghc.vim new file mode 100644 index 00000000..79fd8ff9 --- /dev/null +++ b/ale_linters/haskell/cabal_ghc.vim @@ -0,0 +1,18 @@ +" Author: Eric Wolf <ericwolf42@gmail.com> +" Description: ghc for Haskell files called with cabal exec + +call ale#Set('haskell_cabal_ghc_options', '-fno-code -v0') + +function! ale_linters#haskell#cabal_ghc#GetCommand(buffer) abort + return 'cabal exec -- ghc ' + \ . ale#Var(a:buffer, 'haskell_cabal_ghc_options') + \ . ' %t' +endfunction + +call ale#linter#Define('haskell', { +\ 'name': 'cabal-ghc', +\ 'output_stream': 'stderr', +\ 'executable': 'cabal', +\ 'command_callback': 'ale_linters#haskell#cabal_ghc#GetCommand', +\ 'callback': 'ale#handlers#haskell#HandleGHCFormat', +\}) diff --git a/autoload/ale.vim b/autoload/ale.vim index 26c73547..6d1e8521 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -192,12 +192,7 @@ endfunction " Every variable name will be prefixed with 'ale_'. function! ale#Var(buffer, variable_name) abort let l:full_name = 'ale_' . a:variable_name - let l:vars = getbufvar(str2nr(a:buffer), '', 0) - - if l:vars is 0 - " Look for variables from deleted buffers, saved from :ALEFix - let l:vars = get(get(g:ale_fix_buffer_data, a:buffer, {}), 'vars', {}) - endif + let l:vars = getbufvar(str2nr(a:buffer), '', {}) return get(l:vars, l:full_name, g:[l:full_name]) endfunction diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index e7da4028..7440f8cd 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -336,7 +336,9 @@ function! ale#completion#ParseLSPCompletions(response) abort endif " See :help complete-items for Vim completion kinds - if l:item.kind is s:LSP_COMPLETION_METHOD_KIND + if !has_key(l:item, 'kind') + let l:kind = 'v' + elseif l:item.kind is s:LSP_COMPLETION_METHOD_KIND let l:kind = 'm' elseif l:item.kind is s:LSP_COMPLETION_CONSTRUCTOR_KIND let l:kind = 'm' @@ -422,54 +424,65 @@ endfunction function! s:GetLSPCompletions(linter) abort let l:buffer = bufnr('') - let l:Callback = a:linter.lsp is# 'tsserver' - \ ? function('ale#completion#HandleTSServerResponse') - \ : function('ale#completion#HandleLSPResponse') - - let l:lsp_details = ale#lsp_linter#StartLSP(l:buffer, a:linter, l:Callback) + let l:lsp_details = ale#lsp_linter#StartLSP(l:buffer, a:linter) if empty(l:lsp_details) return 0 endif let l:id = l:lsp_details.connection_id + let l:root = l:lsp_details.project_root - if a:linter.lsp is# 'tsserver' - let l:message = ale#lsp#tsserver_message#Completions( - \ l:buffer, - \ b:ale_completion_info.line, - \ b:ale_completion_info.column, - \ b:ale_completion_info.prefix, - \) - else - " Send a message saying the buffer has changed first, otherwise - " completions won't know what text is nearby. - call ale#lsp#NotifyForChanges(l:lsp_details) - - " For LSP completions, we need to clamp the column to the length of - " the line. python-language-server and perhaps others do not implement - " this correctly. - let l:message = ale#lsp#message#Completion( - \ l:buffer, - \ b:ale_completion_info.line, - \ min([ - \ b:ale_completion_info.line_length, - \ b:ale_completion_info.column, - \ ]), - \ ale#completion#GetTriggerCharacter(&filetype, b:ale_completion_info.prefix), - \) - endif + function! OnReady(...) abort closure + " If we have sent a completion request already, don't send another. + if b:ale_completion_info.request_id + return + endif - let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root) + let l:Callback = a:linter.lsp is# 'tsserver' + \ ? function('ale#completion#HandleTSServerResponse') + \ : function('ale#completion#HandleLSPResponse') + call ale#lsp#RegisterCallback(l:id, l:Callback) + + if a:linter.lsp is# 'tsserver' + let l:message = ale#lsp#tsserver_message#Completions( + \ l:buffer, + \ b:ale_completion_info.line, + \ b:ale_completion_info.column, + \ b:ale_completion_info.prefix, + \) + else + " Send a message saying the buffer has changed first, otherwise + " completions won't know what text is nearby. + call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer) + + " For LSP completions, we need to clamp the column to the length of + " the line. python-language-server and perhaps others do not implement + " this correctly. + let l:message = ale#lsp#message#Completion( + \ l:buffer, + \ b:ale_completion_info.line, + \ min([ + \ b:ale_completion_info.line_length, + \ b:ale_completion_info.column, + \ ]), + \ ale#completion#GetTriggerCharacter(&filetype, b:ale_completion_info.prefix), + \) + endif - if l:request_id - let b:ale_completion_info.conn_id = l:id - let b:ale_completion_info.request_id = l:request_id + let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root) - if has_key(a:linter, 'completion_filter') - let b:ale_completion_info.completion_filter = a:linter.completion_filter + if l:request_id + let b:ale_completion_info.conn_id = l:id + let b:ale_completion_info.request_id = l:request_id + + if has_key(a:linter, 'completion_filter') + let b:ale_completion_info.completion_filter = a:linter.completion_filter + endif endif - endif + endfunction + + call ale#lsp#WaitForCapability(l:id, l:root, 'completion', function('OnReady')) endfunction function! ale#completion#GetCompletions() abort diff --git a/autoload/ale/definition.vim b/autoload/ale/definition.vim index 6c70b64c..6c7d7d32 100644 --- a/autoload/ale/definition.vim +++ b/autoload/ale/definition.vim @@ -60,43 +60,50 @@ endfunction function! s:GoToLSPDefinition(linter, options) abort let l:buffer = bufnr('') let [l:line, l:column] = getcurpos()[1:2] + let l:lsp_details = ale#lsp_linter#StartLSP(l:buffer, a:linter) - let l:Callback = a:linter.lsp is# 'tsserver' - \ ? function('ale#definition#HandleTSServerResponse') - \ : function('ale#definition#HandleLSPResponse') - - let l:lsp_details = ale#lsp_linter#StartLSP(l:buffer, a:linter, l:Callback) + if a:linter.lsp isnot# 'tsserver' + let l:column = min([l:column, len(getline(l:line))]) + endif if empty(l:lsp_details) return 0 endif let l:id = l:lsp_details.connection_id + let l:root = l:lsp_details.project_root + + function! OnReady(...) abort closure + let l:Callback = a:linter.lsp is# 'tsserver' + \ ? function('ale#definition#HandleTSServerResponse') + \ : function('ale#definition#HandleLSPResponse') + call ale#lsp#RegisterCallback(l:id, l:Callback) + + if a:linter.lsp is# 'tsserver' + let l:message = ale#lsp#tsserver_message#Definition( + \ l:buffer, + \ l:line, + \ l:column + \) + else + " Send a message saying the buffer has changed first, or the + " definition position probably won't make sense. + call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer) + + " For LSP completions, we need to clamp the column to the length of + " the line. python-language-server and perhaps others do not implement + " this correctly. + let l:message = ale#lsp#message#Definition(l:buffer, l:line, l:column) + endif - if a:linter.lsp is# 'tsserver' - let l:message = ale#lsp#tsserver_message#Definition( - \ l:buffer, - \ l:line, - \ l:column - \) - else - " Send a message saying the buffer has changed first, or the - " definition position probably won't make sense. - call ale#lsp#NotifyForChanges(l:lsp_details) - - let l:column = min([l:column, len(getline(l:line))]) - - " For LSP completions, we need to clamp the column to the length of - " the line. python-language-server and perhaps others do not implement - " this correctly. - let l:message = ale#lsp#message#Definition(l:buffer, l:line, l:column) - endif + let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root) - let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root) + let s:go_to_definition_map[l:request_id] = { + \ 'open_in_tab': get(a:options, 'open_in_tab', 0), + \} + endfunction - let s:go_to_definition_map[l:request_id] = { - \ 'open_in_tab': get(a:options, 'open_in_tab', 0), - \} + call ale#lsp#WaitForCapability(l:id, l:root, 'definition', function('OnReady')) endfunction function! ale#definition#GoTo(options) abort diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index 62674b87..8dfdeca8 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -420,9 +420,7 @@ function! ale#fix#InitBufferData(buffer, fixing_flag) abort " The 'done' flag tells the function for applying changes when fixing " is complete. let g:ale_fix_buffer_data[a:buffer] = { - \ 'vars': getbufvar(a:buffer, ''), \ 'lines_before': getbufline(a:buffer, 1, '$'), - \ 'filename': expand('#' . a:buffer . ':p'), \ 'done': 0, \ 'should_save': a:fixing_flag is# 'save_file', \ 'temporary_directory_list': [], diff --git a/autoload/ale/hover.vim b/autoload/ale/hover.vim index 6d131adc..5e97e16e 100644 --- a/autoload/ale/hover.vim +++ b/autoload/ale/hover.vim @@ -93,45 +93,51 @@ function! ale#hover#HandleLSPResponse(conn_id, response) abort endfunction function! s:ShowDetails(linter, buffer, line, column, opt) abort - let l:Callback = a:linter.lsp is# 'tsserver' - \ ? function('ale#hover#HandleTSServerResponse') - \ : function('ale#hover#HandleLSPResponse') - - let l:lsp_details = ale#lsp_linter#StartLSP(a:buffer, a:linter, l:Callback) + let l:lsp_details = ale#lsp_linter#StartLSP(a:buffer, a:linter) if empty(l:lsp_details) return 0 endif let l:id = l:lsp_details.connection_id + let l:root = l:lsp_details.project_root let l:language_id = l:lsp_details.language_id - if a:linter.lsp is# 'tsserver' - let l:column = a:column + function! OnReady(...) abort closure + let l:Callback = a:linter.lsp is# 'tsserver' + \ ? function('ale#hover#HandleTSServerResponse') + \ : function('ale#hover#HandleLSPResponse') + call ale#lsp#RegisterCallback(l:id, l:Callback) - let l:message = ale#lsp#tsserver_message#Quickinfo( - \ a:buffer, - \ a:line, - \ l:column - \) - else - " Send a message saying the buffer has changed first, or the - " hover position probably won't make sense. - call ale#lsp#NotifyForChanges(l:lsp_details) + if a:linter.lsp is# 'tsserver' + let l:column = a:column - let l:column = min([a:column, len(getbufline(a:buffer, a:line)[0])]) + let l:message = ale#lsp#tsserver_message#Quickinfo( + \ a:buffer, + \ a:line, + \ l:column + \) + else + " Send a message saying the buffer has changed first, or the + " hover position probably won't make sense. + call ale#lsp#NotifyForChanges(l:id, l:root, a:buffer) - let l:message = ale#lsp#message#Hover(a:buffer, a:line, l:column) - endif + let l:column = min([a:column, len(getbufline(a:buffer, a:line)[0])]) + + let l:message = ale#lsp#message#Hover(a:buffer, a:line, l:column) + endif + + let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root) - let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root) + let s:hover_map[l:request_id] = { + \ 'buffer': a:buffer, + \ 'line': a:line, + \ 'column': l:column, + \ 'hover_from_balloonexpr': get(a:opt, 'called_from_balloonexpr', 0), + \} + endfunction - let s:hover_map[l:request_id] = { - \ 'buffer': a:buffer, - \ 'line': a:line, - \ 'column': l:column, - \ 'hover_from_balloonexpr': get(a:opt, 'called_from_balloonexpr', 0), - \} + call ale#lsp#WaitForCapability(l:id, l:root, 'hover', function('OnReady')) endfunction " Obtain Hover information for the specified position diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim index 1dac3ab1..312319ab 100644 --- a/autoload/ale/lsp.vim +++ b/autoload/ale/lsp.vim @@ -18,6 +18,7 @@ function! ale#lsp#NewConnection(initialization_options) abort " initialization_options: Options to send to the server. " capabilities: Features the server supports. let l:conn = { + \ 'is_tsserver': 0, \ 'id': '', \ 'data': '', \ 'projects': {}, @@ -188,6 +189,16 @@ function! s:MarkProjectAsInitialized(conn, project) abort " Remove the messages now. let a:conn.message_queue = [] + + " Call capabilities callbacks queued for the project. + for [l:capability, l:Callback] in a:project.capabilities_queue + if a:conn.is_tsserver || a:conn.capabilities[l:capability] + call call(l:Callback, [a:conn.id, a:project.root]) + endif + endfor + + " Clear the queued callbacks now. + let a:project.capabilities_queue = [] endfunction function! s:HandleInitializeResponse(conn, response) abort @@ -302,22 +313,43 @@ function! s:HandleCommandMessage(job_id, message) abort call ale#lsp#HandleMessage(l:conn, a:message) endfunction -function! ale#lsp#RegisterProject(conn, project_root) abort +" Given a connection ID, mark it as a tsserver connection, so it will be +" handled that way. +function! ale#lsp#MarkConnectionAsTsserver(conn_id) abort + let l:conn = s:FindConnection('id', a:conn_id) + + if !empty(l:conn) + let l:conn.is_tsserver = 1 + endif +endfunction + +" Register a project for an LSP connection. +" +" This function will throw if the connection doesn't exist. +function! ale#lsp#RegisterProject(conn_id, project_root) abort + let l:conn = s:FindConnection('id', a:conn_id) + " Empty strings can't be used for Dictionary keys in NeoVim, due to E713. " This appears to be a nonsensical bug in NeoVim. let l:key = empty(a:project_root) ? '<<EMPTY>>' : a:project_root - if !has_key(a:conn.projects, l:key) + if !has_key(l:conn.projects, l:key) " Tools without project roots are ready right away, like tsserver. - let a:conn.projects[l:key] = { + let l:conn.projects[l:key] = { + \ 'root': a:project_root, \ 'initialized': empty(a:project_root), \ 'init_request_id': 0, \ 'message_queue': [], + \ 'capabilities_queue': [], \} endif endfunction function! ale#lsp#GetProject(conn, project_root) abort + if empty(a:conn) + return {} + endif + let l:key = empty(a:project_root) ? '<<EMPTY>>' : a:project_root return get(a:conn.projects, l:key, {}) @@ -327,7 +359,7 @@ endfunction " " The job ID will be returned for for the program if it ran, otherwise " 0 will be returned. -function! ale#lsp#StartProgram(executable, command, project_root, callback, initialization_options) abort +function! ale#lsp#StartProgram(executable, command, init_options) abort if !executable(a:executable) return 0 endif @@ -335,7 +367,7 @@ function! ale#lsp#StartProgram(executable, command, project_root, callback, init let l:conn = s:FindConnection('executable', a:executable) " Get the current connection or a new one. - let l:conn = !empty(l:conn) ? l:conn : ale#lsp#NewConnection(a:initialization_options) + let l:conn = !empty(l:conn) ? l:conn : ale#lsp#NewConnection(a:init_options) let l:conn.executable = a:executable if !has_key(l:conn, 'id') || !ale#job#IsRunning(l:conn.id) @@ -353,18 +385,15 @@ function! ale#lsp#StartProgram(executable, command, project_root, callback, init endif let l:conn.id = l:job_id - " Add the callback to the List if it's not there already. - call uniq(sort(add(l:conn.callback_list, a:callback))) - call ale#lsp#RegisterProject(l:conn, a:project_root) return l:job_id endfunction " Connect to an address and set up a callback for handling responses. -function! ale#lsp#ConnectToAddress(address, project_root, callback, initialization_options) abort +function! ale#lsp#ConnectToAddress(address, init_options) abort let l:conn = s:FindConnection('id', a:address) " Get the current connection or a new one. - let l:conn = !empty(l:conn) ? l:conn : ale#lsp#NewConnection(a:initialization_options) + let l:conn = !empty(l:conn) ? l:conn : ale#lsp#NewConnection(a:init_options) if !has_key(l:conn, 'channel_id') || !ale#socket#IsOpen(l:conn.channel_id) let l:conn.channel_id = ale#socket#Open(a:address, { @@ -377,13 +406,21 @@ function! ale#lsp#ConnectToAddress(address, project_root, callback, initializati endif let l:conn.id = a:address - " Add the callback to the List if it's not there already. - call uniq(sort(add(l:conn.callback_list, a:callback))) - call ale#lsp#RegisterProject(l:conn, a:project_root) return a:address endfunction +" Given a connection ID and a callback, register that callback for handling +" messages if the connection exists. +function! ale#lsp#RegisterCallback(conn_id, callback) abort + let l:conn = s:FindConnection('id', a:conn_id) + + if !empty(l:conn) + " Add the callback to the List if it's not there already. + call uniq(sort(add(l:conn.callback_list, a:callback))) + endif +endfunction + " Stop all LSP connections, closing all jobs and channels, and removing any " queued messages. function! ale#lsp#StopAll() abort @@ -421,11 +458,6 @@ function! ale#lsp#Send(conn_id, message, ...) abort let l:project_root = get(a:000, 0, '') let l:conn = s:FindConnection('id', a:conn_id) - - if empty(l:conn) - return 0 - endif - let l:project = ale#lsp#GetProject(l:conn, l:project_root) if empty(l:project) @@ -459,45 +491,22 @@ function! ale#lsp#Send(conn_id, message, ...) abort return l:id == 0 ? -1 : l:id endfunction -" The Document details Dictionary should contain the following keys. -" -" buffer - The buffer number for the document. -" connection_id - The connection ID for the LSP server. -" command - The command to run to start the LSP connection. -" project_root - The project root for the LSP project. -" language_id - The language ID for the project, like 'python', 'rust', etc. - -" Create a new Dictionary containing more connection details, with the -" following information added: -" -" conn - An existing LSP connection for the document. -" document_open - 1 if the document is currently open, 0 otherwise. -function! s:ExtendDocumentDetails(details) abort - let l:extended = copy(a:details) - let l:conn = s:FindConnection('id', a:details.connection_id) - - let l:extended.conn = l:conn - let l:extended.document_open = !empty(l:conn) - \ && has_key(l:conn.open_documents, a:details.buffer) - - return l:extended -endfunction - " Notify LSP servers or tsserver if a document is opened, if needed. " If a document is opened, 1 will be returned, otherwise 0 will be returned. -function! ale#lsp#OpenDocument(basic_details) abort - let l:d = s:ExtendDocumentDetails(a:basic_details) +function! ale#lsp#OpenDocument(conn_id, project_root, buffer, language_id) abort + let l:conn = s:FindConnection('id', a:conn_id) let l:opened = 0 - if !empty(l:d.conn) && !l:d.document_open - if empty(l:d.language_id) - let l:message = ale#lsp#tsserver_message#Open(l:d.buffer) + " FIXME: Return 1 if the document is already open? + if !empty(l:conn) && !has_key(l:conn.open_documents, a:buffer) + if l:conn.is_tsserver + let l:message = ale#lsp#tsserver_message#Open(a:buffer) else - let l:message = ale#lsp#message#DidOpen(l:d.buffer, l:d.language_id) + let l:message = ale#lsp#message#DidOpen(a:buffer, a:language_id) endif - call ale#lsp#Send(l:d.connection_id, l:message, l:d.project_root) - let l:d.conn.open_documents[l:d.buffer] = getbufvar(l:d.buffer, 'changedtick') + call ale#lsp#Send(a:conn_id, l:message, a:project_root) + let l:conn.open_documents[a:buffer] = getbufvar(a:buffer, 'changedtick') let l:opened = 1 endif @@ -506,25 +515,50 @@ endfunction " Notify LSP servers or tsserver that a document has changed, if needed. " If a notification is sent, 1 will be returned, otherwise 0 will be returned. -function! ale#lsp#NotifyForChanges(basic_details) abort - let l:d = s:ExtendDocumentDetails(a:basic_details) +function! ale#lsp#NotifyForChanges(conn_id, project_root, buffer) abort + let l:conn = s:FindConnection('id', a:conn_id) let l:notified = 0 - if l:d.document_open - let l:new_tick = getbufvar(l:d.buffer, 'changedtick') + if !empty(l:conn) && has_key(l:conn.open_documents, a:buffer) + let l:new_tick = getbufvar(a:buffer, 'changedtick') - if l:d.conn.open_documents[l:d.buffer] < l:new_tick - if empty(l:d.language_id) - let l:message = ale#lsp#tsserver_message#Change(l:d.buffer) + if l:conn.open_documents[a:buffer] < l:new_tick + if l:conn.is_tsserver + let l:message = ale#lsp#tsserver_message#Change(a:buffer) else - let l:message = ale#lsp#message#DidChange(l:d.buffer) + let l:message = ale#lsp#message#DidChange(a:buffer) endif - call ale#lsp#Send(l:d.connection_id, l:message, l:d.project_root) - let l:d.conn.open_documents[l:d.buffer] = l:new_tick + call ale#lsp#Send(a:conn_id, l:message, a:project_root) + let l:conn.open_documents[a:buffer] = l:new_tick let l:notified = 1 endif endif return l:notified endfunction + +" Given some LSP details that must contain at least `connection_id` and +" `project_root` keys, +function! ale#lsp#WaitForCapability(conn_id, project_root, capability, callback) abort + let l:conn = s:FindConnection('id', a:conn_id) + let l:project = ale#lsp#GetProject(l:conn, a:project_root) + + if empty(l:project) + return 0 + endif + + if type(get(l:conn.capabilities, a:capability, v:null)) isnot type(0) + throw 'Invalid capability ' . a:capability + endif + + if l:project.initialized + if l:conn.is_tsserver || l:conn.capabilities[a:capability] + " The project has been initialized, so call the callback now. + call call(a:callback, [a:conn_id, a:project_root]) + endif + else + " Call the callback later, once we have the information we need. + call add(l:project.capabilities_queue, [a:capability, a:callback]) + endif +endfunction diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim index 6dc78e4c..87aee759 100644 --- a/autoload/ale/lsp_linter.vim +++ b/autoload/ale/lsp_linter.vim @@ -126,10 +126,9 @@ function! ale#lsp_linter#GetOptions(buffer, linter) abort return l:initialization_options endfunction -" Given a buffer, an LSP linter, and a callback to register for handling -" messages, start up an LSP linter and get ready to receive errors or -" completions. -function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort +" Given a buffer, an LSP linter, start up an LSP linter and get ready to +" receive messages for the document. +function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:command = '' let l:address = '' let l:root = ale#util#GetFunction(a:linter.project_root_callback)(a:buffer) @@ -140,16 +139,11 @@ function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort return {} endif - let l:initialization_options = ale#lsp_linter#GetOptions(a:buffer, a:linter) + let l:init_options = ale#lsp_linter#GetOptions(a:buffer, a:linter) if a:linter.lsp is# 'socket' let l:address = ale#linter#GetAddress(a:buffer, a:linter) - let l:conn_id = ale#lsp#ConnectToAddress( - \ l:address, - \ l:root, - \ a:callback, - \ l:initialization_options, - \) + let l:conn_id = ale#lsp#ConnectToAddress(l:address, l:init_options) else let l:executable = ale#linter#GetExecutable(a:buffer, a:linter) @@ -164,14 +158,10 @@ function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort let l:conn_id = ale#lsp#StartProgram( \ l:executable, \ l:command, - \ l:root, - \ a:callback, - \ l:initialization_options, + \ l:init_options, \) endif - let l:language_id = ale#util#GetFunction(a:linter.language_callback)(a:buffer) - if empty(l:conn_id) if g:ale_history_enabled && !empty(l:command) call ale#history#Add(a:buffer, 'failed', l:conn_id, l:command) @@ -180,6 +170,16 @@ function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort return {} endif + " tsserver behaves differently, so tell the LSP API that it is tsserver. + if a:linter.lsp is# 'tsserver' + call ale#lsp#MarkConnectionAsTsserver(l:conn_id) + endif + + " Register the project now the connection is ready. + call ale#lsp#RegisterProject(l:conn_id, l:root) + + let l:language_id = ale#util#GetFunction(a:linter.language_callback)(a:buffer) + let l:details = { \ 'buffer': a:buffer, \ 'connection_id': l:conn_id, @@ -188,7 +188,7 @@ function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort \ 'language_id': l:language_id, \} - if ale#lsp#OpenDocument(l:details) + if ale#lsp#OpenDocument(l:conn_id, l:root, a:buffer, l:language_id) if g:ale_history_enabled && !empty(l:command) call ale#history#Add(a:buffer, 'started', l:conn_id, l:command) endif @@ -196,7 +196,7 @@ function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort " The change message needs to be sent for tsserver before doing anything. if a:linter.lsp is# 'tsserver' - call ale#lsp#NotifyForChanges(l:details) + call ale#lsp#NotifyForChanges(l:conn_id, l:root, a:buffer) endif return l:details @@ -204,11 +204,7 @@ endfunction function! ale#lsp_linter#CheckWithLSP(buffer, linter) abort let l:info = g:ale_buffer_info[a:buffer] - let l:lsp_details = ale#lsp_linter#StartLSP( - \ a:buffer, - \ a:linter, - \ function('ale#lsp_linter#HandleLSPResponse'), - \) + let l:lsp_details = ale#lsp_linter#StartLSP(a:buffer, a:linter) if empty(l:lsp_details) return 0 @@ -217,25 +213,25 @@ function! ale#lsp_linter#CheckWithLSP(buffer, linter) abort let l:id = l:lsp_details.connection_id let l:root = l:lsp_details.project_root + " Register a callback now for handling errors now. + let l:Callback = function('ale#lsp_linter#HandleLSPResponse') + call ale#lsp#RegisterCallback(l:id, l:Callback) + " Remember the linter this connection is for. let s:lsp_linter_map[l:id] = a:linter.name if a:linter.lsp is# 'tsserver' let l:message = ale#lsp#tsserver_message#Geterr(a:buffer) - let l:request_id = ale#lsp#Send(l:id, l:message, l:root) - - let l:notified = l:request_id != 0 + let l:notified = ale#lsp#Send(l:id, l:message, l:root) != 0 else - let l:notified = ale#lsp#NotifyForChanges(l:lsp_details) + let l:notified = ale#lsp#NotifyForChanges(l:id, l:root, a:buffer) endif " If this was a file save event, also notify the server of that. if a:linter.lsp isnot# 'tsserver' \&& getbufvar(a:buffer, 'ale_save_event_fired', 0) let l:save_message = ale#lsp#message#DidSave(a:buffer) - let l:request_id = ale#lsp#Send(l:id, l:save_message, l:root) - - let l:notified = l:request_id != 0 + let l:notified = ale#lsp#Send(l:id, l:save_message, l:root) != 0 endif if l:notified diff --git a/autoload/ale/references.vim b/autoload/ale/references.vim index 89df69eb..3a710b7b 100644 --- a/autoload/ale/references.vim +++ b/autoload/ale/references.vim @@ -68,37 +68,46 @@ function! s:FindReferences(linter) abort let l:buffer = bufnr('') let [l:line, l:column] = getcurpos()[1:2] - let l:Callback = a:linter.lsp is# 'tsserver' - \ ? function('ale#references#HandleTSServerResponse') - \ : function('ale#references#HandleLSPResponse') + if a:linter.lsp isnot# 'tsserver' + let l:column = min([l:column, len(getline(l:line))]) + endif - let l:lsp_details = ale#lsp_linter#StartLSP(l:buffer, a:linter, l:Callback) + let l:lsp_details = ale#lsp_linter#StartLSP(l:buffer, a:linter) if empty(l:lsp_details) return 0 endif let l:id = l:lsp_details.connection_id + let l:root = l:lsp_details.project_root - if a:linter.lsp is# 'tsserver' - let l:message = ale#lsp#tsserver_message#References( - \ l:buffer, - \ l:line, - \ l:column - \) - else - " Send a message saying the buffer has changed first, or the - " references position probably won't make sense. - call ale#lsp#NotifyForChanges(l:lsp_details) + function! OnReady(...) abort closure + let l:Callback = a:linter.lsp is# 'tsserver' + \ ? function('ale#references#HandleTSServerResponse') + \ : function('ale#references#HandleLSPResponse') - let l:column = min([l:column, len(getline(l:line))]) + call ale#lsp#RegisterCallback(l:id, l:Callback) - let l:message = ale#lsp#message#References(l:buffer, l:line, l:column) - endif + if a:linter.lsp is# 'tsserver' + let l:message = ale#lsp#tsserver_message#References( + \ l:buffer, + \ l:line, + \ l:column + \) + else + " Send a message saying the buffer has changed first, or the + " references position probably won't make sense. + call ale#lsp#NotifyForChanges(l:id, l:root, l:buffer) + + let l:message = ale#lsp#message#References(l:buffer, l:line, l:column) + endif + + let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root) - let l:request_id = ale#lsp#Send(l:id, l:message, l:lsp_details.project_root) + let s:references_map[l:request_id] = {} + endfunction - let s:references_map[l:request_id] = {} + call ale#lsp#WaitForCapability(l:id, l:root, 'references', function('OnReady')) endfunction function! ale#references#Find() abort diff --git a/doc/ale-c.txt b/doc/ale-c.txt index c41f3bc8..acff722c 100644 --- a/doc/ale-c.txt +++ b/doc/ale-c.txt @@ -64,6 +64,25 @@ g:ale_c_clang_options *g:ale_c_clang_options* =============================================================================== +clangd *ale-c-clangd* + +g:ale_c_clangd_executable *g:ale_c_clangd_executable* + *b:ale_c_clangd_executable* + Type: |String| + Default: `'clangd'` + + This variable can be changed to use a different executable for clangd. + + +g:ale_c_clangd_options *g:ale_c_clangd_options* + *b:ale_c_clangd_options* + Type: |String| + Default: `''` + + This variable can be changed to modify flags given to clangd. + + +=============================================================================== clang-format *ale-c-clangformat* g:ale_c_clangformat_executable *g:ale_c_clangformat_executable* diff --git a/doc/ale-haskell.txt b/doc/ale-haskell.txt index 09ecd92d..15d3ce48 100644 --- a/doc/ale-haskell.txt +++ b/doc/ale-haskell.txt @@ -23,6 +23,17 @@ g:ale_haskell_ghc_options *g:ale_haskell_ghc_options* This variable can be changed to modify flags given to ghc. =============================================================================== +cabal-ghc *ale-haskell-cabal-ghc* + +g:ale_haskell_cabal_ghc_options *g:ale_haskell_cabal_ghc_options* + *b:ale_haskell_cabal_ghc_options* + Type: |String| + Default: `'-fno-code -v0'` + + This variable can be changed to modify flags given to ghc through cabal + exec. + +=============================================================================== hdevtools *ale-haskell-hdevtools* g:ale_haskell_hdevtools_executable *g:ale_haskell_hdevtools_executable* diff --git a/doc/ale.txt b/doc/ale.txt index 589b58f9..8182c27a 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -26,6 +26,7 @@ CONTENTS *ale-contents* gawk................................|ale-awk-gawk| c.....................................|ale-c-options| clang...............................|ale-c-clang| + clangd..............................|ale-c-clangd| clang-format........................|ale-c-clangformat| clangtidy...........................|ale-c-clangtidy| cppcheck............................|ale-c-cppcheck| @@ -99,6 +100,7 @@ CONTENTS *ale-contents* haskell...............................|ale-haskell-options| brittany............................|ale-haskell-brittany| ghc.................................|ale-haskell-ghc| + cabal-ghc...........................|ale-haskell-cabal-ghc| hdevtools...........................|ale-haskell-hdevtools| hfmt................................|ale-haskell-hfmt| stack-build.........................|ale-haskell-stack-build| @@ -334,7 +336,7 @@ Notes: * Awk: `gawk` * Bash: `language-server`, `shell` (-n flag), `shellcheck`, `shfmt` * Bourne Shell: `shell` (-n flag), `shellcheck`, `shfmt` -* C: `cppcheck`, `cpplint`!!, `clang`, `clangtidy`!!, `clang-format`, `flawfinder`, `gcc` +* C: `cppcheck`, `cpplint`!!, `clang`, `clangd`, `clangtidy`!!, `clang-format`, `flawfinder`, `gcc` * C++ (filetype cpp): `clang`, `clangcheck`!!, `clangtidy`!!, `clang-format`, `cppcheck`, `cpplint`!!, `cquery`, `flawfinder`, `gcc` * CUDA: `nvcc`!! * C#: `mcs`, `mcsc`!! @@ -365,7 +367,7 @@ Notes: * GraphQL: `eslint`, `gqlint`, `prettier` * Haml: `haml-lint` * Handlebars: `ember-template-lint` -* Haskell: `brittany`, `ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt` +* Haskell: `brittany`, `ghc`, `cabal-ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt` * HTML: `alex`!!, `HTMLHint`, `proselint`, `tidy`, `write-good` * Idris: `idris` * Java: `checkstyle`, `javac`, `google-java-format`, `PMD` @@ -120,6 +120,11 @@ file_number=0 pid_list='' for vim in $(docker run --rm "$DOCKER_RUN_IMAGE" ls /vim-build/bin | grep '^neovim\|^vim' ); do + # Skip Vim 8.1 for now. + if [[ $vim =~ ^vim-v8.1 ]]; then + continue + fi + if ( [[ $vim =~ ^vim ]] && ((run_vim_tests)) ) \ || ( [[ $vim =~ ^neovim-v0.2 ]] && ((run_neovim_02_tests)) ) \ || ( [[ $vim =~ ^neovim-v0.3 ]] && ((run_neovim_03_tests)) ); then diff --git a/test/command_callback/clangd_paths/compile_commands.json b/test/command_callback/clangd_paths/compile_commands.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/clangd_paths/compile_commands.json diff --git a/test/command_callback/test_c_clangd_command_callbacks.vader b/test/command_callback/test_c_clangd_command_callbacks.vader new file mode 100644 index 00000000..c8c10b67 --- /dev/null +++ b/test/command_callback/test_c_clangd_command_callbacks.vader @@ -0,0 +1,32 @@ +Before: + call ale#assert#SetUpLinterTest('c', 'clangd') + + Save &filetype + let &filetype = 'c' + +After: + call ale#assert#TearDownLinterTest() + +Execute(The language string should be correct): + AssertLSPLanguage 'c' + +Execute(The default executable should be correct): + AssertLinter 'clangd', ale#Escape('clangd') + +Execute(The project root should be detected correctly): + AssertLSPProject '' + + call ale#test#SetFilename('clangd_paths/dummy.c') + + AssertLSPProject ale#path#Simplify(g:dir . '/clangd_paths') + +Execute(The executable should be configurable): + let g:ale_c_clangd_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') + +Execute(The options should be configurable): + let b:ale_c_clangd_options = '-compile-commands-dir=foo' + + AssertLinter 'clangd', ale#Escape('clangd') . ' ' . b:ale_c_clangd_options + diff --git a/test/command_callback/test_haskell_cabal_ghc_command_callbacks.vader b/test/command_callback/test_haskell_cabal_ghc_command_callbacks.vader new file mode 100644 index 00000000..650aefa3 --- /dev/null +++ b/test/command_callback/test_haskell_cabal_ghc_command_callbacks.vader @@ -0,0 +1,23 @@ +Before: + Save g:ale_haskell_cabal_ghc_options + + unlet! g:ale_haskell_cabal_ghc_options + unlet! b:ale_haskell_cabal_ghc_options + + runtime ale_linters/haskell/cabal_ghc.vim + +After: + Restore + unlet! b:ale_haskell_cabal_ghc_options + call ale#linter#Reset() + +Execute(The options should be used in the command): + AssertEqual + \ 'cabal exec -- ghc -fno-code -v0 %t', + \ ale_linters#haskell#cabal_ghc#GetCommand(bufnr('')) + + let b:ale_haskell_cabal_ghc_options = 'foobar' + + AssertEqual + \ 'cabal exec -- ghc foobar %t', + \ ale_linters#haskell#cabal_ghc#GetCommand(bufnr('')) diff --git a/test/completion/test_completion_events.vader b/test/completion/test_completion_events.vader index f8cf268c..f3e05950 100644 --- a/test/completion/test_completion_events.vader +++ b/test/completion/test_completion_events.vader @@ -32,8 +32,16 @@ Before: endfunction let g:ale_completion_delay = 0 - call ale#completion#Queue() - sleep 1m + + " Run this check a few times, as it can fail randomly. + for g:i in range(has('nvim-0.3') || has('win32') ? 5 : 1) + call ale#completion#Queue() + sleep 1m + + if g:get_completions_called is a:expect_success + break + endif + endfor AssertEqual a:expect_success, g:get_completions_called endfunction diff --git a/test/completion/test_lsp_completion_messages.vader b/test/completion/test_lsp_completion_messages.vader index 00a174dc..ed0f358b 100644 --- a/test/completion/test_lsp_completion_messages.vader +++ b/test/completion/test_lsp_completion_messages.vader @@ -13,11 +13,11 @@ Before: runtime autoload/ale/lsp.vim let g:message_list = [] + let g:capability_checked = '' let g:Callback = '' + let g:wait_callback_list = [] - function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort - let g:Callback = a:callback - + function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:conn = ale#lsp#NewConnection({}) let l:conn.id = 347 let l:conn.open_documents = {a:buffer : -1} @@ -35,15 +35,28 @@ Before: return 'i' endfunction + function! ale#lsp#WaitForCapability(conn_id, project_root, capability, callback) abort + let g:capability_checked = a:capability + call add(g:wait_callback_list, a:callback) + endfunction + + function! ale#lsp#RegisterCallback(conn_id, callback) abort + let g:Callback = a:callback + endfunction + " Replace the Send function for LSP, so we can monitor calls to it. function! ale#lsp#Send(conn_id, message, ...) abort call add(g:message_list, a:message) + + return 1 endfunction After: Restore unlet! g:message_list + unlet! g:capability_checked + unlet! g:wait_callback_list unlet! g:Callback unlet! b:ale_old_omnifunc unlet! b:ale_old_completopt @@ -84,6 +97,13 @@ Execute(The right message should be sent for the initial tsserver request): call ale#completion#GetCompletions() + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual 1, len(g:wait_callback_list) + AssertEqual 'completion', g:capability_checked + call map(g:wait_callback_list, 'v:val([347, ''/foo/bar''])') + " We should send the right callback. AssertEqual \ 'function(''ale#completion#HandleTSServerResponse'')', @@ -96,9 +116,9 @@ Execute(The right message should be sent for the initial tsserver request): AssertEqual \ { \ 'line_length': 3, - \ 'conn_id': 0, + \ 'conn_id': 347, \ 'column': 3, - \ 'request_id': 0, + \ 'request_id': 1, \ 'line': 1, \ 'prefix': 'fo', \ }, @@ -164,6 +184,13 @@ Execute(The right message should be sent for the initial LSP request): call ale#completion#GetCompletions() + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual 1, len(g:wait_callback_list) + AssertEqual 'completion', g:capability_checked + call map(g:wait_callback_list, 'v:val([347, ''/foo/bar''])') + " We should send the right callback. AssertEqual \ 'function(''ale#completion#HandleLSPResponse'')', @@ -192,10 +219,58 @@ Execute(The right message should be sent for the initial LSP request): AssertEqual \ { \ 'line_length': 3, - \ 'conn_id': 0, + \ 'conn_id': 347, \ 'column': 3, - \ 'request_id': 0, + \ 'request_id': 1, \ 'line': 1, \ 'prefix': 'fo', + \ 'completion_filter': 'ale#completion#python#CompletionItemFilter', \ }, \ get(b:, 'ale_completion_info', {}) + +Execute(Two completion requests shouldn't be sent in a row): + call ale#linter#PreventLoading('python') + call ale#linter#Define('python', { + \ 'name': 'foo', + \ 'lsp': 'stdio', + \ 'executable': 'foo', + \ 'command': 'foo', + \ 'project_root_callback': {-> '/foo/bar'}, + \}) + call ale#linter#Define('python', { + \ 'name': 'bar', + \ 'lsp': 'stdio', + \ 'executable': 'foo', + \ 'command': 'foo', + \ 'project_root_callback': {-> '/foo/bar'}, + \}) + let b:ale_linters = ['foo', 'bar'] + + " The cursor position needs to match what was saved before. + call setpos('.', [bufnr(''), 1, 5, 0]) + + call ale#completion#GetCompletions() + + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual 2, len(g:wait_callback_list) + AssertEqual 'completion', g:capability_checked + call map(g:wait_callback_list, 'v:val([347, ''/foo/bar''])') + + " We should only send one completion message for two LSP servers. + AssertEqual + \ [ + \ [1, 'textDocument/didChange', { + \ 'textDocument': { + \ 'uri': ale#path#ToURI(expand('%:p')), + \ 'version': g:ale_lsp_next_version_id - 1, + \ }, + \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}] + \ }], + \ [0, 'textDocument/completion', { + \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))}, + \ 'position': {'line': 0, 'character': 3}, + \ }], + \ ], + \ g:message_list diff --git a/test/completion/test_lsp_completion_parsing.vader b/test/completion/test_lsp_completion_parsing.vader index 736353e3..d5a45b54 100644 --- a/test/completion/test_lsp_completion_parsing.vader +++ b/test/completion/test_lsp_completion_parsing.vader @@ -430,10 +430,10 @@ Execute(Should handle Python completion results correctly): \ } \ }) -Execute(Should handle missing detail keys): +Execute(Should handle missing keys): AssertEqual \ [ - \ {'word': 'x', 'menu': '', 'info': 'y', 'kind': 'f', 'icase': 1}, + \ {'word': 'x', 'menu': '', 'info': '', 'kind': 'v', 'icase': 1}, \ ], \ ale#completion#ParseLSPCompletions({ \ 'jsonrpc': '2.0', @@ -443,8 +443,6 @@ Execute(Should handle missing detail keys): \ 'items': [ \ { \ 'label': 'x', - \ 'kind': 3, - \ 'documentation': 'y', \ }, \ ] \ } diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader index 80eda4a0..14206d8d 100644 --- a/test/fix/test_ale_fix.vader +++ b/test/fix/test_ale_fix.vader @@ -552,8 +552,6 @@ Execute(ale#fix#InitBufferData() should set up the correct data): AssertEqual { \ bufnr(''): { \ 'temporary_directory_list': [], - \ 'vars': b:, - \ 'filename': ale#path#Simplify(getcwd() . '/fix_test_file'), \ 'done': 0, \ 'lines_before': ['a', 'b', 'c'], \ 'should_save': 1, diff --git a/test/lsp/test_did_save_event.vader b/test/lsp/test_did_save_event.vader index b696ee4b..428135fb 100644 --- a/test/lsp/test_did_save_event.vader +++ b/test/lsp/test_did_save_event.vader @@ -14,7 +14,6 @@ Before: let g:ale_lsp_next_message_id = 1 let g:ale_run_synchronously = 1 let g:message_list = [] - let g:Callback = '' function! LanguageCallback() abort return 'foobar' @@ -34,9 +33,7 @@ Before: \ }) let g:ale_linters = {'foobar': ['dummy_linter']} - function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort - let g:Callback = a:callback - + function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:conn = ale#lsp#NewConnection({}) let l:conn.id = 347 let l:conn.open_documents = {a:buffer : -1} @@ -59,7 +56,6 @@ After: unlet! b:ale_enabled unlet! b:ale_linters - unlet! g:Callback unlet! g:message_list delfunction LanguageCallback diff --git a/test/lsp/test_lsp_command_formatting.vader b/test/lsp/test_lsp_command_formatting.vader index f436397f..9d2c84ee 100644 --- a/test/lsp/test_lsp_command_formatting.vader +++ b/test/lsp/test_lsp_command_formatting.vader @@ -23,15 +23,14 @@ Execute(Command formatting should be applied correctly for LSP linters): \ 'executable': has('win32') ? 'cmd': 'true', \ 'command': '%e --foo', \ }, - \ {->0} \) if has('win32') AssertEqual - \ ['cmd', 'cmd /s/c "cmd --foo"', '/foo/bar'], - \ g:args[:2] + \ ['cmd', 'cmd /s/c "cmd --foo"', {}], + \ g:args else AssertEqual - \ ['true', [&shell, '-c', '''true'' --foo'], '/foo/bar'], - \ g:args[:2] + \ ['true', [&shell, '-c', '''true'' --foo'], {}], + \ g:args endif diff --git a/test/lsp/test_lsp_connections.vader b/test/lsp/test_lsp_connections.vader index 8651d801..ae64eadb 100644 --- a/test/lsp/test_lsp_connections.vader +++ b/test/lsp/test_lsp_connections.vader @@ -2,6 +2,10 @@ Before: let g:ale_lsp_next_message_id = 1 After: + if exists('b:conn') && has_key(b:conn, 'id') + call ale#lsp#RemoveConnectionWithID(b:conn.id) + endif + unlet! b:data unlet! b:conn @@ -223,17 +227,20 @@ Execute(ale#lsp#ReadMessageData() should handle a message with part of a second \ ) Execute(Projects with regular project roots should be registered correctly): - let b:conn = {'projects': {}} - - call ale#lsp#RegisterProject(b:conn, '/foo/bar') + let b:conn = ale#lsp#NewConnection({}) + call ale#lsp#RegisterProject(b:conn.id, '/foo/bar') AssertEqual \ { - \ 'projects': { - \ '/foo/bar': {'initialized': 0, 'message_queue': [], 'init_request_id': 0}, + \ '/foo/bar': { + \ 'root': '/foo/bar', + \ 'initialized': 0, + \ 'message_queue': [], + \ 'capabilities_queue': [], + \ 'init_request_id': 0, \ }, \ }, - \ b:conn + \ b:conn.projects Execute(Projects with regular project roots should be fetched correctly): let b:conn = { @@ -247,17 +254,20 @@ Execute(Projects with regular project roots should be fetched correctly): \ ale#lsp#GetProject(b:conn, '/foo/bar') Execute(Projects with empty project roots should be registered correctly): - let b:conn = {'projects': {}} - - call ale#lsp#RegisterProject(b:conn, '') + let b:conn = ale#lsp#NewConnection({}) + call ale#lsp#RegisterProject(b:conn.id, '') AssertEqual \ { - \ 'projects': { - \ '<<EMPTY>>': {'initialized': 1, 'message_queue': [], 'init_request_id': 0}, + \ '<<EMPTY>>': { + \ 'root': '', + \ 'initialized': 1, + \ 'message_queue': [], + \ 'capabilities_queue': [], + \ 'init_request_id': 0, \ }, \ }, - \ b:conn + \ b:conn.projects Execute(Projects with empty project roots should be fetched correctly): let b:conn = { diff --git a/test/lsp/test_other_initialize_message_handling.vader b/test/lsp/test_other_initialize_message_handling.vader index f9567ee0..45457979 100644 --- a/test/lsp/test_other_initialize_message_handling.vader +++ b/test/lsp/test_other_initialize_message_handling.vader @@ -3,6 +3,7 @@ Before: \ 'initialized': 0, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \} let b:conn = { @@ -34,6 +35,7 @@ Execute(publishDiagnostics messages with files inside project directories should \ 'initialized': 0, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \ }, \ b:project @@ -47,6 +49,7 @@ Execute(publishDiagnostics messages with files inside project directories should \ 'initialized': 1, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \ }, \ b:project @@ -60,6 +63,7 @@ Execute(Messages with no method and capabilities should initialize projects): \ 'initialized': 1, \ 'init_request_id': 3, \ 'message_queue': [], + \ 'capabilities_queue': [], \ }, \ b:project @@ -120,6 +124,7 @@ Execute(Capabilities should bet set up correctly): \ '/foo/bar': { \ 'initialized': 1, \ 'message_queue': [], + \ 'capabilities_queue': [], \ 'init_request_id': 3, \ }, \ }, @@ -170,6 +175,7 @@ Execute(Disabled capabilities should be recognised correctly): \ '/foo/bar': { \ 'initialized': 1, \ 'message_queue': [], + \ 'capabilities_queue': [], \ 'init_request_id': 3, \ }, \ }, diff --git a/test/test_ale_var.vader b/test/test_ale_var.vader index 5f42fe95..419a9983 100644 --- a/test/test_ale_var.vader +++ b/test/test_ale_var.vader @@ -5,8 +5,6 @@ After: unlet! g:ale_some_variable unlet! b:undefined_variable_name - let g:ale_fix_buffer_data = {} - Execute(ale#Var should return global variables): AssertEqual 'abc', ale#Var(bufnr(''), 'some_variable') @@ -24,13 +22,3 @@ Execute(ale#Var should throw exceptions for undefined variables): let b:undefined_variable_name = 'def' AssertThrows call ale#Var(bufnr(''), 'undefined_variable_name') - -Execute(ale#Var return variables from deleted buffers, saved for fixing things): - let g:ale_fix_buffer_data[1347347] = {'vars': {'ale_some_variable': 'def'}} - - AssertEqual 'def', ale#Var(1347347, 'some_variable') - -Execute(ale#Var should return the global variable for unknown variables): - let g:ale_fix_buffer_data = {} - - AssertEqual 'abc', ale#Var(1347347, 'some_variable') diff --git a/test/test_find_references.vader b/test/test_find_references.vader index 150e0471..ecced068 100644 --- a/test/test_find_references.vader +++ b/test/test_find_references.vader @@ -3,20 +3,20 @@ Before: call ale#test#SetFilename('dummy.txt') let g:old_filename = expand('%:p') - let g:Callback = 0 + let g:Callback = '' let g:expr_list = [] let g:message_list = [] let g:preview_called = 0 let g:item_list = [] + let g:capability_checked = '' + let g:WaitCallback = v:null runtime autoload/ale/linter.vim runtime autoload/ale/lsp.vim runtime autoload/ale/util.vim runtime autoload/ale/preview.vim - function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort - let g:Callback = a:callback - + function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:conn = ale#lsp#NewConnection({}) let l:conn.id = 347 let l:conn.open_documents = {a:buffer : -1} @@ -29,6 +29,15 @@ Before: \} endfunction + function! ale#lsp#WaitForCapability(conn_id, project_root, capability, callback) abort + let g:capability_checked = a:capability + let g:WaitCallback = a:callback + endfunction + + function! ale#lsp#RegisterCallback(conn_id, callback) abort + let g:Callback = a:callback + endfunction + function! ale#lsp#Send(conn_id, message, root) abort call add(g:message_list, a:message) @@ -50,6 +59,8 @@ After: call ale#test#RestoreDirectory() call ale#linter#Reset() + unlet! g:capability_checked + unlet! g:WaitCallback unlet! g:old_filename unlet! g:Callback unlet! g:message_list @@ -152,6 +163,13 @@ Execute(tsserver reference requests should be sent): ALEFindReferences + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'references', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#references#HandleTSServerResponse'')', \ string(g:Callback) @@ -226,6 +244,13 @@ Execute(LSP reference requests should be sent): ALEFindReferences + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'references', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#references#HandleLSPResponse'')', \ string(g:Callback) diff --git a/test/test_go_to_definition.vader b/test/test_go_to_definition.vader index 749f4d7e..7f0e3fcb 100644 --- a/test/test_go_to_definition.vader +++ b/test/test_go_to_definition.vader @@ -3,17 +3,17 @@ Before: call ale#test#SetFilename('dummy.txt') let g:old_filename = expand('%:p') - let g:Callback = 0 + let g:Callback = '' let g:message_list = [] let g:expr_list = [] + let g:capability_checked = '' + let g:WaitCallback = v:null runtime autoload/ale/linter.vim runtime autoload/ale/lsp.vim runtime autoload/ale/util.vim - function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort - let g:Callback = a:callback - + function! ale#lsp_linter#StartLSP(buffer, linter) abort let l:conn = ale#lsp#NewConnection({}) let l:conn.id = 347 let l:conn.open_documents = {a:buffer : -1} @@ -26,6 +26,15 @@ Before: \} endfunction + function! ale#lsp#WaitForCapability(conn_id, project_root, capability, callback) abort + let g:capability_checked = a:capability + let g:WaitCallback = a:callback + endfunction + + function! ale#lsp#RegisterCallback(conn_id, callback) abort + let g:Callback = a:callback + endfunction + function! ale#lsp#Send(conn_id, message, root) abort call add(g:message_list, a:message) @@ -42,6 +51,8 @@ After: call ale#test#RestoreDirectory() call ale#linter#Reset() + unlet! g:capability_checked + unlet! g:WaitCallback unlet! g:old_filename unlet! g:Callback unlet! g:message_list @@ -137,6 +148,13 @@ Execute(tsserver completion requests should be sent): ALEGoToDefinition + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'definition', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#definition#HandleTSServerResponse'')', \ string(g:Callback) @@ -151,6 +169,13 @@ Execute(tsserver tab completion requests should be sent): ALEGoToDefinitionInTab + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'definition', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#definition#HandleTSServerResponse'')', \ string(g:Callback) @@ -276,6 +301,13 @@ Execute(LSP completion requests should be sent): ALEGoToDefinition + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'definition', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#definition#HandleLSPResponse'')', \ string(g:Callback) @@ -305,6 +337,13 @@ Execute(LSP tab completion requests should be sent): ALEGoToDefinitionInTab + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'definition', g:capability_checked + call call(g:WaitCallback, [347, '/foo/bar']) + AssertEqual \ 'function(''ale#definition#HandleLSPResponse'')', \ string(g:Callback) |