From a990188e276aad9410bc6fd1b627153fb279ffac Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 30 Nov 2017 10:34:51 +0000 Subject: [PATCH] Fix #1176 - Add an option for caching failing executable checks --- autoload/ale/engine.vim | 18 +++++++++++------- doc/ale.txt | 13 +++++++++++++ plugin/ale.vim | 4 ++++ test/test_ale_info.vader | 29 +++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 811b243..150b53c 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -32,16 +32,20 @@ function! ale#engine#IsExecutable(buffer, executable) abort return 0 endif - if has_key(s:executable_cache_map, a:executable) - return 1 + " Check for a cached executable() check. + let l:result = get(s:executable_cache_map, a:executable, v:null) + + if l:result isnot v:null + return l:result endif - let l:result = 0 + " Check if the file is executable, and convert -1 to 1. + let l:result = executable(a:executable) isnot 0 - if executable(a:executable) - let s:executable_cache_map[a:executable] = 1 - - let l:result = 1 + " Cache the executable check if we found it, or if the option to cache + " failing checks is on. + if l:result || g:ale_cache_executable_check_failures + let s:executable_cache_map[a:executable] = l:result endif if g:ale_history_enabled diff --git a/doc/ale.txt b/doc/ale.txt index 184912c..a4ec727 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -605,6 +605,19 @@ g:airline#extensions#ale#enabled *g:airline#extensions#ale#enabled* |airline#extensions#ale#warning_symbol|. +g:ale_cache_executable_check_failures *g:ale_cache_executable_check_failures* + + Type: |Number| + Default: `0` + + When set to `1`, ALE will cache failing executable checks for linters. By + default, only executable checks which succeed will be cached. + + When this option is set to `1`, Vim will have to be restarted after new + executables are installed for ALE to be able to run linters for those + executables. + + g:ale_change_sign_column_color *g:ale_change_sign_column_color* Type: |Number| diff --git a/plugin/ale.vim b/plugin/ale.vim index 8c97e39..a07915f 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -188,6 +188,10 @@ let g:ale_history_enabled = get(g:, 'ale_history_enabled', 1) " A flag for storing the full output of commands in the history. let g:ale_history_log_output = get(g:, 'ale_history_log_output', 1) +" A flag for caching failed executable checks. +" This is off by default, because it will cause problems. +call ale#Set('cache_executable_check_failures', 0) + " A dictionary mapping regular expression patterns to arbitrary buffer " variables to be set. Useful for configuration ALE based on filename " patterns. diff --git a/test/test_ale_info.vader b/test/test_ale_info.vader index 30237a3..2ca1834 100644 --- a/test/test_ale_info.vader +++ b/test/test_ale_info.vader @@ -2,9 +2,13 @@ Before: Save g:ale_warn_about_trailing_whitespace Save g:ale_linters Save g:ale_fixers + Save g:ale_lint_on_text_changed + Save g:ale_cache_executable_check_failures unlet! b:ale_history + let g:ale_lint_on_text_changed = 'always' + let g:ale_cache_executable_check_failures = 0 let g:ale_warn_about_trailing_whitespace = 1 let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout'} @@ -355,6 +359,31 @@ Execute (ALEInfo command history should print command output if logging is on): Execute (ALEInfo should include executable checks in the history): call ale#linter#Define('testft', g:testlinter1) call ale#engine#IsExecutable(bufnr(''), has('win32') ? 'cmd' : 'echo') + call ale#engine#IsExecutable(bufnr(''), has('win32') ? 'cmd' : 'echo') + call ale#engine#IsExecutable(bufnr(''), 'TheresNoWayThisIsExecutable') + call ale#engine#IsExecutable(bufnr(''), 'TheresNoWayThisIsExecutable') + + call CheckInfo([ + \ ' Current Filetype: testft.testft2', + \ 'Available Linters: [''testlinter1'']', + \ ' Enabled Linters: [''testlinter1'']', + \ ' Linter Variables:', + \ '', + \] + g:globals_lines + g:command_header + [ + \ '', + \ '(executable check - success) ' . (has('win32') ? 'cmd' : 'echo'), + \ '(executable check - failure) TheresNoWayThisIsExecutable', + \ '(executable check - failure) TheresNoWayThisIsExecutable', + \]) + +Execute (The option for caching failing executable checks should work): + let g:ale_cache_executable_check_failures = 1 + + call ale#linter#Define('testft', g:testlinter1) + + call ale#engine#IsExecutable(bufnr(''), has('win32') ? 'cmd' : 'echo') + call ale#engine#IsExecutable(bufnr(''), has('win32') ? 'cmd' : 'echo') + call ale#engine#IsExecutable(bufnr(''), 'TheresNoWayThisIsExecutable') call ale#engine#IsExecutable(bufnr(''), 'TheresNoWayThisIsExecutable') call CheckInfo([