From ebbbeacfdb5c68b7bcce824280aa4c24943eebe5 Mon Sep 17 00:00:00 2001 From: Andrey Popp <8mayday@gmail.com> Date: Sun, 12 May 2019 12:55:44 +0300 Subject: [PATCH] Lint on FocusGained/VimResume This commits allow to configure ALE to lint when vim gains focus or is resumed after being suspended (C-z and then `fg` command). Not that for this to work with tmux one must set ``` set -g focus-events on ``` in their `tmux.conf`. --- autoload/ale/events.vim | 18 ++++++++++++++++++ autoload/ale/lsp.vim | 4 +++- plugin/ale.vim | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/autoload/ale/events.vim b/autoload/ale/events.vim index c3dbd37890..1f0864bc0e 100644 --- a/autoload/ale/events.vim +++ b/autoload/ale/events.vim @@ -92,6 +92,11 @@ function! ale#events#FileChangedEvent(buffer) abort endif endfunction +function! ale#events#FocusGained(buffer) abort + call setbufvar(a:buffer, 'force_changedtick', 1) + call ale#Queue(0, 'lint_file', a:buffer) +endfunction + function! ale#events#Init() abort " This value used to be a Boolean as a Number, and is now a String. let l:text_changed = '' . g:ale_lint_on_text_changed @@ -127,6 +132,19 @@ function! ale#events#Init() abort \) endif + if g:ale_lint_on_focus_gained + if exists('##FocusGained') + autocmd FocusGained * call ale#events#FocusGained( + \ str2nr(expand('')) + \) + endif + if exists('##VimResume') + autocmd VimResume * call ale#events#FocusGained( + \ str2nr(expand('')) + \) + endif + endif + if g:ale_lint_on_insert_leave autocmd InsertLeave * call ale#Queue(0) endif diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim index 7186d2a9d7..3fcc7b83f8 100644 --- a/autoload/ale/lsp.vim +++ b/autoload/ale/lsp.vim @@ -492,8 +492,10 @@ function! ale#lsp#NotifyForChanges(conn_id, buffer) abort if !empty(l:conn) && has_key(l:conn.open_documents, a:buffer) let l:new_tick = getbufvar(a:buffer, 'changedtick') + let l:force = getbufvar(a:buffer, 'force_changedtick', 0) - if l:conn.open_documents[a:buffer] < l:new_tick + if l:conn.open_documents[a:buffer] < l:new_tick || l:force + call setbufvar(a:buffer, 'force_changedtick', 0) if l:conn.is_tsserver let l:message = ale#lsp#tsserver_message#Change(a:buffer) else diff --git a/plugin/ale.vim b/plugin/ale.vim index cf39d6328e..5372bbc962 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -87,6 +87,9 @@ let g:ale_lint_on_save = get(g:, 'ale_lint_on_save', 1) " This flag can be set to 1 to enable linting when the filetype is changed. let g:ale_lint_on_filetype_changed = get(g:, 'ale_lint_on_filetype_changed', 1) +" This flag can be set to 1 to enable linting when vim gains focus. +let g:ale_lint_on_focus_gained = get(g:, 'ale_lint_on_focus_gained', 1) + " This Dictionary configures the default LSP roots for various linters. let g:ale_lsp_root = get(g:, 'ale_lsp_root', {})