From f2837b5802c14e0fcdddf1af7caab0fb96858589 Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 28 May 2018 19:19:20 +0100 Subject: [PATCH] #1524 - Define global variables where they are needed --- autoload/ale.vim | 15 +++--- autoload/ale/completion.vim | 4 +- autoload/ale/cursor.vim | 5 ++ autoload/ale/engine.vim | 5 +- autoload/ale/history.vim | 3 ++ autoload/ale/job.vim | 3 ++ autoload/ale/list.vim | 13 +++++ autoload/ale/pattern_options.vim | 5 ++ autoload/ale/sign.vim | 19 ++++++++ autoload/ale/statusline.vim | 6 +++ autoload/ale/toggle.vim | 7 +-- doc/ale.txt | 4 +- plugin/ale.vim | 81 ++------------------------------ test/test_ale_info.vader | 20 +++++--- test/test_lint_error_delay.vader | 2 +- 15 files changed, 90 insertions(+), 102 deletions(-) diff --git a/autoload/ale.vim b/autoload/ale.vim index 725a395..f31446c 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -2,6 +2,11 @@ " Description: Primary code path for the plugin " Manages execution of linters when requested by autocommands +" Strings used for severity in the echoed message +let g:ale_echo_msg_error_str = get(g:, 'ale_echo_msg_error_str', 'Error') +let g:ale_echo_msg_info_str = get(g:, 'ale_echo_msg_info_str', 'Info') +let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning') + let s:lint_timer = -1 let s:queued_buffer_number = -1 let s:should_lint_file_for_buffer = {} @@ -32,12 +37,8 @@ function! ale#CallWithCooldown(timestamp_key, func, arglist) abort endfunction " Return 1 if a file is too large for ALE to handle. -function! ale#FileTooLarge() abort - if !exists('g:ale_maximum_file_size') - return 0 - endif - - let l:max = ale#Var(bufnr(''), 'maximum_file_size') +function! ale#FileTooLarge(buffer) abort + let l:max = getbufvar(a:buffer, 'ale_maximum_file_size', get(g:, 'ale_maximum_file_size', 0)) return l:max > 0 ? (line2byte(line('$') + 1) > l:max) : 0 endfunction @@ -90,7 +91,7 @@ function! ale#ShouldDoNothing(buffer) abort endif " Do nothing if the file is too large. - if ale#FileTooLarge() + if ale#FileTooLarge(a:buffer) return 1 endif diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index a338ce7..6fa2619 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -1,7 +1,9 @@ " Author: w0rp " Description: Completion support for LSP linters -call ale#Set('completion_excluded_words', []) +let g:ale_completion_delay = get(g:, 'ale_completion_delay', 100) +let g:ale_completion_excluded_words = get(g:, 'ale_completion_excluded_words', []) +let g:ale_completion_max_suggestions = get(g:, 'ale_completion_max_suggestions', 50) let s:timer_id = -1 let s:last_done_pos = [] diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim index 50b1fb5..e3dd420 100644 --- a/autoload/ale/cursor.vim +++ b/autoload/ale/cursor.vim @@ -1,6 +1,11 @@ " Author: w0rp " Description: Echoes lint message for the current line, if any +" Controls the milliseconds delay before echoing a message. +let g:ale_echo_delay = get(g:, 'ale_echo_delay', 10) +" A string format for the echoed message. +let g:ale_echo_msg_format = get(g:, 'ale_echo_msg_format', '%code: %%s') + let s:cursor_timer = -1 let s:last_pos = [0, 0, 0] diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index f988d1b..b489c5f 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -2,6 +2,9 @@ " Description: Backend execution and job management " Executes linters in the background, using NeoVim or Vim 8 jobs +" Remapping of linter problems. +let g:ale_type_map = get(g:, 'ale_type_map', {}) + " Stores information for each job including: " " linter: The linter dictionary for the job. @@ -44,7 +47,7 @@ function! ale#engine#IsExecutable(buffer, executable) abort " 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 + if l:result || get(g:, 'ale_cache_executable_check_failures', 0) let s:executable_cache_map[a:executable] = l:result endif diff --git a/autoload/ale/history.vim b/autoload/ale/history.vim index a6282ea..27ae74c 100644 --- a/autoload/ale/history.vim +++ b/autoload/ale/history.vim @@ -1,6 +1,9 @@ " Author: w0rp " Description: Tools for managing command history +" A flag for controlling the maximum size of the command history to store. +let g:ale_max_buffer_history_size = get(g:, 'ale_max_buffer_history_size', 20) + " Return a shallow copy of the command history for a given buffer number. function! ale#history#Get(buffer) abort return copy(getbufvar(a:buffer, 'ale_history', [])) diff --git a/autoload/ale/job.vim b/autoload/ale/job.vim index 33040bb..6ffc2a0 100644 --- a/autoload/ale/job.vim +++ b/autoload/ale/job.vim @@ -8,6 +8,9 @@ " ale#job#IsRunning(job_id) -> 1 if running, 0 otherwise. " ale#job#Stop(job_id) +" A setting for wrapping commands. +let g:ale_command_wrapper = get(g:, 'ale_command_wrapper', '') + if !has_key(s:, 'job_map') let s:job_map = {} endif diff --git a/autoload/ale/list.vim b/autoload/ale/list.vim index 30b8f5c..35304a0 100644 --- a/autoload/ale/list.vim +++ b/autoload/ale/list.vim @@ -1,6 +1,19 @@ " Author: Bjorn Neergaard , modified by Yann fery " Description: Manages the loclist and quickfix lists +" This flag dictates if ale open the configured loclist +let g:ale_open_list = get(g:, 'ale_open_list', 0) +" This flag dictates if ale keeps open loclist even if there is no error in loclist +let g:ale_keep_list_window_open = get(g:, 'ale_keep_list_window_open', 0) +" This flag dictates that quickfix windows should be opened vertically +let g:ale_list_vertical = get(g:, 'ale_list_vertical', 0) +" The window size to set for the quickfix and loclist windows +let g:ale_list_window_size = get(g:, 'ale_list_window_size', 10) +" A string format for the loclist messages. +let g:ale_loclist_msg_format = get(g:, 'ale_loclist_msg_format', +\ get(g:, 'ale_echo_msg_format', '%code: %%s') +\) + if !exists('s:timer_args') let s:timer_args = {} endif diff --git a/autoload/ale/pattern_options.vim b/autoload/ale/pattern_options.vim index e58b8cf..c445a9e 100644 --- a/autoload/ale/pattern_options.vim +++ b/autoload/ale/pattern_options.vim @@ -1,6 +1,11 @@ " Author: w0rp " Description: Set options in files based on regex patterns. +" A dictionary mapping regular expression patterns to arbitrary buffer +" variables to be set. Useful for configuring ALE based on filename patterns. +let g:ale_pattern_options = get(g:, 'ale_pattern_options', {}) +let g:ale_pattern_options_enabled = get(g:, 'ale_pattern_options_enabled', !empty(g:ale_pattern_options)) + " These variables are used to cache the sorting of patterns below. let s:last_pattern_options = {} let s:sorted_items = [] diff --git a/autoload/ale/sign.vim b/autoload/ale/sign.vim index d1139c0..3166372 100644 --- a/autoload/ale/sign.vim +++ b/autoload/ale/sign.vim @@ -2,6 +2,25 @@ scriptencoding utf8 " Author: w0rp " Description: Draws error and warning signs into signcolumn +" This flag can be set to some integer to control the maximum number of signs +" that ALE will set. +let g:ale_max_signs = get(g:, 'ale_max_signs', -1) +" This flag can be set to 1 to enable changing the sign column colors when +" there are errors. +let g:ale_change_sign_column_color = get(g:, 'ale_change_sign_column_color', 0) +" These variables dictate what signs are used to indicate errors and warnings. +let g:ale_sign_error = get(g:, 'ale_sign_error', '>>') +let g:ale_sign_style_error = get(g:, 'ale_sign_style_error', g:ale_sign_error) +let g:ale_sign_warning = get(g:, 'ale_sign_warning', '--') +let g:ale_sign_style_warning = get(g:, 'ale_sign_style_warning', g:ale_sign_warning) +let g:ale_sign_info = get(g:, 'ale_sign_info', g:ale_sign_warning) +" This variable sets an offset which can be set for sign IDs. +" This ID can be changed depending on what IDs are set for other plugins. +" The dummy sign will use the ID exactly equal to the offset. +let g:ale_sign_offset = get(g:, 'ale_sign_offset', 1000000) +" This flag can be set to 1 to keep sign gutter always open +let g:ale_sign_column_always = get(g:, 'ale_sign_column_always', 0) + if !hlexists('ALEErrorSign') highlight link ALEErrorSign error endif diff --git a/autoload/ale/statusline.vim b/autoload/ale/statusline.vim index 3f53368..368cdd7 100644 --- a/autoload/ale/statusline.vim +++ b/autoload/ale/statusline.vim @@ -1,6 +1,12 @@ " Author: KabbAmine " Description: Statusline related function(s) +" A deprecated setting for ale#statusline#Status() +" See :help ale#statusline#Count() for getting status reports. +let g:ale_statusline_format = get(g:, 'ale_statusline_format', +\ ['%d error(s)', '%d warning(s)', 'OK'] +\) + function! s:CreateCountDict() abort " Keys 0 and 1 are for backwards compatibility. " The count object used to be a List of [error_count, warning_count]. diff --git a/autoload/ale/toggle.vim b/autoload/ale/toggle.vim index 1f69154..d8472cd 100644 --- a/autoload/ale/toggle.vim +++ b/autoload/ale/toggle.vim @@ -1,6 +1,6 @@ function! s:EnablePreamble() abort " Set pattern options again, if enabled. - if g:ale_pattern_options_enabled + if get(g:, 'ale_pattern_options_enabled', 0) call ale#pattern_options#SetOptions(bufnr('')) endif @@ -53,11 +53,6 @@ endfunction function! ale#toggle#Enable() abort if !g:ale_enabled - " Set pattern options again, if enabled. - if g:ale_pattern_options_enabled - call ale#pattern_options#SetOptions(bufnr('')) - endif - call ale#toggle#Toggle() endif endfunction diff --git a/doc/ale.txt b/doc/ale.txt index 25895f3..0bf1c84 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -686,7 +686,7 @@ g:airline#extensions#ale#enabled *g:airline#extensions#ale#enabled* g:ale_cache_executable_check_failures *g:ale_cache_executable_check_failures* Type: |Number| - Default: `0` + Default: undefined When set to `1`, ALE will cache failing executable checks for linters. By default, only executable checks which succeed will be cached. @@ -1259,7 +1259,7 @@ g:ale_max_signs *g:ale_max_signs* g:ale_maximum_file_size *g:ale_maximum_file_size* *b:ale_maximum_file_size* Type: |Number| - Default: `0` + Default: undefined A maximum file size in bytes for ALE to check. If set to any positive number, ALE will skip checking files larger than the given size. diff --git a/plugin/ale.vim b/plugin/ale.vim index 980a6bb..997a196 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -96,6 +96,7 @@ 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 automatically fixing files on save. let g:ale_fix_on_save = get(g:, 'ale_fix_on_save', 0) " This flag may be set to 0 to disable ale. After ale is loaded, :ALEToggle @@ -107,72 +108,20 @@ let g:ale_enabled = get(g:, 'ale_enabled', 1) let g:ale_set_loclist = get(g:, 'ale_set_loclist', 1) let g:ale_set_quickfix = get(g:, 'ale_set_quickfix', 0) -" This flag dictates if ale open the configured loclist -let g:ale_open_list = get(g:, 'ale_open_list', 0) - -" This flag dictates if ale keeps open loclist even if there is no error in loclist -let g:ale_keep_list_window_open = get(g:, 'ale_keep_list_window_open', 0) - -" This flag dictates that quickfix windows should be opened vertically -let g:ale_list_vertical = get(g:, 'ale_list_vertical', 0) - -" The window size to set for the quickfix and loclist windows -let g:ale_list_window_size = get(g:, 'ale_list_window_size', 10) - " This flag can be set to 0 to disable setting signs. " This is enabled by default only if the 'signs' feature exists. let g:ale_set_signs = get(g:, 'ale_set_signs', has('signs')) -" This flag can be set to some integer to control the maximum number of signs -" that ALE will set. -let g:ale_max_signs = get(g:, 'ale_max_signs', -1) - -" This flag can be set to 1 to enable changing the sign column colors when -" there are errors. -let g:ale_change_sign_column_color = get(g:, 'ale_change_sign_column_color', 0) " This flag can be set to 0 to disable setting error highlights. let g:ale_set_highlights = get(g:, 'ale_set_highlights', has('syntax')) -" These variables dictate what sign is used to indicate errors and warnings. -let g:ale_sign_error = get(g:, 'ale_sign_error', '>>') -let g:ale_sign_style_error = get(g:, 'ale_sign_style_error', g:ale_sign_error) -let g:ale_sign_warning = get(g:, 'ale_sign_warning', '--') -let g:ale_sign_style_warning = get(g:, 'ale_sign_style_warning', g:ale_sign_warning) -let g:ale_sign_info = get(g:, 'ale_sign_info', g:ale_sign_warning) - -" This variable sets an offset which can be set for sign IDs. -" This ID can be changed depending on what IDs are set for other plugins. -" The dummy sign will use the ID exactly equal to the offset. -let g:ale_sign_offset = get(g:, 'ale_sign_offset', 1000000) - -" This flag can be set to 1 to keep sign gutter always open -let g:ale_sign_column_always = get(g:, 'ale_sign_column_always', 0) - -" A string format for the echoed message -let g:ale_echo_msg_format = get(g:, 'ale_echo_msg_format', '%code: %%s') -" The same for the loclist. -let g:ale_loclist_msg_format = get(g:, 'ale_loclist_msg_format', g:ale_echo_msg_format) - -" Strings used for severity in the echoed message -let g:ale_echo_msg_error_str = get(g:, 'ale_echo_msg_error_str', 'Error') -let g:ale_echo_msg_info_str = get(g:, 'ale_echo_msg_info_str', 'Info') -let g:ale_echo_msg_warning_str = get(g:, 'ale_echo_msg_warning_str', 'Warning') - " This flag can be set to 0 to disable echoing when the cursor moves. let g:ale_echo_cursor = get(g:, 'ale_echo_cursor', 1) -" Controls the milliseconds delay before echoing a message. -let g:ale_echo_delay = get(g:, 'ale_echo_delay', 10) " This flag can be set to 0 to disable balloon support. let g:ale_set_balloons = get(g:, 'ale_set_balloons', -\ has('balloon_eval') && has('gui_running') || -\ has('balloon_eval_term') && !has('gui_running') -\) - -" A deprecated setting for ale#statusline#Status() -" See :help ale#statusline#Count() for getting status reports. -let g:ale_statusline_format = get(g:, 'ale_statusline_format', -\ ['%d error(s)', '%d warning(s)', 'OK'] +\ (has('balloon_eval') && has('gui_running')) +\ || (has('balloon_eval_term') && !has('gui_running')) \) " This flag can be set to 0 to disable warnings for trailing whitespace @@ -180,38 +129,14 @@ let g:ale_warn_about_trailing_whitespace = get(g:, 'ale_warn_about_trailing_whit " This flag can be set to 0 to disable warnings for trailing blank lines let g:ale_warn_about_trailing_blank_lines = get(g:, 'ale_warn_about_trailing_blank_lines', 1) -" A flag for controlling the maximum size of the command history to store. -let g:ale_max_buffer_history_size = get(g:, 'ale_max_buffer_history_size', 20) - " A flag for enabling or disabling the command history. 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. -let g:ale_cache_executable_check_failures = get(g:, 'ale_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. -let g:ale_pattern_options = get(g:, 'ale_pattern_options', {}) -let g:ale_pattern_options_enabled = get(g:, 'ale_pattern_options_enabled', !empty(g:ale_pattern_options)) - -" A maximum file size for checking for errors. -let g:ale_maximum_file_size = get(g:, 'ale_maximum_file_size', 0) - -" Remapping of linter problems. -let g:ale_type_map = get(g:, 'ale_type_map', {}) - " Enable automatic completion with LSP servers and tsserver let g:ale_completion_enabled = get(g:, 'ale_completion_enabled', 0) -let g:ale_completion_delay = get(g:, 'ale_completion_delay', 100) -let g:ale_completion_max_suggestions = get(g:, 'ale_completion_max_suggestions', 50) - -" A setting for wrapping commands. -let g:ale_command_wrapper = get(g:, 'ale_command_wrapper', '') if g:ale_set_balloons call ale#balloon#Enable() diff --git a/test/test_ale_info.vader b/test/test_ale_info.vader index 16c04b7..7507860 100644 --- a/test/test_ale_info.vader +++ b/test/test_ale_info.vader @@ -1,43 +1,51 @@ Before: Save g:ale_buffer_info Save g:ale_cache_executable_check_failures + Save g:ale_completion_delay Save g:ale_completion_enabled + Save g:ale_completion_max_suggestions Save g:ale_fixers Save g:ale_history_log_output Save g:ale_lint_on_insert_leave Save g:ale_lint_on_text_changed Save g:ale_linters + Save g:ale_lsp_error_messages Save g:ale_maximum_file_size Save g:ale_pattern_options Save g:ale_pattern_options_enabled Save g:ale_set_balloons - Save g:ale_warn_about_trailing_whitespace Save g:ale_sign_error - Save g:ale_sign_warning Save g:ale_sign_info Save g:ale_sign_style_error Save g:ale_sign_style_warning - Save g:ale_lsp_error_messages + Save g:ale_sign_warning + Save g:ale_statusline_format + Save g:ale_type_map + Save g:ale_warn_about_trailing_whitespace unlet! b:ale_history let g:ale_buffer_info = {} let g:ale_cache_executable_check_failures = 0 + let g:ale_completion_delay = 100 let g:ale_completion_enabled = 0 + let g:ale_completion_max_suggestions = 50 let g:ale_history_log_output = 1 let g:ale_lint_on_insert_leave = 0 let g:ale_lint_on_text_changed = 'always' + let g:ale_lsp_error_messages = {} let g:ale_maximum_file_size = 0 let g:ale_pattern_options = {} let g:ale_pattern_options_enabled = 0 let g:ale_set_balloons = 0 - let g:ale_warn_about_trailing_whitespace = 1 let g:ale_sign_error = '>>' - let g:ale_sign_warning = '--' let g:ale_sign_info = '--' let g:ale_sign_style_error = '>>' let g:ale_sign_style_warning = '--' - let g:ale_lsp_error_messages = {} + let g:ale_sign_warning = '--' + let g:ale_statusline_format = ['%d error(s)', '%d warning(s)', 'OK'] + let g:ale_type_map = {} + let g:ale_warn_about_trailing_whitespace = 1 let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout'} let g:testlinter2 = {'name': 'testlinter2', 'executable': 'testlinter2', 'command': 'testlinter2', 'callback': 'testCB2', 'output_stream': 'stdout'} diff --git a/test/test_lint_error_delay.vader b/test/test_lint_error_delay.vader index d539708..cf73b2c 100644 --- a/test/test_lint_error_delay.vader +++ b/test/test_lint_error_delay.vader @@ -2,7 +2,7 @@ Before: runtime autoload/ale.vim " Replace one of the key ALE functions and make it throw. - function! ale#FileTooLarge() abort + function! ale#FileTooLarge(buffer) abort throw 'broken' endfunction