mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-10 13:32:34 +08:00
Merge branch 'master' into dhall
This commit is contained in:
@@ -100,13 +100,7 @@ function! s:Lint(buffer, should_lint_file, timer_id) abort
|
||||
" Use the filetype from the buffer
|
||||
let l:filetype = getbufvar(a:buffer, '&filetype')
|
||||
let l:linters = ale#linter#Get(l:filetype)
|
||||
|
||||
" Apply ignore lists for linters only if needed.
|
||||
let l:ignore_config = ale#Var(a:buffer, 'linters_ignore')
|
||||
let l:disable_lsp = ale#Var(a:buffer, 'disable_lsp')
|
||||
let l:linters = !empty(l:ignore_config) || l:disable_lsp
|
||||
\ ? ale#engine#ignore#Exclude(l:filetype, l:linters, l:ignore_config, l:disable_lsp)
|
||||
\ : l:linters
|
||||
let l:linters = ale#linter#RemoveIgnored(a:buffer, l:filetype, l:linters)
|
||||
|
||||
" Tell other sources that they can start checking the buffer now.
|
||||
let g:ale_want_results_buffer = a:buffer
|
||||
@@ -163,7 +157,7 @@ function! ale#Queue(delay, ...) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:current_ale_version = [2, 7, 0]
|
||||
let s:current_ale_version = [3, 0, 0]
|
||||
|
||||
" A function used to check for ALE features in files outside of the project.
|
||||
function! ale#Has(feature) abort
|
||||
|
||||
@@ -503,17 +503,19 @@ function! ale#completion#ParseTSServerCompletionEntryDetails(response) abort
|
||||
\ || g:ale_completion_autoimport,
|
||||
\ 'info': join(l:documentationParts, ''),
|
||||
\}
|
||||
" This flag is used to tell if this completion came from ALE or not.
|
||||
let l:user_data = {'_ale_completion_item': 1}
|
||||
|
||||
if has_key(l:suggestion, 'codeActions')
|
||||
let l:result.user_data = json_encode({
|
||||
\ 'codeActions': l:suggestion.codeActions,
|
||||
\ })
|
||||
let l:user_data.code_actions = l:suggestion.codeActions
|
||||
endif
|
||||
|
||||
let l:result.user_data = json_encode(l:user_data)
|
||||
|
||||
" Include this item if we'll accept any items,
|
||||
" or if we only want items with additional edits, and this has them.
|
||||
if !get(l:info, 'additional_edits_only', 0)
|
||||
\|| has_key(l:result, 'user_data')
|
||||
\|| has_key(l:user_data, 'code_actions')
|
||||
call add(l:results, l:result)
|
||||
endif
|
||||
endfor
|
||||
@@ -534,6 +536,7 @@ function! ale#completion#ParseTSServerCompletionEntryDetails(response) abort
|
||||
\ 'icase': 1,
|
||||
\ 'menu': '',
|
||||
\ 'info': '',
|
||||
\ 'user_data': json_encode({'_ale_completion_item': 1}),
|
||||
\})
|
||||
endfor
|
||||
endif
|
||||
@@ -610,6 +613,8 @@ function! ale#completion#ParseLSPCompletions(response) abort
|
||||
\ 'menu': get(l:item, 'detail', ''),
|
||||
\ 'info': (type(l:doc) is v:t_string ? l:doc : ''),
|
||||
\}
|
||||
" This flag is used to tell if this completion came from ALE or not.
|
||||
let l:user_data = {'_ale_completion_item': 1}
|
||||
|
||||
if has_key(l:item, 'additionalTextEdits')
|
||||
let l:text_changes = []
|
||||
@@ -629,24 +634,24 @@ function! ale#completion#ParseLSPCompletions(response) abort
|
||||
endfor
|
||||
|
||||
if !empty(l:text_changes)
|
||||
let l:result.user_data = json_encode({
|
||||
\ 'codeActions': [{
|
||||
\ 'description': 'completion',
|
||||
\ 'changes': [
|
||||
\ {
|
||||
\ 'fileName': expand('#' . l:buffer . ':p'),
|
||||
\ 'textChanges': l:text_changes,
|
||||
\ }
|
||||
\ ],
|
||||
\ }],
|
||||
\})
|
||||
let l:user_data.code_actions = [{
|
||||
\ 'description': 'completion',
|
||||
\ 'changes': [
|
||||
\ {
|
||||
\ 'fileName': expand('#' . l:buffer . ':p'),
|
||||
\ 'textChanges': l:text_changes,
|
||||
\ },
|
||||
\ ],
|
||||
\}]
|
||||
endif
|
||||
endif
|
||||
|
||||
let l:result.user_data = json_encode(l:user_data)
|
||||
|
||||
" Include this item if we'll accept any items,
|
||||
" or if we only want items with additional edits, and this has them.
|
||||
if !get(l:info, 'additional_edits_only', 0)
|
||||
\|| has_key(l:result, 'user_data')
|
||||
\|| has_key(l:user_data, 'code_actions')
|
||||
call add(l:results, l:result)
|
||||
endif
|
||||
endfor
|
||||
@@ -983,30 +988,29 @@ function! ale#completion#Queue() abort
|
||||
endfunction
|
||||
|
||||
function! ale#completion#HandleUserData(completed_item) abort
|
||||
let l:source = get(get(b:, 'ale_completion_info', {}), 'source', '')
|
||||
|
||||
if l:source isnot# 'ale-automatic'
|
||||
\&& l:source isnot# 'ale-manual'
|
||||
\&& l:source isnot# 'ale-callback'
|
||||
\&& l:source isnot# 'ale-import'
|
||||
return
|
||||
endif
|
||||
|
||||
let l:user_data_json = get(a:completed_item, 'user_data', '')
|
||||
|
||||
if empty(l:user_data_json)
|
||||
return
|
||||
endif
|
||||
|
||||
let l:user_data = json_decode(l:user_data_json)
|
||||
let l:user_data = !empty(l:user_data_json)
|
||||
\ ? json_decode(l:user_data_json)
|
||||
\ : v:null
|
||||
|
||||
if type(l:user_data) isnot v:t_dict
|
||||
\|| get(l:user_data, '_ale_completion_item', 0) isnot 1
|
||||
return
|
||||
endif
|
||||
|
||||
for l:code_action in get(l:user_data, 'codeActions', [])
|
||||
call ale#code_action#HandleCodeAction(l:code_action, v:false)
|
||||
endfor
|
||||
let l:source = get(get(b:, 'ale_completion_info', {}), 'source', '')
|
||||
|
||||
if l:source is# 'ale-automatic'
|
||||
\|| l:source is# 'ale-manual'
|
||||
\|| l:source is# 'ale-callback'
|
||||
\|| l:source is# 'ale-import'
|
||||
\|| l:source is# 'ale-omnifunc'
|
||||
for l:code_action in get(l:user_data, 'code_actions', [])
|
||||
call ale#code_action#HandleCodeAction(l:code_action, v:false)
|
||||
endfor
|
||||
endif
|
||||
|
||||
silent doautocmd <nomodeline> User ALECompletePost
|
||||
endfunction
|
||||
|
||||
function! ale#completion#Done() abort
|
||||
|
||||
@@ -8,6 +8,7 @@ let s:global_variable_list = [
|
||||
\ 'ale_completion_delay',
|
||||
\ 'ale_completion_enabled',
|
||||
\ 'ale_completion_max_suggestions',
|
||||
\ 'ale_disable_lsp',
|
||||
\ 'ale_echo_cursor',
|
||||
\ 'ale_echo_msg_error_str',
|
||||
\ 'ale_echo_msg_format',
|
||||
@@ -28,6 +29,7 @@ let s:global_variable_list = [
|
||||
\ 'ale_linter_aliases',
|
||||
\ 'ale_linters',
|
||||
\ 'ale_linters_explicit',
|
||||
\ 'ale_linters_ignore',
|
||||
\ 'ale_list_vertical',
|
||||
\ 'ale_list_window_size',
|
||||
\ 'ale_loclist_msg_format',
|
||||
@@ -196,6 +198,7 @@ function! s:EchoLSPErrorMessages(all_linter_names) abort
|
||||
endfunction
|
||||
|
||||
function! ale#debugging#Info() abort
|
||||
let l:buffer = bufnr('')
|
||||
let l:filetype = &filetype
|
||||
|
||||
" We get the list of enabled linters for free by the above function.
|
||||
@@ -222,10 +225,20 @@ function! ale#debugging#Info() abort
|
||||
let l:fixers = uniq(sort(l:fixers[0] + l:fixers[1]))
|
||||
let l:fixers_string = join(map(copy(l:fixers), '"\n " . v:val'), '')
|
||||
|
||||
let l:non_ignored_names = map(
|
||||
\ copy(ale#linter#RemoveIgnored(l:buffer, l:filetype, l:enabled_linters)),
|
||||
\ 'v:val[''name'']',
|
||||
\)
|
||||
let l:ignored_names = filter(
|
||||
\ copy(l:enabled_names),
|
||||
\ 'index(l:non_ignored_names, v:val) < 0'
|
||||
\)
|
||||
|
||||
call s:Echo(' Current Filetype: ' . l:filetype)
|
||||
call s:Echo('Available Linters: ' . string(l:all_names))
|
||||
call s:EchoLinterAliases(l:all_linters)
|
||||
call s:Echo(' Enabled Linters: ' . string(l:enabled_names))
|
||||
call s:Echo(' Ignored Linters: ' . string(l:ignored_names))
|
||||
call s:Echo(' Suggested Fixers: ' . l:fixers_string)
|
||||
call s:Echo(' Linter Variables:')
|
||||
call s:Echo('')
|
||||
|
||||
@@ -444,7 +444,7 @@ function! s:RunJob(command, options) abort
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:StopCurrentJobs(buffer, clear_lint_file_jobs) abort
|
||||
function! s:StopCurrentJobs(buffer, clear_lint_file_jobs, linter_slots) abort
|
||||
let l:info = get(g:ale_buffer_info, a:buffer, {})
|
||||
call ale#command#StopJobs(a:buffer, 'linter')
|
||||
|
||||
@@ -453,11 +453,25 @@ function! s:StopCurrentJobs(buffer, clear_lint_file_jobs) abort
|
||||
call ale#command#StopJobs(a:buffer, 'file_linter')
|
||||
let l:info.active_linter_list = []
|
||||
else
|
||||
let l:lint_file_map = {}
|
||||
|
||||
" Use a previously computed map of `lint_file` values to find
|
||||
" linters that are used for linting files.
|
||||
for [l:lint_file, l:linter] in a:linter_slots
|
||||
if l:lint_file is 1
|
||||
let l:lint_file_map[l:linter.name] = 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Keep jobs for linting files when we're only linting buffers.
|
||||
call filter(l:info.active_linter_list, 'get(v:val, ''lint_file'')')
|
||||
call filter(l:info.active_linter_list, 'get(l:lint_file_map, v:val.name)')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#engine#Stop(buffer) abort
|
||||
call s:StopCurrentJobs(a:buffer, 1, [])
|
||||
endfunction
|
||||
|
||||
function! s:RemoveProblemsForDisabledLinters(buffer, linters) abort
|
||||
" Figure out which linters are still enabled, and remove
|
||||
" problems for linters which are no longer enabled.
|
||||
@@ -558,6 +572,22 @@ function! s:RunLinter(buffer, linter, lint_file) abort
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:GetLintFileSlots(buffer, linters) abort
|
||||
let l:linter_slots = []
|
||||
|
||||
for l:linter in a:linters
|
||||
let l:LintFile = l:linter.lint_file
|
||||
|
||||
if type(l:LintFile) is v:t_func
|
||||
let l:LintFile = l:LintFile(a:buffer)
|
||||
endif
|
||||
|
||||
call add(l:linter_slots, [l:LintFile, l:linter])
|
||||
endfor
|
||||
|
||||
return l:linter_slots
|
||||
endfunction
|
||||
|
||||
function! s:GetLintFileValues(slots, Callback) abort
|
||||
let l:deferred_list = []
|
||||
let l:new_slots = []
|
||||
@@ -591,12 +621,18 @@ endfunction
|
||||
|
||||
function! s:RunLinters(
|
||||
\ buffer,
|
||||
\ linters,
|
||||
\ slots,
|
||||
\ should_lint_file,
|
||||
\ new_buffer,
|
||||
\ can_clear_results
|
||||
\) abort
|
||||
let l:can_clear_results = a:can_clear_results
|
||||
call s:StopCurrentJobs(a:buffer, a:should_lint_file, a:slots)
|
||||
call s:RemoveProblemsForDisabledLinters(a:buffer, a:linters)
|
||||
|
||||
" We can only clear the results if we aren't checking the buffer.
|
||||
let l:can_clear_results = !ale#engine#IsCheckingBuffer(a:buffer)
|
||||
|
||||
silent doautocmd <nomodeline> User ALELintPre
|
||||
|
||||
for [l:lint_file, l:linter] in a:slots
|
||||
" Only run lint_file linters if we should.
|
||||
@@ -627,36 +663,19 @@ endfunction
|
||||
function! ale#engine#RunLinters(buffer, linters, should_lint_file) abort
|
||||
" Initialise the buffer information if needed.
|
||||
let l:new_buffer = ale#engine#InitBufferInfo(a:buffer)
|
||||
call s:StopCurrentJobs(a:buffer, a:should_lint_file)
|
||||
call s:RemoveProblemsForDisabledLinters(a:buffer, a:linters)
|
||||
|
||||
" We can only clear the results if we aren't checking the buffer.
|
||||
let l:can_clear_results = !ale#engine#IsCheckingBuffer(a:buffer)
|
||||
|
||||
silent doautocmd <nomodeline> User ALELintPre
|
||||
|
||||
" Handle `lint_file` callbacks first.
|
||||
let l:linter_slots = []
|
||||
|
||||
for l:linter in a:linters
|
||||
let l:LintFile = l:linter.lint_file
|
||||
|
||||
if type(l:LintFile) is v:t_func
|
||||
let l:LintFile = l:LintFile(a:buffer)
|
||||
endif
|
||||
|
||||
call add(l:linter_slots, [l:LintFile, l:linter])
|
||||
endfor
|
||||
|
||||
call s:GetLintFileValues(l:linter_slots, {
|
||||
\ new_slots -> s:RunLinters(
|
||||
\ a:buffer,
|
||||
\ new_slots,
|
||||
\ a:should_lint_file,
|
||||
\ l:new_buffer,
|
||||
\ l:can_clear_results,
|
||||
\ )
|
||||
\})
|
||||
call s:GetLintFileValues(
|
||||
\ s:GetLintFileSlots(a:buffer, a:linters),
|
||||
\ {
|
||||
\ slots -> s:RunLinters(
|
||||
\ a:buffer,
|
||||
\ a:linters,
|
||||
\ slots,
|
||||
\ a:should_lint_file,
|
||||
\ l:new_buffer,
|
||||
\ )
|
||||
\ }
|
||||
\)
|
||||
endfunction
|
||||
|
||||
" Clean up a buffer.
|
||||
|
||||
@@ -75,7 +75,10 @@ function! ale#fix#ApplyFixes(buffer, output) abort
|
||||
|
||||
if l:data.lines_before != l:lines
|
||||
call remove(g:ale_fix_buffer_data, a:buffer)
|
||||
execute 'echoerr ''The file was changed before fixing finished'''
|
||||
|
||||
if !l:data.ignore_file_changed_errors
|
||||
execute 'echoerr ''The file was changed before fixing finished'''
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
@@ -329,6 +332,7 @@ function! ale#fix#InitBufferData(buffer, fixing_flag) abort
|
||||
\ 'lines_before': getbufline(a:buffer, 1, '$'),
|
||||
\ 'done': 0,
|
||||
\ 'should_save': a:fixing_flag is# 'save_file',
|
||||
\ 'ignore_file_changed_errors': a:fixing_flag is# '!',
|
||||
\ 'temporary_directory_list': [],
|
||||
\}
|
||||
endfunction
|
||||
@@ -337,19 +341,23 @@ endfunction
|
||||
"
|
||||
" Returns 0 if no fixes can be applied, and 1 if fixing can be done.
|
||||
function! ale#fix#Fix(buffer, fixing_flag, ...) abort
|
||||
if a:fixing_flag isnot# '' && a:fixing_flag isnot# 'save_file'
|
||||
throw "fixing_flag must be either '' or 'save_file'"
|
||||
if a:fixing_flag isnot# ''
|
||||
\&& a:fixing_flag isnot# '!'
|
||||
\&& a:fixing_flag isnot# 'save_file'
|
||||
throw "fixing_flag must be '', '!', or 'save_file'"
|
||||
endif
|
||||
|
||||
try
|
||||
let l:callback_list = s:GetCallbacks(a:buffer, a:fixing_flag, a:000)
|
||||
catch /E700\|BADNAME/
|
||||
let l:function_name = join(split(split(v:exception, ':')[3]))
|
||||
let l:echo_message = printf(
|
||||
\ 'There is no fixer named `%s`. Check :ALEFixSuggest',
|
||||
\ l:function_name,
|
||||
\)
|
||||
execute 'echom l:echo_message'
|
||||
if a:fixing_flag isnot# '!'
|
||||
let l:function_name = join(split(split(v:exception, ':')[3]))
|
||||
let l:echo_message = printf(
|
||||
\ 'There is no fixer named `%s`. Check :ALEFixSuggest',
|
||||
\ l:function_name,
|
||||
\)
|
||||
execute 'echom l:echo_message'
|
||||
endif
|
||||
|
||||
return 0
|
||||
endtry
|
||||
|
||||
@@ -394,6 +394,16 @@ function! ale#linter#Get(original_filetypes) abort
|
||||
return reverse(l:combined_linters)
|
||||
endfunction
|
||||
|
||||
function! ale#linter#RemoveIgnored(buffer, filetype, linters) abort
|
||||
" Apply ignore lists for linters only if needed.
|
||||
let l:ignore_config = ale#Var(a:buffer, 'linters_ignore')
|
||||
let l:disable_lsp = ale#Var(a:buffer, 'disable_lsp')
|
||||
|
||||
return !empty(l:ignore_config) || l:disable_lsp
|
||||
\ ? ale#engine#ignore#Exclude(a:filetype, a:linters, l:ignore_config, l:disable_lsp)
|
||||
\ : a:linters
|
||||
endfunction
|
||||
|
||||
" Given a buffer and linter, get the executable String for the linter.
|
||||
function! ale#linter#GetExecutable(buffer, linter) abort
|
||||
let l:Executable = a:linter.executable
|
||||
|
||||
Reference in New Issue
Block a user