diff options
author | Ben Boeckel <mathstuf@users.noreply.github.com> | 2023-01-29 17:25:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-29 17:25:09 +0000 |
commit | 116d713f63c7a81663fa53efa10e34649c9479e3 (patch) | |
tree | 0ca5ed37b4320e70901de6b9bcafee53c259a2aa /autoload | |
parent | 0af4899605af26dd8ea7fe79acff6ab99f6532b2 (diff) | |
download | ale-116d713f63c7a81663fa53efa10e34649c9479e3.zip |
diagnostics: support sending ALE output to Neovim's diagnostics API (#4345)
Support replacing ALE's display of problems with sending problems to the Neovim diagnostics API.
:help g:ale_use_neovim_diagnostics_api
Co-authored-by: David Balatero <dbalatero@users.noreply.github.com>
Co-authored-by: Georgi Angelchev <angelchev@live.co.uk>
Co-authored-by: w0rp <devw0rp@gmail.com>
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/debugging.vim | 1 | ||||
-rw-r--r-- | autoload/ale/engine.vim | 27 | ||||
-rw-r--r-- | autoload/ale/virtualtext.vim | 11 |
3 files changed, 29 insertions, 10 deletions
diff --git a/autoload/ale/debugging.vim b/autoload/ale/debugging.vim index 31f3078c..c100d6e6 100644 --- a/autoload/ale/debugging.vim +++ b/autoload/ale/debugging.vim @@ -55,6 +55,7 @@ let s:global_variable_list = [ \ 'ale_sign_highlight_linenrs', \ 'ale_statusline_format', \ 'ale_type_map', +\ 'ale_use_neovim_diagnostics_api', \ 'ale_use_global_executables', \ 'ale_virtualtext_cursor', \ 'ale_warn_about_trailing_blank_lines', diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 150bbc82..185d54db 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -184,9 +184,13 @@ endfunction function! ale#engine#SetResults(buffer, loclist) abort let l:linting_is_done = !ale#engine#IsCheckingBuffer(a:buffer) + if g:ale_use_neovim_diagnostics_api + call ale#engine#SendResultsToNeovimDiagnostics(a:buffer, a:loclist) + endif + " Set signs first. This could potentially fix some line numbers. " The List could be sorted again here by SetSigns. - if g:ale_set_signs + if !g:ale_use_neovim_diagnostics_api && g:ale_set_signs call ale#sign#SetSigns(a:buffer, a:loclist) endif @@ -199,11 +203,12 @@ function! ale#engine#SetResults(buffer, loclist) abort call ale#statusline#Update(a:buffer, a:loclist) endif - if g:ale_set_highlights + if !g:ale_use_neovim_diagnostics_api && g:ale_set_highlights call ale#highlight#SetHighlights(a:buffer, a:loclist) endif - if g:ale_virtualtext_cursor is# 'all' || g:ale_virtualtext_cursor == 2 + if !g:ale_use_neovim_diagnostics_api + \&& (g:ale_virtualtext_cursor is# 'all' || g:ale_virtualtext_cursor == 2) call ale#virtualtext#SetTexts(a:buffer, a:loclist) endif @@ -214,7 +219,8 @@ function! ale#engine#SetResults(buffer, loclist) abort call ale#cursor#EchoCursorWarning() endif - if g:ale_virtualtext_cursor is# 'current' || g:ale_virtualtext_cursor == 1 + if !g:ale_use_neovim_diagnostics_api + \&& (g:ale_virtualtext_cursor is# 'current' || g:ale_virtualtext_cursor == 1) " Try and show the warning now. " This will only do something meaningful if we're in normal mode. call ale#virtualtext#ShowCursorWarning() @@ -238,6 +244,19 @@ function! ale#engine#SetResults(buffer, loclist) abort endif endfunction +function! ale#engine#SendResultsToNeovimDiagnostics(buffer, loclist) abort + if !has('nvim-0.6') + " We will warn the user on startup as well if they try to set + " g:ale_use_neovim_diagnostics_api outside of a Neovim context. + return + endif + + " Keep the Lua surface area really small in the VimL part of ALE, + " and just require the diagnostics.lua module on demand. + let l:SendDiagnostics = luaeval('require("diagnostics").sendAleResultsToDiagnostics') + call l:SendDiagnostics(a:buffer, a:loclist) +endfunction + function! s:RemapItemTypes(type_map, loclist) abort for l:item in a:loclist let l:key = l:item.type diff --git a/autoload/ale/virtualtext.vim b/autoload/ale/virtualtext.vim index 0f2b2173..4897154b 100644 --- a/autoload/ale/virtualtext.vim +++ b/autoload/ale/virtualtext.vim @@ -187,10 +187,8 @@ function! ale#virtualtext#ShowCursorWarning(...) abort let l:buffer = bufnr('') if mode(1) isnot# 'n' - return - endif - - if ale#ShouldDoNothing(l:buffer) + \|| g:ale_use_neovim_diagnostics_api + \|| ale#ShouldDoNothing(l:buffer) return endif @@ -210,12 +208,13 @@ function! ale#virtualtext#ShowCursorWarningWithDelay() abort return endif + call s:StopCursorTimer() + if mode(1) isnot# 'n' + \|| g:ale_use_neovim_diagnostics_api return endif - call s:StopCursorTimer() - let l:pos = getpos('.')[0:2] " Check the current buffer, line, and column number against the last |