1
0
mirror of https://github.com/amix/vimrc synced 2025-09-18 18:45:01 +08:00

Merge branch 'Linux' of https://github.com/Geezus42/vimrc into Linux

This commit is contained in:
geezus
2021-06-30 13:19:18 -05:00
235 changed files with 6246 additions and 1351 deletions

View File

@ -157,7 +157,23 @@ function! ale#Queue(delay, ...) abort
endif
endfunction
<<<<<<< HEAD
let s:current_ale_version = [3, 1, 0]
=======
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
let s:current_ale_version = [2, 5, 0]
=======
let s:current_ale_version = [2, 6, 0]
>>>>>>> 27ad0d07862847896f691309a544a206783c94d6
=======
let s:current_ale_version = [3, 0, 0]
>>>>>>> master
=======
let s:current_ale_version = [3, 1, 0]
>>>>>>> 597b7acdc0316524c7c65c79d4dc9bf3f5cfce70
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
" A function used to check for ALE features in files outside of the project.
function! ale#Has(feature) abort

View File

@ -23,19 +23,23 @@ function! ale#ant#FindExecutable(buffer) abort
return ''
endfunction
" Given a buffer number, build a command to print the classpath of the root
" project. Returns an empty string if cannot build the command.
" Given a buffer number, get a working directory and command to print the
" classpath of the root project.
"
" Returns an empty string for the command if Ant is not detected.
function! ale#ant#BuildClasspathCommand(buffer) abort
let l:executable = ale#ant#FindExecutable(a:buffer)
let l:project_root = ale#ant#FindProjectRoot(a:buffer)
if !empty(l:executable) && !empty(l:project_root)
return ale#path#CdString(l:project_root)
\ . ale#Escape(l:executable)
\ . ' classpath'
\ . ' -S'
\ . ' -q'
if !empty(l:executable)
let l:project_root = ale#ant#FindProjectRoot(a:buffer)
if !empty(l:project_root)
return [
\ l:project_root,
\ ale#Escape(l:executable) .' classpath -S -q'
\]
endif
endif
return ''
return ['', '']
endfunction

View File

@ -52,6 +52,36 @@ function! s:ProcessDeferredCommands(initial_result) abort
return l:command
endfunction
function! s:ProcessDeferredCwds(initial_command, initial_cwd) abort
let l:result = a:initial_command
let l:last_cwd = v:null
let l:command_index = 0
let l:cwd_list = []
while ale#command#IsDeferred(l:result)
call add(l:cwd_list, l:result.cwd)
if get(g:, 'ale_run_synchronously_emulate_commands')
" Don't run commands, but simulate the results.
let l:Callback = g:ale_run_synchronously_callbacks[0]
let l:output = get(s:command_output, l:command_index, [])
call l:Callback(0, l:output)
unlet g:ale_run_synchronously_callbacks
let l:command_index += 1
else
" Run the commands in the shell, synchronously.
call ale#test#FlushJobs()
endif
let l:result = l:result.value
endwhile
call add(l:cwd_list, a:initial_cwd is v:null ? l:last_cwd : a:initial_cwd)
return l:cwd_list
endfunction
" Load the currently loaded linter for a test case, and check that the command
" matches the given string.
function! ale#assert#Linter(expected_executable, expected_command) abort
@ -85,6 +115,38 @@ function! ale#assert#Linter(expected_executable, expected_command) abort
\ [l:executable, l:command]
endfunction
function! ale#assert#LinterCwd(expected_cwd) abort
let l:buffer = bufnr('')
let l:linter = s:GetLinter()
let l:initial_cwd = ale#linter#GetCwd(l:buffer, l:linter)
call ale#command#SetCwd(l:buffer, l:initial_cwd)
let l:cwd = s:ProcessDeferredCwds(
\ ale#linter#GetCommand(l:buffer, l:linter),
\ l:initial_cwd,
\)
call ale#command#ResetCwd(l:buffer)
if type(a:expected_cwd) isnot v:t_list
let l:cwd = l:cwd[-1]
endif
AssertEqual a:expected_cwd, l:cwd
endfunction
function! ale#assert#FixerCwd(expected_cwd) abort
let l:buffer = bufnr('')
let l:cwd = s:ProcessDeferredCwds(s:FixerFunction(l:buffer), v:null)
if type(a:expected_cwd) isnot v:t_list
let l:cwd = l:cwd[-1]
endif
AssertEqual a:expected_cwd, l:cwd
endfunction
function! ale#assert#Fixer(expected_result) abort
let l:buffer = bufnr('')
let l:result = s:ProcessDeferredCommands(s:FixerFunction(l:buffer))
@ -107,8 +169,21 @@ function! ale#assert#LinterNotExecuted() abort
let l:buffer = bufnr('')
let l:linter = s:GetLinter()
let l:executable = ale#linter#GetExecutable(l:buffer, l:linter)
let l:executed = 1
Assert empty(l:executable), "The linter will be executed when it shouldn't be"
if !empty(l:executable)
let l:command = ale#linter#GetCommand(l:buffer, l:linter)
if type(l:command) is v:t_list
let l:command = l:command[-1]
endif
let l:executed = !empty(l:command)
else
let l:executed = 0
endif
Assert !l:executed, "The linter will be executed when it shouldn't be"
endfunction
function! ale#assert#LSPOptions(expected_options) abort
@ -153,6 +228,7 @@ endfunction
function! ale#assert#SetUpLinterTestCommands() abort
command! -nargs=+ GivenCommandOutput :call ale#assert#GivenCommandOutput(<args>)
command! -nargs=+ AssertLinterCwd :call ale#assert#LinterCwd(<args>)
command! -nargs=+ AssertLinter :call ale#assert#Linter(<args>)
command! -nargs=0 AssertLinterNotExecuted :call ale#assert#LinterNotExecuted()
command! -nargs=+ AssertLSPOptions :call ale#assert#LSPOptions(<args>)
@ -164,10 +240,35 @@ endfunction
function! ale#assert#SetUpFixerTestCommands() abort
command! -nargs=+ GivenCommandOutput :call ale#assert#GivenCommandOutput(<args>)
command! -nargs=+ AssertFixerCwd :call ale#assert#FixerCwd(<args>)
command! -nargs=+ AssertFixer :call ale#assert#Fixer(<args>)
command! -nargs=0 AssertFixerNotExecuted :call ale#assert#FixerNotExecuted()
endfunction
function! ale#assert#ResetVariables(filetype, name, ...) abort
" If the suffix of the option names format is different, an additional
" argument can be used for that instead.
if a:0 > 1
throw 'Too many arguments'
endif
let l:option_suffix = get(a:000, 0, a:name)
let l:prefix = 'ale_' . a:filetype . '_'
\ . substitute(l:option_suffix, '-', '_', 'g')
let l:filter_expr = 'v:val[: len(l:prefix) - 1] is# l:prefix'
" Save and clear linter variables.
" We'll load the runtime file to reset them to defaults.
for l:key in filter(keys(g:), l:filter_expr)
execute 'Save g:' . l:key
unlet g:[l:key]
endfor
for l:key in filter(keys(b:), l:filter_expr)
unlet b:[l:key]
endfor
endfunction
" A dummy function for making sure this module is loaded.
function! ale#assert#SetUpLinterTest(filetype, name) abort
" Set up a marker so ALE doesn't create real random temporary filenames.
@ -177,35 +278,22 @@ function! ale#assert#SetUpLinterTest(filetype, name) abort
call ale#linter#Reset()
call ale#linter#PreventLoading(a:filetype)
let l:prefix = 'ale_' . a:filetype . '_' . a:name
let b:filter_expr = 'v:val[: len(l:prefix) - 1] is# l:prefix'
Save g:ale_root
let g:ale_root = {}
Save g:ale_lsp_root
let g:ale_lsp_root = {}
Save b:ale_root
unlet! b:ale_root
Save b:ale_lsp_root
unlet! b:ale_lsp_root
call ale#assert#ResetVariables(a:filetype, a:name)
Save g:ale_c_build_dir
unlet! g:ale_c_build_dir
" Save and clear linter variables.
" We'll load the runtime file to reset them to defaults.
for l:key in filter(keys(g:), b:filter_expr)
execute 'Save g:' . l:key
unlet g:[l:key]
endfor
unlet! b:ale_c_build_dir
for l:key in filter(keys(b:), b:filter_expr)
unlet b:[l:key]
endfor
execute 'runtime ale_linters/' . a:filetype . '/' . a:name . '.vim'
if !exists('g:dir')
call ale#test#SetDirectory('/testplugin/test/command_callback')
call ale#test#SetDirectory('/testplugin/test/linter')
endif
call ale#assert#SetUpLinterTestCommands()
@ -226,6 +314,10 @@ function! ale#assert#TearDownLinterTest() abort
delcommand GivenCommandOutput
endif
if exists(':AssertLinterCwd')
delcommand AssertLinterCwd
endif
if exists(':AssertLinter')
delcommand AssertLinter
endif
@ -281,18 +373,7 @@ function! ale#assert#SetUpFixerTest(filetype, name, ...) abort
let s:FixerFunction = function(l:function_name)
let l:option_suffix = get(a:000, 0, a:name)
let l:prefix = 'ale_' . a:filetype . '_'
\ . substitute(l:option_suffix, '-', '_', 'g')
let b:filter_expr = 'v:val[: len(l:prefix) - 1] is# l:prefix'
for l:key in filter(keys(g:), b:filter_expr)
execute 'Save g:' . l:key
unlet g:[l:key]
endfor
for l:key in filter(keys(b:), b:filter_expr)
unlet b:[l:key]
endfor
call ale#assert#ResetVariables(a:filetype, a:name, l:option_suffix)
execute 'runtime autoload/ale/fixers/' . substitute(a:name, '-', '_', 'g') . '.vim'
@ -329,6 +410,10 @@ function! ale#assert#TearDownFixerTest() abort
delcommand GivenCommandOutput
endif
if exists(':AssertFixerCwd')
delcommand AssertFixerCwd
endif
if exists(':AssertFixer')
delcommand AssertFixer
endif

View File

@ -513,16 +513,18 @@ function! ale#c#GetMakeCommand(buffer) abort
if !empty(l:path)
let l:always_make = ale#Var(a:buffer, 'c_always_make')
return ale#path#CdString(fnamemodify(l:path, ':h'))
\ . 'make -n' . (l:always_make ? ' --always-make' : '')
return [
\ fnamemodify(l:path, ':h'),
\ 'make -n' . (l:always_make ? ' --always-make' : ''),
\]
endif
endif
return ''
return ['', '']
endfunction
function! ale#c#RunMakeCommand(buffer, Callback) abort
let l:command = ale#c#GetMakeCommand(a:buffer)
let [l:cwd, l:command] = ale#c#GetMakeCommand(a:buffer)
if empty(l:command)
return a:Callback(a:buffer, [])
@ -532,6 +534,7 @@ function! ale#c#RunMakeCommand(buffer, Callback) abort
\ a:buffer,
\ l:command,
\ {b, output -> a:Callback(a:buffer, output)},
\ {'cwd': l:cwd},
\)
endfunction

View File

@ -71,6 +71,11 @@ function! ale#code_action#ApplyChanges(filename, changes, should_save) abort
if l:buffer > 0
let l:lines = getbufline(l:buffer, 1, '$')
" Add empty line if there's trailing newline, like readfile() does.
if getbufvar(l:buffer, '&eol')
let l:lines += ['']
endif
else
let l:lines = readfile(a:filename, 'b')
endif
@ -89,62 +94,82 @@ function! ale#code_action#ApplyChanges(filename, changes, should_save) abort
let l:end_column = l:code_edit.end.offset
let l:text = l:code_edit.newText
" Adjust the ends according to previous edits.
if l:end_line > len(l:lines)
let l:end_line_len = 0
else
let l:end_line_len = len(l:lines[l:end_line - 1])
endif
let l:insertions = split(l:text, '\n', 1)
if l:line is 1
" Same logic as for column below. Vimscript's slice [:-1] will not
" be an empty list.
let l:start = []
else
let l:start = l:lines[: l:line - 2]
" Fix invalid columns
let l:column = l:column > 0 ? l:column : 1
let l:end_column = l:end_column > 0 ? l:end_column : 1
" Clamp start to BOF
if l:line < 1
let [l:line, l:column] = [1, 1]
endif
" Special case when text must be added after new line
if l:column > len(l:lines[l:line - 1])
call extend(l:start, [l:lines[l:line - 1]])
let l:column = 1
" Clamp start to EOF
if l:line > len(l:lines) || l:line == len(l:lines) && l:column > len(l:lines[-1]) + 1
let [l:line, l:column] = [len(l:lines), len(l:lines[-1]) + 1]
" Special case when start is after EOL
elseif l:line < len(l:lines) && l:column > len(l:lines[l:line - 1]) + 1
let [l:line, l:column] = [l:line + 1, 1]
endif
if l:column is 1
" We need to handle column 1 specially, because we can't slice an
" empty string ending on index 0.
let l:middle = [l:insertions[0]]
else
let l:middle = [l:lines[l:line - 1][: l:column - 2] . l:insertions[0]]
" Adjust end: clamp if invalid and/or adjust if we moved start
if l:end_line < l:line || l:end_line == l:line && l:end_column < l:column
let [l:end_line, l:end_column] = [l:line, l:column]
endif
call extend(l:middle, l:insertions[1:])
if l:end_line <= len(l:lines)
" Only extend the last line if end_line is within the range of
" lines.
let l:middle[-1] .= l:lines[l:end_line - 1][l:end_column - 1 :]
" Clamp end to EOF
if l:end_line > len(l:lines) || l:end_line == len(l:lines) && l:end_column > len(l:lines[-1]) + 1
let [l:end_line, l:end_column] = [len(l:lines), len(l:lines[-1]) + 1]
" Special case when end is after EOL
elseif l:end_line < len(l:lines) && l:end_column > len(l:lines[l:end_line - 1]) + 1
let [l:end_line, l:end_column] = [l:end_line + 1, 1]
endif
" Careful, [:-1] is not an empty list
let l:start = l:line is 1 ? [] : l:lines[: l:line - 2]
let l:middle = l:column is 1 ? [''] : [l:lines[l:line - 1][: l:column - 2]]
let l:middle[-1] .= l:insertions[0]
let l:middle += l:insertions[1:]
let l:middle[-1] .= l:lines[l:end_line - 1][l:end_column - 1 :]
let l:end_line_len = len(l:lines[l:end_line - 1])
let l:lines_before_change = len(l:lines)
let l:lines = l:start + l:middle + l:lines[l:end_line :]
let l:current_line_offset = len(l:lines) - l:lines_before_change
let l:column_offset = len(l:middle[-1]) - l:end_line_len
let l:pos = s:UpdateCursor(l:pos,
\ [l:line, l:column],
\ [l:end_line, l:end_column],
\ [l:current_line_offset, l:column_offset])
" Keep cursor where it was (if outside of changes) or move it after
" the changed text (if inside), but don't touch it when the change
" spans the entire buffer, in which case we have no clue and it's
" better to not do anything.
if l:line isnot 1 || l:column isnot 1
\|| l:end_line < l:lines_before_change
\|| l:end_line == l:lines_before_change && l:end_column <= l:end_line_len
let l:pos = s:UpdateCursor(l:pos,
\ [l:line, l:column],
\ [l:end_line, l:end_column],
\ [l:current_line_offset, l:column_offset])
endif
endfor
if l:lines[-1] is# ''
if l:buffer > 0
" Make sure ale#util#{Writefile,SetBufferContents} add trailing
" newline if and only if it should be added.
if l:lines[-1] is# '' && getbufvar(l:buffer, '&eol')
call remove(l:lines, -1)
else
call setbufvar(l:buffer, '&eol', 0)
endif
elseif exists('+fixeol') && &fixeol && l:lines[-1] is# ''
" Not in buffer, ale#util#Writefile can't check &eol and always adds
" newline if &fixeol: remove to prevent double trailing newline.
call remove(l:lines, -1)
endif
if a:should_save
if a:should_save || l:buffer < 0
call ale#util#Writefile(l:buffer, l:lines, a:filename)
else
call ale#util#SetBufferContents(l:buffer, l:lines)
@ -222,6 +247,10 @@ function! s:UpdateCursor(cursor, start, end, offset) abort
endfunction
function! ale#code_action#GetChanges(workspace_edit) abort
if a:workspace_edit is v:null
return {}
endif
let l:changes = {}
if has_key(a:workspace_edit, 'changes') && !empty(a:workspace_edit.changes)

View File

@ -7,6 +7,9 @@ if !exists('s:buffer_data')
let s:buffer_data = {}
endif
" The regular expression used for formatting filenames with modifiers.
let s:path_format_regex = '\v\%s(%(:h|:t|:r|:e)*)'
" Used to get the data in tests.
function! ale#command#GetData() abort
return deepcopy(s:buffer_data)
@ -26,6 +29,19 @@ function! ale#command#InitData(buffer) abort
endif
endfunction
" Set the cwd for commands that are about to run.
" Used internally.
function! ale#command#SetCwd(buffer, cwd) abort
call ale#command#InitData(a:buffer)
let s:buffer_data[a:buffer].cwd = a:cwd
endfunction
function! ale#command#ResetCwd(buffer) abort
if has_key(s:buffer_data, a:buffer)
let s:buffer_data[a:buffer].cwd = v:null
endif
endfunction
function! ale#command#ManageFile(buffer, file) abort
call ale#command#InitData(a:buffer)
call add(s:buffer_data[a:buffer].file_list, a:file)
@ -151,6 +167,24 @@ function! s:FormatFilename(filename, mappings, modifiers) abort
return ale#Escape(l:filename)
endfunction
" Produce a command prefix to check to a particular directory for a command.
" %s format markers with filename-modifiers can be used as the directory, and
" will be returned verbatim for formatting in paths relative to files.
function! ale#command#CdString(directory) abort
let l:match = matchstrpos(a:directory, s:path_format_regex)
" Do not escape the directory here if it's a valid format string.
" This allows us to use sequences like %s:h, %s:h:h, etc.
let l:directory = l:match[1:] == [0, len(a:directory)]
\ ? a:directory
\ : ale#Escape(a:directory)
if has('win32')
return 'cd /d ' . l:directory . ' && '
endif
return 'cd ' . l:directory . ' && '
endfunction
" Given a command string, replace every...
" %s -> with the current filename
" %t -> with the name of an unused file in a temporary directory
@ -161,11 +195,16 @@ function! ale#command#FormatCommand(
\ command,
\ pipe_file_if_needed,
\ input,
\ cwd,
\ mappings,
\) abort
let l:temporary_file = ''
let l:command = a:command
if !empty(a:cwd)
let l:command = ale#command#CdString(a:cwd) . l:command
endif
" First replace all uses of %%, used for literal percent characters,
" with an ugly string.
let l:command = substitute(l:command, '%%', '<<PERCENTS>>', 'g')
@ -181,7 +220,7 @@ function! ale#command#FormatCommand(
let l:filename = fnamemodify(bufname(a:buffer), ':p')
let l:command = substitute(
\ l:command,
\ '\v\%s(%(:h|:t|:r|:e)*)',
\ s:path_format_regex,
\ '\=s:FormatFilename(l:filename, a:mappings, submatch(1))',
\ 'g'
\)
@ -279,9 +318,16 @@ function! s:ExitCallback(buffer, line_list, Callback, data) abort
let l:result = a:data.result
let l:result.value = l:value
if get(l:result, 'result_callback', v:null) isnot v:null
call call(l:result.result_callback, [l:value])
endif
" Set the default cwd for this buffer in this call stack.
call ale#command#SetCwd(a:buffer, l:result.cwd)
try
if get(l:result, 'result_callback', v:null) isnot v:null
call call(l:result.result_callback, [l:value])
endif
finally
call ale#command#ResetCwd(a:buffer)
endtry
endfunction
function! ale#command#Run(buffer, command, Callback, ...) abort
@ -293,6 +339,13 @@ function! ale#command#Run(buffer, command, Callback, ...) abort
let l:output_stream = get(l:options, 'output_stream', 'stdout')
let l:line_list = []
let l:cwd = get(l:options, 'cwd', v:null)
if l:cwd is v:null
" Default the working directory to whatever it was for the last
" command run in the chain.
let l:cwd = get(get(s:buffer_data, a:buffer, {}), 'cwd', v:null)
endif
let [l:temporary_file, l:command, l:file_created] = ale#command#FormatCommand(
\ a:buffer,
@ -300,6 +353,7 @@ function! ale#command#Run(buffer, command, Callback, ...) abort
\ a:command,
\ get(l:options, 'read_buffer', 0),
\ get(l:options, 'input', v:null),
\ l:cwd,
\ get(l:options, 'filename_mappings', []),
\)
let l:command = ale#job#PrepareCommand(a:buffer, l:command)
@ -366,10 +420,14 @@ function! ale#command#Run(buffer, command, Callback, ...) abort
" The `_deferred_job_id` is used for both checking the type of object, and
" for checking the job ID and status.
"
" The cwd is kept and used as the default value for the next command in
" the chain.
"
" The original command here is used in tests.
let l:result = {
\ '_deferred_job_id': l:job_id,
\ 'executable': get(l:options, 'executable', ''),
\ 'cwd': l:cwd,
\ 'command': a:command,
\}

View File

@ -269,13 +269,19 @@ function! s:ReplaceCompletionOptions(source) abort
let b:ale_old_completeopt = &l:completeopt
endif
if &l:completeopt =~# 'preview'
let &l:completeopt = 'menu,menuone,preview,noselect,noinsert'
elseif &l:completeopt =~# 'popup'
let &l:completeopt = 'menu,menuone,popup,noselect,noinsert'
else
let &l:completeopt = 'menu,menuone,noselect,noinsert'
endif
let l:opt_list = split(&l:completeopt, ',')
" The menu and noinsert options must be set, or automatic completion
" will be annoying.
let l:new_opt_list = ['menu', 'menuone', 'noinsert']
" Permit some other completion options, provided users have set them.
for l:opt in ['preview', 'popup', 'noselect']
if index(l:opt_list, l:opt) >= 0
call add(l:new_opt_list, l:opt)
endif
endfor
let &l:completeopt = join(l:new_opt_list, ',')
endif
endfunction

View File

@ -33,13 +33,13 @@ let s:global_variable_list = [
\ 'ale_list_vertical',
\ 'ale_list_window_size',
\ 'ale_loclist_msg_format',
\ 'ale_lsp_root',
\ 'ale_max_buffer_history_size',
\ 'ale_max_signs',
\ 'ale_maximum_file_size',
\ 'ale_open_list',
\ 'ale_pattern_options',
\ 'ale_pattern_options_enabled',
\ 'ale_root',
\ 'ale_set_balloons',
\ 'ale_set_highlights',
\ 'ale_set_loclist',
@ -259,9 +259,7 @@ function! ale#debugging#InfoToClipboard() abort
return
endif
redir => l:output
silent call ale#debugging#Info()
redir END
let l:output = execute('call ale#debugging#Info()')
let @+ = l:output
call s:Echo('ALEInfo copied to your clipboard')
@ -270,9 +268,7 @@ endfunction
function! ale#debugging#InfoToFile(filename) abort
let l:expanded_filename = expand(a:filename)
redir => l:output
silent call ale#debugging#Info()
redir END
let l:output = execute('call ale#debugging#Info()')
call writefile(split(l:output, "\n"), l:expanded_filename)
call s:Echo('ALEInfo written to ' . l:expanded_filename)

View File

@ -36,7 +36,7 @@ function! ale#definition#UpdateTagStack() abort
endfunction
function! ale#definition#HandleTSServerResponse(conn_id, response) abort
if get(a:response, 'command', '') is# 'definition'
if has_key(a:response, 'request_seq')
\&& has_key(s:go_to_definition_map, a:response.request_seq)
let l:options = remove(s:go_to_definition_map, a:response.request_seq)
@ -66,9 +66,17 @@ function! ale#definition#HandleLSPResponse(conn_id, response) abort
endif
for l:item in l:result
let l:filename = ale#path#FromURI(l:item.uri)
let l:line = l:item.range.start.line + 1
let l:column = l:item.range.start.character + 1
if has_key(l:item, 'targetUri')
" LocationLink items use targetUri
let l:filename = ale#path#FromURI(l:item.targetUri)
let l:line = l:item.targetRange.start.line + 1
let l:column = l:item.targetRange.start.character + 1
else
" LocationLink items use uri
let l:filename = ale#path#FromURI(l:item.uri)
let l:line = l:item.range.start.line + 1
let l:column = l:item.range.start.character + 1
endif
call ale#definition#UpdateTagStack()
call ale#util#Open(l:filename, l:line, l:column, l:options)
@ -92,11 +100,19 @@ function! s:OnReady(line, column, options, capability, linter, lsp_details) abor
call ale#lsp#RegisterCallback(l:id, l:Callback)
if a:linter.lsp is# 'tsserver'
let l:message = ale#lsp#tsserver_message#Definition(
\ l:buffer,
\ a:line,
\ a:column
\)
if a:capability is# 'definition'
let l:message = ale#lsp#tsserver_message#Definition(
\ l:buffer,
\ a:line,
\ a:column
\)
elseif a:capability is# 'typeDefinition'
let l:message = ale#lsp#tsserver_message#TypeDefinition(
\ l:buffer,
\ a:line,
\ a:column
\)
endif
else
" Send a message saying the buffer has changed first, or the
" definition position probably won't make sense.
@ -145,12 +161,6 @@ endfunction
function! ale#definition#GoToType(options) abort
for l:linter in ale#linter#Get(&filetype)
if !empty(l:linter.lsp)
" TODO: handle typeDefinition for tsserver if supported by the
" protocol
if l:linter.lsp is# 'tsserver'
continue
endif
call s:GoToLSPDefinition(l:linter, a:options, 'typeDefinition')
endif
endfor

View File

@ -413,6 +413,7 @@ function! s:RunJob(command, options) abort
return 0
endif
let l:cwd = a:options.cwd
let l:executable = a:options.executable
let l:buffer = a:options.buffer
let l:linter = a:options.linter
@ -425,6 +426,7 @@ function! s:RunJob(command, options) abort
\ 'executable': l:executable,
\}])
let l:result = ale#command#Run(l:buffer, l:command, l:Callback, {
\ 'cwd': l:cwd,
\ 'output_stream': l:output_stream,
\ 'executable': l:executable,
\ 'read_buffer': l:read_buffer,
@ -541,8 +543,22 @@ function! s:RunIfExecutable(buffer, linter, lint_file, executable) abort
let l:job_type = a:lint_file ? 'file_linter' : 'linter'
call setbufvar(a:buffer, 'ale_job_type', l:job_type)
" Get the cwd for the linter and set it before we call GetCommand.
" This will ensure that ale#command#Run uses it by default.
let l:cwd = ale#linter#GetCwd(a:buffer, a:linter)
if l:cwd isnot v:null
call ale#command#SetCwd(a:buffer, l:cwd)
endif
let l:command = ale#linter#GetCommand(a:buffer, a:linter)
if l:cwd isnot v:null
call ale#command#ResetCwd(a:buffer)
endif
let l:options = {
\ 'cwd': l:cwd,
\ 'executable': a:executable,
\ 'buffer': a:buffer,
\ 'linter': a:linter,

View File

@ -4,9 +4,7 @@
function! ale#filetypes#LoadExtensionMap() abort
" Output includes:
" '*.erl setf erlang'
redir => l:output
silent exec 'autocmd'
redir end
let l:output = execute('exec "autocmd"')
let l:map = {}

View File

@ -172,6 +172,7 @@ function! s:RunJob(result, options) abort
let l:read_temporary_file = get(a:result, 'read_temporary_file', 0)
let l:read_buffer = get(a:result, 'read_buffer', 1)
let l:output_stream = get(a:result, 'output_stream', 'stdout')
let l:cwd = get(a:result, 'cwd', v:null)
if l:read_temporary_file
let l:output_stream = 'none'
@ -190,6 +191,7 @@ function! s:RunJob(result, options) abort
\ 'read_buffer': l:read_buffer,
\ 'input': l:input,
\ 'log_output': 0,
\ 'cwd': l:cwd,
\ 'filename_mappings': ale#GetFilenameMappings(l:buffer, l:fixer_name),
\})

View File

@ -32,6 +32,14 @@ let s:default_registry = {
\ 'suggested_filetypes': ['python'],
\ 'description': 'Fix PEP8 issues with black.',
\ },
<<<<<<< HEAD
=======
\ 'buildifier': {
\ 'function': 'ale#fixers#buildifier#Fix',
\ 'suggested_filetypes': ['bzl'],
\ 'description': 'Format BUILD and .bzl files with buildifier.',
\ },
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
\ 'deno': {
\ 'function': 'ale#fixers#deno#Fix',
\ 'suggested_filetypes': ['typescript'],
@ -107,7 +115,11 @@ let s:default_registry = {
\ },
\ 'prettier': {
\ 'function': 'ale#fixers#prettier#Fix',
<<<<<<< HEAD
\ 'suggested_filetypes': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue', 'html', 'yaml', 'openapi', 'ruby'],
=======
\ 'suggested_filetypes': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'json5', 'graphql', 'markdown', 'vue', 'svelte', 'html', 'yaml', 'openapi', 'ruby'],
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
\ 'description': 'Apply prettier to a file.',
\ },
\ 'prettier_eslint': {
@ -186,6 +198,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['swift'],
\ 'description': 'Apply SwiftFormat to a file.',
\ },
\ 'apple-swift-format': {
\ 'function': 'ale#fixers#appleswiftformat#Fix',
\ 'suggested_filetypes': ['swift'],
\ 'description': 'Apply apple/swift-format to a file.',
\ },
\ 'phpcbf': {
\ 'function': 'ale#fixers#phpcbf#Fix',
\ 'suggested_filetypes': ['php'],
@ -293,12 +310,12 @@ let s:default_registry = {
\ },
\ 'ocamlformat': {
\ 'function': 'ale#fixers#ocamlformat#Fix',
\ 'suggested_filetypes': ['ocaml'],
\ 'suggested_filetypes': ['ocaml', 'ocamlinterface'],
\ 'description': 'Fix OCaml files with ocamlformat.',
\ },
\ 'ocp-indent': {
\ 'function': 'ale#fixers#ocp_indent#Fix',
\ 'suggested_filetypes': ['ocaml'],
\ 'suggested_filetypes': ['ocaml', 'ocamlinterface'],
\ 'description': 'Fix OCaml files with ocp-indent.',
\ },
\ 'refmt': {
@ -336,6 +353,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['json'],
\ 'description': 'Fix JSON files with jq.',
\ },
\ 'protolint': {
\ 'function': 'ale#fixers#protolint#Fix',
\ 'suggested_filetypes': ['proto'],
\ 'description': 'Fix Protocol Buffer files with protolint.',
\ },
\ 'perltidy': {
\ 'function': 'ale#fixers#perltidy#Fix',
\ 'suggested_filetypes': ['perl'],
@ -401,6 +423,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['ada'],
\ 'description': 'Format Ada files with gnatpp.',
\ },
\ 'nixfmt': {
\ 'function': 'ale#fixers#nixfmt#Fix',
\ 'suggested_filetypes': ['nix'],
\ 'description': 'A nix formatter written in Haskell.',
\ },
\ 'nixpkgs-fmt': {
\ 'function': 'ale#fixers#nixpkgsfmt#Fix',
\ 'suggested_filetypes': ['nix'],
@ -425,6 +452,19 @@ let s:default_registry = {
\ 'function': 'ale#fixers#ormolu#Fix',
\ 'suggested_filetypes': ['haskell'],
\ 'description': 'A formatter for Haskell source code.',
<<<<<<< HEAD
=======
\ },
\ 'ptop': {
\ 'function': 'ale#fixers#ptop#Fix',
\ 'suggested_filetypes': ['pascal'],
\ 'description': 'Fix Pascal files with ptop.',
\ },
\ 'vfmt': {
\ 'function': 'ale#fixers#vfmt#Fix',
\ 'suggested_filetypes': ['v'],
\ 'description': 'A formatter for V source code.',
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
\ }
\}

View File

@ -0,0 +1,16 @@
" Author: (bosr) <bosr@bosr.cc>
" Description: Integration of apple/swift-format formatter with ALE.
function! ale#fixers#appleswiftformat#Fix(buffer) abort
let l:command_args = ale#swift#GetAppleSwiftFormatCommand(a:buffer) . ' format --in-place %t'
let l:config_args = ale#swift#GetAppleSwiftFormatConfigArgs(a:buffer)
if l:config_args isnot# ''
let l:command_args = l:command_args . ' ' . l:config_args
endif
return {
\ 'read_temporary_file': 1,
\ 'command': l:command_args,
\}
endfunction

View File

@ -19,7 +19,9 @@ function! ale#fixers#autoimport#Fix(buffer) abort
endif
return {
\ 'command': ale#path#BufferCdString(a:buffer)
\ . ale#Escape(l:executable) . (!empty(l:options) ? ' ' . l:options : '') . ' -',
\ 'cwd': '%s:h',
\ 'command': ale#Escape(l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -',
\}
endfunction

View File

@ -17,25 +17,25 @@ function! ale#fixers#black#GetExecutable(buffer) abort
endfunction
function! ale#fixers#black#Fix(buffer) abort
let l:cd_string = ale#Var(a:buffer, 'python_black_change_directory')
\ ? ale#path#BufferCdString(a:buffer)
\ : ''
let l:executable = ale#fixers#black#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv$'
\ ? ' run black'
\ : ''
let l:options = ale#Var(a:buffer, 'python_black_options')
if expand('#' . a:buffer . ':e') is? 'pyi'
let l:options .= '--pyi'
endif
return {
\ 'command': l:cd_string . ale#Escape(l:executable) . l:exec_args
let l:result = {
\ 'command': ale#Escape(l:executable) . l:exec_args
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -',
\}
if ale#Var(a:buffer, 'python_black_change_directory')
let l:result.cwd = '%s:h'
endif
return l:result
endfunction

View File

@ -0,0 +1,26 @@
" Author: Jon Parise <jon@indelible.org>
" Description: Format Bazel BUILD and .bzl files with buildifier.
"
call ale#Set('bazel_buildifier_executable', 'buildifier')
call ale#Set('bazel_buildifier_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('bazel_buildifier_options', '')
function! ale#fixers#buildifier#GetExecutable(buffer) abort
return ale#path#FindExecutable(a:buffer, 'bazel_buildifier', [
\ 'buildifier',
\])
endfunction
function! ale#fixers#buildifier#Fix(buffer) abort
let l:executable = ale#Escape(ale#fixers#buildifier#GetExecutable(a:buffer))
let l:options = ale#Var(a:buffer, 'bazel_buildifier_options')
let l:filename = ale#Escape(bufname(a:buffer))
let l:command = l:executable . ' -mode fix -lint fix -path ' . l:filename
if l:options isnot# ''
let l:command .= ' ' . l:options
endif
return {'command': l:command . ' -'}
endfunction

View File

@ -9,7 +9,7 @@ call ale#Set('c_clangformat_style_option', '')
call ale#Set('c_clangformat_use_local_file', 0)
function! ale#fixers#clangformat#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'c_clangformat', [
return ale#path#FindExecutable(a:buffer, 'c_clangformat', [
\ 'clang-format',
\])
endfunction

View File

@ -10,9 +10,7 @@ function! ale#fixers#cmakeformat#Fix(buffer) abort
return {
\ 'command': ale#Escape(l:executable)
\ . ' -i '
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' %t',
\ 'read_temporary_file': 1,
\ . ' -'
\}
endfunction

View File

@ -6,7 +6,7 @@ call ale#Set('elm_format_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('elm_format_options', '--yes')
function! ale#fixers#elm_format#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'elm_format', [
return ale#path#FindExecutable(a:buffer, 'elm_format', [
\ 'node_modules/.bin/elm-format',
\])
endfunction

View File

@ -0,0 +1,21 @@
" Author: AntoineGagne - https://github.com/AntoineGagne
" Description: Integration of erlfmt with ALE.
call ale#Set('erlang_erlfmt_executable', 'erlfmt')
call ale#Set('erlang_erlfmt_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('erlang_erlfmt_options', '')
function! ale#fixers#erlfmt#GetExecutable(buffer) abort
return ale#path#FindExecutable(a:buffer, 'erlang_erlfmt', ['erlfmt'])
endfunction
function! ale#fixers#erlfmt#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'erlang_erlfmt_options')
let l:executable = ale#fixers#erlfmt#GetExecutable(a:buffer)
let l:command = ale#Escape(l:executable) . (empty(l:options) ? '' : ' ' . l:options) . ' %s'
return {
\ 'command': l:command
\}
endfunction

View File

@ -53,8 +53,8 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort
" Use --fix-to-stdout with eslint_d
if l:executable =~# 'eslint_d$' && ale#semver#GTE(a:version, [3, 19, 0])
return {
\ 'command': ale#handlers#eslint#GetCdString(a:buffer)
\ . ale#node#Executable(a:buffer, l:executable)
\ 'cwd': ale#handlers#eslint#GetCwd(a:buffer),
\ 'command': ale#node#Executable(a:buffer, l:executable)
\ . ale#Pad(l:options)
\ . ' --stdin-filename %s --stdin --fix-to-stdout',
\ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput',
@ -64,8 +64,8 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort
" 4.9.0 is the first version with --fix-dry-run
if ale#semver#GTE(a:version, [4, 9, 0])
return {
\ 'command': ale#handlers#eslint#GetCdString(a:buffer)
\ . ale#node#Executable(a:buffer, l:executable)
\ 'cwd': ale#handlers#eslint#GetCwd(a:buffer),
\ 'command': ale#node#Executable(a:buffer, l:executable)
\ . ale#Pad(l:options)
\ . ' --stdin-filename %s --stdin --fix-dry-run --format=json',
\ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput',
@ -73,8 +73,8 @@ function! ale#fixers#eslint#ApplyFixForVersion(buffer, version) abort
endif
return {
\ 'command': ale#handlers#eslint#GetCdString(a:buffer)
\ . ale#node#Executable(a:buffer, l:executable)
\ 'cwd': ale#handlers#eslint#GetCwd(a:buffer),
\ 'command': ale#node#Executable(a:buffer, l:executable)
\ . ale#Pad(l:options)
\ . (!empty(l:config) ? ' -c ' . ale#Escape(l:config) : '')
\ . ' --fix %t',

View File

@ -6,7 +6,7 @@ call ale#Set('json_fixjson_options', '')
call ale#Set('json_fixjson_use_global', get(g:, 'ale_use_global_executables', 0))
function! ale#fixers#fixjson#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'json_fixjson', [
return ale#path#FindExecutable(a:buffer, 'json_fixjson', [
\ 'node_modules/.bin/fixjson',
\])
endfunction

View File

@ -17,20 +17,32 @@ endfunction
function! ale#fixers#isort#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'python_isort_options')
let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv$'
\ ? ' run isort'
\ : ''
<<<<<<< HEAD
let l:executable = ale#fixers#isort#GetExecutable(a:buffer)
let l:exec_args = l:executable =~? 'pipenv$'
\ ? ' run isort'
\ : ''
=======
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
if !executable(l:executable) && l:executable isnot# 'pipenv'
return 0
endif
return {
<<<<<<< HEAD
\ 'command': ale#path#BufferCdString(a:buffer)
\ . ale#Escape(l:executable) . l:exec_args
=======
\ 'cwd': '%s:h',
\ 'command': ale#Escape(l:executable) . l:exec_args
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
\ . (!empty(l:options) ? ' ' . l:options : '') . ' -',
\}
endfunction

View File

@ -0,0 +1,15 @@
scriptencoding utf-8
" Author: houstdav000 <houstdav000@gh0st.sh>
" Description: Fix files with nixfmt
call ale#Set('nix_nixfmt_executable', 'nixfmt')
call ale#Set('nix_nixfmt_options', '')
function! ale#fixers#nixfmt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'nix_nixfmt_executable')
let l:options = ale#Var(a:buffer, 'nix_nixfmt_options')
return {
\ 'command': ale#Escape(l:executable) . ale#Pad(l:options),
\}
endfunction

View File

@ -6,7 +6,7 @@ call ale#Set('php_cs_fixer_use_global', get(g:, 'ale_use_global_executables', 0)
call ale#Set('php_cs_fixer_options', '')
function! ale#fixers#php_cs_fixer#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'php_cs_fixer', [
return ale#path#FindExecutable(a:buffer, 'php_cs_fixer', [
\ 'vendor/bin/php-cs-fixer',
\ 'php-cs-fixer'
\])

View File

@ -7,7 +7,7 @@ call ale#Set('php_phpcbf_executable', 'phpcbf')
call ale#Set('php_phpcbf_use_global', get(g:, 'ale_use_global_executables', 0))
function! ale#fixers#phpcbf#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'php_phpcbf', [
return ale#path#FindExecutable(a:buffer, 'php_phpcbf', [
\ 'vendor/bin/phpcbf',
\ 'phpcbf'
\])

View File

@ -7,7 +7,7 @@ call ale#Set('javascript_prettier_use_global', get(g:, 'ale_use_global_executabl
call ale#Set('javascript_prettier_options', '')
function! ale#fixers#prettier#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_prettier', [
return ale#path#FindExecutable(a:buffer, 'javascript_prettier', [
\ 'node_modules/.bin/prettier_d',
\ 'node_modules/prettier-cli/index.js',
\ 'node_modules/.bin/prettier',
@ -34,19 +34,11 @@ function! ale#fixers#prettier#ProcessPrettierDOutput(buffer, output) abort
return a:output
endfunction
function! ale#fixers#prettier#GetProjectRoot(buffer) abort
function! ale#fixers#prettier#GetCwd(buffer) abort
let l:config = ale#path#FindNearestFile(a:buffer, '.prettierignore')
if !empty(l:config)
return fnamemodify(l:config, ':h')
endif
" Fall back to the directory of the buffer
return fnamemodify(bufname(a:buffer), ':p:h')
endfunction
function! ale#fixers#prettier#CdProjectRoot(buffer) abort
return ale#path#CdString(ale#fixers#prettier#GetProjectRoot(a:buffer))
return !empty(l:config) ? fnamemodify(l:config, ':h') : '%s:h'
endfunction
function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
@ -82,6 +74,7 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
\ 'graphql': 'graphql',
\ 'markdown': 'markdown',
\ 'vue': 'vue',
\ 'svelte': 'svelte',
\ 'yaml': 'yaml',
\ 'openapi': 'yaml',
\ 'html': 'html',
@ -103,8 +96,8 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
" Special error handling needed for prettier_d
if l:executable =~# 'prettier_d$'
return {
\ 'command': ale#path#BufferCdString(a:buffer)
\ . ale#Escape(l:executable)
\ 'cwd': '%s:h',
\ 'command':ale#Escape(l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --stdin-filepath %s --stdin',
\ 'process_with': 'ale#fixers#prettier#ProcessPrettierDOutput',
@ -114,8 +107,8 @@ function! ale#fixers#prettier#ApplyFixForVersion(buffer, version) abort
" 1.4.0 is the first version with --stdin-filepath
if ale#semver#GTE(a:version, [1, 4, 0])
return {
\ 'command': ale#fixers#prettier#CdProjectRoot(a:buffer)
\ . ale#Escape(l:executable)
\ 'cwd': ale#fixers#prettier#GetCwd(a:buffer),
\ 'command': ale#Escape(l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --stdin-filepath %s --stdin',
\}

View File

@ -7,7 +7,7 @@ call ale#Set('javascript_prettier_eslint_use_global', get(g:, 'ale_use_global_ex
call ale#Set('javascript_prettier_eslint_options', '')
function! ale#fixers#prettier_eslint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_prettier_eslint', [
return ale#path#FindExecutable(a:buffer, 'javascript_prettier_eslint', [
\ 'node_modules/prettier-eslint-cli/dist/index.js',
\ 'node_modules/.bin/prettier-eslint',
\])
@ -37,8 +37,8 @@ function! ale#fixers#prettier_eslint#ApplyFixForVersion(buffer, version) abort
" 4.4.0 is the first version with --stdin-filepath
if ale#semver#GTE(a:version, [4, 4, 0])
return {
\ 'command': ale#path#BufferCdString(a:buffer)
\ . ale#Escape(l:executable)
\ 'cwd': '%s:h',
\ 'command': ale#Escape(l:executable)
\ . l:eslint_config_option
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --stdin-filepath %s --stdin',

View File

@ -6,7 +6,7 @@ call ale#Set('javascript_prettier_standard_use_global', get(g:, 'ale_use_global_
call ale#Set('javascript_prettier_standard_options', '')
function! ale#fixers#prettier_standard#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_prettier_standard', [
return ale#path#FindExecutable(a:buffer, 'javascript_prettier_standard', [
\ 'node_modules/prettier-standard/lib/index.js',
\ 'node_modules/.bin/prettier-standard',
\])

View File

@ -0,0 +1,26 @@
" Author: Yohei Yoshimuta <yoheimuta@gmail.com>
" Description: Integration of protolint with ALE.
call ale#Set('proto_protolint_executable', 'protolint')
call ale#Set('proto_protolint_config', '')
function! ale#fixers#protolint#GetExecutable(buffer) abort
let l:executable = ale#Var(a:buffer, 'proto_protolint_executable')
return ale#Escape(l:executable)
endfunction
function! ale#fixers#protolint#Fix(buffer) abort
let l:executable = ale#fixers#protolint#GetExecutable(a:buffer)
let l:config = ale#Var(a:buffer, 'proto_protolint_config')
return {
\ 'command': l:executable
\ . (!empty(l:config) ? ' -config_path=' . ale#Escape(l:config) : '')
\ . ' -fix'
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction

View File

@ -0,0 +1,17 @@
" Author: BarrOff https://github.com/BarrOff
" Description: Integration of ptop with ALE.
call ale#Set('pascal_ptop_executable', 'ptop')
call ale#Set('pascal_ptop_options', '')
function! ale#fixers#ptop#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'pascal_ptop_executable')
let l:options = ale#Var(a:buffer, 'pascal_ptop_options')
return {
\ 'command': ale#Escape(l:executable)
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' %s %t',
\ 'read_temporary_file': 1,
\}
endfunction

View File

@ -6,7 +6,7 @@ call ale#Set('markdown_remark_lint_use_global', get(g:, 'ale_use_global_executab
call ale#Set('markdown_remark_lint_options', '')
function! ale#fixers#remark_lint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'markdown_remark_lint', [
return ale#path#FindExecutable(a:buffer, 'markdown_remark_lint', [
\ 'node_modules/remark-cli/cli.js',
\ 'node_modules/.bin/remark',
\])

View File

@ -6,7 +6,7 @@ call ale#Set('javascript_standard_use_global', get(g:, 'ale_use_global_executabl
call ale#Set('javascript_standard_options', '')
function! ale#fixers#standard#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_standard', [
return ale#path#FindExecutable(a:buffer, 'javascript_standard', [
\ 'node_modules/standardx/bin/cmd.js',
\ 'node_modules/standard/bin/cmd.js',
\ 'node_modules/.bin/standard',

View File

@ -6,7 +6,7 @@ call ale#Set('stylelint_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('stylelint_options', '')
function! ale#fixers#stylelint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'stylelint', [
return ale#path#FindExecutable(a:buffer, 'stylelint', [
\ 'node_modules/stylelint/bin/stylelint.js',
\ 'node_modules/.bin/stylelint',
\])
@ -17,11 +17,10 @@ function! ale#fixers#stylelint#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'stylelint_options')
return {
\ 'command': ale#path#BufferCdString(a:buffer)
\ . ale#node#Executable(a:buffer, l:executable)
\ . ' %t'
\ 'cwd': '%s:h',
\ 'command': ale#node#Executable(a:buffer, l:executable)
\ . ale#Pad(l:options)
\ . ' --fix',
\ 'read_temporary_file': 1,
\ . ' --fix --stdin --stdin-filename %s',
\ 'read_temporary_file': 0,
\}
endfunction

View File

@ -6,7 +6,7 @@ call ale#Set('swift_swiftformat_use_global', get(g:, 'ale_use_global_executables
call ale#Set('swift_swiftformat_options', '')
function! ale#fixers#swiftformat#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'swift_swiftformat', [
return ale#path#FindExecutable(a:buffer, 'swift_swiftformat', [
\ 'Pods/SwiftFormat/CommandLineTool/swiftformat',
\ 'ios/Pods/SwiftFormat/CommandLineTool/swiftformat',
\ 'swiftformat',

View File

@ -5,7 +5,7 @@ call ale#Set('html_tidy_executable', 'tidy')
call ale#Set('html_tidy_use_global', get(g:, 'ale_use_global_executables', 0))
function! ale#fixers#tidy#Fix(buffer) abort
let l:executable = ale#node#FindExecutable(
let l:executable = ale#path#FindExecutable(
\ a:buffer,
\ 'html_tidy',
\ ['tidy'],

View File

@ -0,0 +1,13 @@
" Author: fiatjaf <fiatjaf@alhur.es>
" Description: Integration of `v fmt` with ALE.
call ale#Set('v_vfmt_options', '')
function! ale#fixers#vfmt#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'v_v_executable')
let l:options = ale#Var(a:buffer, 'v_vfmt_options')
return {
\ 'command': ale#Escape(l:executable) . ' fmt' . ale#Pad(l:options)
\}
endfunction

View File

@ -7,7 +7,6 @@ call ale#Set('yaml_yamlfix_use_global', get(g:, 'ale_use_global_executables', 0)
function! ale#fixers#yamlfix#Fix(buffer) abort
let l:options = ale#Var(a:buffer, 'yaml_yamlfix_options')
let l:executable = ale#python#FindExecutable(
\ a:buffer,
\ 'yaml_yamlfix',
@ -19,7 +18,8 @@ function! ale#fixers#yamlfix#Fix(buffer) abort
endif
return {
\ 'command': ale#path#BufferCdString(a:buffer)
\ . ale#Escape(l:executable) . (!empty(l:options) ? ' ' . l:options : '') . ' -',
\ 'cwd': '%s:h',
\ 'command': ale#Escape(l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '') . ' -',
\}
endfunction

View File

@ -47,16 +47,65 @@ function! ale#floating_preview#Show(lines, ...) abort
endif
augroup END
<<<<<<< HEAD
let l:width = max(map(copy(a:lines), 'strdisplaywidth(v:val)'))
let l:height = min([len(a:lines), 10])
call nvim_win_set_width(w:preview['id'], l:width)
call nvim_win_set_height(w:preview['id'], l:height)
call nvim_buf_set_lines(w:preview['buffer'], 0, -1, v:false, a:lines)
=======
let [l:lines, l:width, l:height] = s:PrepareWindowContent(a:lines)
call nvim_win_set_width(w:preview['id'], l:width)
call nvim_win_set_height(w:preview['id'], l:height)
call nvim_buf_set_lines(w:preview['buffer'], 0, -1, v:false, l:lines)
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
call nvim_buf_set_option(w:preview['buffer'], 'modified', v:false)
call nvim_buf_set_option(w:preview['buffer'], 'modifiable', v:false)
endfunction
<<<<<<< HEAD
=======
function! s:PrepareWindowContent(lines) abort
let l:max_height = 10
let l:width = max(map(copy(a:lines), 'strdisplaywidth(v:val)'))
let l:height = min([len(a:lines), l:max_height])
if empty(g:ale_floating_window_border)
return [a:lines, l:width, l:height]
endif
" Add the size of borders
let l:width += 2
let l:height += 2
let l:hor = g:ale_floating_window_border[0]
let l:top = g:ale_floating_window_border[1]
let l:top_left = g:ale_floating_window_border[2]
let l:top_right = g:ale_floating_window_border[3]
let l:bottom_right = g:ale_floating_window_border[4]
let l:bottom_left = g:ale_floating_window_border[5]
let l:lines = [l:top_left . repeat(l:top, l:width - 2) . l:top_right]
for l:line in a:lines
let l:line_width = strchars(l:line)
let l:lines = add(l:lines, l:hor . l:line . repeat(' ', l:width - l:line_width - 2). l:hor)
endfor
" Truncate the lines
if len(l:lines) > l:max_height + 1
let l:lines = l:lines[0:l:max_height]
endif
let l:lines = add(l:lines, l:bottom_left . repeat(l:top, l:width - 2) . l:bottom_right)
return [l:lines, l:width, l:height]
endfunction
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
function! s:Create(options) abort
let l:buffer = nvim_create_buf(v:false, v:false)
let l:winid = nvim_open_win(l:buffer, v:false, {
@ -76,6 +125,12 @@ function! s:Create(options) abort
endfunction
function! s:Close() abort
<<<<<<< HEAD
=======
let l:mode = mode()
let l:restore_visual = l:mode is# 'v' || l:mode is# 'V' || l:mode is# "\<C-V>"
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
if !exists('w:preview')
return
endif
@ -87,5 +142,13 @@ function! s:Close() abort
endif
unlet w:preview
<<<<<<< HEAD
endfunction
=======
if l:restore_visual
normal! gv
endif
endfunction
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3

View File

@ -42,3 +42,17 @@ function! ale#go#EnvString(buffer) abort
return l:env
endfunction
function! ale#go#GetGoPathExecutable(suffix) abort
let l:prefix = $GOPATH
if !empty($GOPATH)
let l:prefix = $GOPATH
elseif has('win32')
let l:prefix = $USERPROFILE . '/go'
else
let l:prefix = $HOME . '/go'
endif
return ale#path#Simplify(l:prefix . '/' . a:suffix)
endfunction

View File

@ -50,18 +50,25 @@ function! ale#gradle#FindExecutable(buffer) abort
return ''
endfunction
" Given a buffer number, build a command to print the classpath of the root
" project. Returns an empty string if cannot build the command.
" Given a buffer number, get a working directory and command to print the
" classpath of the root project.
"
" Returns an empty string for the command if Gradle is not detected.
function! ale#gradle#BuildClasspathCommand(buffer) abort
let l:executable = ale#gradle#FindExecutable(a:buffer)
let l:project_root = ale#gradle#FindProjectRoot(a:buffer)
if !empty(l:executable) && !empty(l:project_root)
return ale#path#CdString(l:project_root)
\ . ale#Escape(l:executable)
\ . ' -I ' . ale#Escape(s:init_path)
\ . ' -q printClasspath'
if !empty(l:executable)
let l:project_root = ale#gradle#FindProjectRoot(a:buffer)
if !empty(l:project_root)
return [
\ l:project_root,
\ ale#Escape(l:executable)
\ . ' -I ' . ale#Escape(s:init_path)
\ . ' -q printClasspath'
\]
endif
endif
return ''
return ['', '']
endfunction

View File

@ -3,7 +3,7 @@ scriptencoding utf-8
" Description: Error handling for errors in alex output format
function! ale#handlers#alex#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'alex', [
return ale#path#FindExecutable(a:buffer, 'alex', [
\ 'node_modules/.bin/alex',
\ 'node_modules/alex/cli.js',
\])

View File

@ -1,10 +1,9 @@
" Description: Handle errors for cppcheck.
function! ale#handlers#cppcheck#GetCdCommand(buffer) abort
function! ale#handlers#cppcheck#GetCwd(buffer) abort
let [l:dir, l:json_path] = ale#c#FindCompileCommands(a:buffer)
let l:cd_command = !empty(l:dir) ? ale#path#CdString(l:dir) : ''
return l:cd_command
return !empty(l:dir) ? l:dir : ''
endfunction
function! ale#handlers#cppcheck#GetBufferPathIncludeOptions(buffer) abort

View File

@ -2,10 +2,10 @@
" Description: Functions for working with eslint, for checking or fixing files.
let s:executables = [
\ '.yarn/sdks/eslint/bin/eslint.js',
\ 'node_modules/.bin/eslint_d',
\ 'node_modules/eslint/bin/eslint.js',
\ 'node_modules/.bin/eslint',
\ '.yarn/sdks/eslint/bin/eslint',
\]
let s:sep = has('win32') ? '\' : '/'
@ -36,12 +36,11 @@ function! ale#handlers#eslint#FindConfig(buffer) abort
endfunction
function! ale#handlers#eslint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_eslint', s:executables)
return ale#path#FindExecutable(a:buffer, 'javascript_eslint', s:executables)
endfunction
" Given a buffer, return a command prefix string which changes directory
" as necessary for running ESLint.
function! ale#handlers#eslint#GetCdString(buffer) abort
" Given a buffer, return an appropriate working directory for ESLint.
function! ale#handlers#eslint#GetCwd(buffer) abort
" ESLint 6 loads plugins/configs/parsers from the project root
" By default, the project root is simply the CWD of the running process.
" https://github.com/eslint/rfcs/blob/master/designs/2018-simplified-package-loading/README.md
@ -50,17 +49,23 @@ function! ale#handlers#eslint#GetCdString(buffer) abort
" If eslint is installed in a directory which contains the buffer, assume
" it is the ESLint project root. Otherwise, use nearest node_modules.
" Note: If node_modules not present yet, can't load local deps anyway.
let l:executable = ale#node#FindNearestExecutable(a:buffer, s:executables)
let l:executable = ale#path#FindNearestExecutable(a:buffer, s:executables)
if !empty(l:executable)
let l:nmi = strridx(l:executable, 'node_modules')
let l:project_dir = l:executable[0:l:nmi - 2]
let l:modules_index = strridx(l:executable, 'node_modules')
let l:modules_root = l:modules_index > -1 ? l:executable[0:l:modules_index - 2] : ''
let l:sdks_index = strridx(l:executable, ale#path#Simplify('.yarn/sdks'))
let l:sdks_root = l:sdks_index > -1 ? l:executable[0:l:sdks_index - 2] : ''
else
let l:modules_dir = ale#path#FindNearestDirectory(a:buffer, 'node_modules')
let l:project_dir = !empty(l:modules_dir) ? fnamemodify(l:modules_dir, ':h:h') : ''
let l:modules_root = !empty(l:modules_dir) ? fnamemodify(l:modules_dir, ':h:h') : ''
let l:sdks_dir = ale#path#FindNearestDirectory(a:buffer, ale#path#Simplify('.yarn/sdks'))
let l:sdks_root = !empty(l:sdks_dir) ? fnamemodify(l:sdks_dir, ':h:h:h') : ''
endif
return !empty(l:project_dir) ? ale#path#CdString(l:project_dir) : ''
return strlen(l:modules_root) > strlen(l:sdks_root) ? l:modules_root : l:sdks_root
endfunction
function! ale#handlers#eslint#GetCommand(buffer) abort
@ -68,8 +73,7 @@ function! ale#handlers#eslint#GetCommand(buffer) abort
let l:options = ale#Var(a:buffer, 'javascript_eslint_options')
return ale#handlers#eslint#GetCdString(a:buffer)
\ . ale#node#Executable(a:buffer, l:executable)
return ale#node#Executable(a:buffer, l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' -f json --stdin --stdin-filename %s'
endfunction

View File

@ -9,7 +9,7 @@ function! ale#handlers#fecs#GetCommand(buffer) abort
endfunction
function! ale#handlers#fecs#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'javascript_fecs', [
return ale#path#FindExecutable(a:buffer, 'javascript_fecs', [
\ 'node_modules/.bin/fecs',
\ 'node_modules/fecs/bin/fecs',
\])

View File

@ -1,6 +1,16 @@
" Author: Risto Stevcev <me@risto.codes>
" Description: Handlers for the official OCaml language server
<<<<<<< HEAD
=======
let s:language_id_of_filetype = {
\ 'menhir': 'ocaml.menhir',
\ 'ocaml': 'ocaml',
\ 'ocamlinterface': 'ocaml.interface',
\ 'ocamllex': 'ocaml.lex'
\}
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
function! ale#handlers#ocamllsp#GetExecutable(buffer) abort
return 'ocamllsp'
endfunction
@ -13,7 +23,11 @@ function! ale#handlers#ocamllsp#GetCommand(buffer) abort
endfunction
function! ale#handlers#ocamllsp#GetLanguage(buffer) abort
<<<<<<< HEAD
return getbufvar(a:buffer, '&filetype')
=======
return s:language_id_of_filetype[getbufvar(a:buffer, '&filetype')]
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
endfunction
function! ale#handlers#ocamllsp#GetProjectRoot(buffer) abort

View File

@ -4,7 +4,7 @@
function! ale#handlers#ols#GetExecutable(buffer) abort
let l:ols_setting = ale#handlers#ols#GetLanguage(a:buffer) . '_ols'
return ale#node#FindExecutable(a:buffer, l:ols_setting, [
return ale#path#FindExecutable(a:buffer, l:ols_setting, [
\ 'node_modules/.bin/ocaml-language-server',
\])
endfunction

View File

@ -40,21 +40,21 @@ function! ale#handlers#shellcheck#GetDialectArgument(buffer) abort
return ''
endfunction
function! ale#handlers#shellcheck#GetCwd(buffer) abort
return ale#Var(a:buffer, 'sh_shellcheck_change_directory') ? '%s:h' : ''
endfunction
function! ale#handlers#shellcheck#GetCommand(buffer, version) abort
let l:options = ale#Var(a:buffer, 'sh_shellcheck_options')
let l:exclude_option = ale#Var(a:buffer, 'sh_shellcheck_exclusions')
let l:dialect = ale#Var(a:buffer, 'sh_shellcheck_dialect')
let l:external_option = ale#semver#GTE(a:version, [0, 4, 0]) ? ' -x' : ''
let l:cd_string = ale#Var(a:buffer, 'sh_shellcheck_change_directory')
\ ? ale#path#BufferCdString(a:buffer)
\ : ''
if l:dialect is# 'auto'
let l:dialect = ale#handlers#shellcheck#GetDialectArgument(a:buffer)
endif
return l:cd_string
\ . '%e'
return '%e'
\ . (!empty(l:dialect) ? ' -s ' . l:dialect : '')
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . (!empty(l:exclude_option) ? ' -e ' . l:exclude_option : '')
@ -111,6 +111,7 @@ function! ale#handlers#shellcheck#DefineLinter(filetype) abort
call ale#linter#Define(a:filetype, {
\ 'name': 'shellcheck',
\ 'executable': {buffer -> ale#Var(buffer, 'sh_shellcheck_executable')},
\ 'cwd': function('ale#handlers#shellcheck#GetCwd'),
\ 'command': {buffer -> ale#semver#RunWithVersionCheck(
\ buffer,
\ ale#Var(buffer, 'sh_shellcheck_executable'),

View File

@ -0,0 +1,98 @@
" Author: Henrique Barcelos <@hbarcelos>
" Description: Functions for working with local solhint for checking *.sol files.
let s:executables = [
\ 'node_modules/.bin/solhint',
\ 'node_modules/solhint/solhint.js',
\ 'solhint',
\]
let s:sep = has('win32') ? '\' : '/'
call ale#Set('solidity_solhint_options', '')
call ale#Set('solidity_solhint_executable', 'solhint')
call ale#Set('solidity_solhint_use_global', get(g:, 'ale_use_global_executables', 0))
function! ale#handlers#solhint#Handle(buffer, lines) abort
" Matches patterns like the following:
" /path/to/file/file.sol: line 1, col 10, Error - 'addOne' is defined but never used. (no-unused-vars)
let l:output = []
let l:lint_pattern = '\v^[^:]+: line (\d+), col (\d+), (Error|Warning) - (.*) \((.*)\)$'
for l:match in ale#util#GetMatches(a:lines, l:lint_pattern)
let l:isError = l:match[3] is? 'error'
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:match[4],
\ 'code': l:match[5],
\ 'type': l:isError ? 'E' : 'W',
\})
endfor
let l:syntax_pattern = '\v^[^:]+: line (\d+), col (\d+), (Error|Warning) - (Parse error): (.*)$'
for l:match in ale#util#GetMatches(a:lines, l:syntax_pattern)
let l:isError = l:match[3] is? 'error'
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'text': l:match[5],
\ 'code': l:match[4],
\ 'type': l:isError ? 'E' : 'W',
\})
endfor
return l:output
endfunction
function! ale#handlers#solhint#FindConfig(buffer) abort
for l:path in ale#path#Upwards(expand('#' . a:buffer . ':p:h'))
for l:basename in [
\ '.solhintrc.js',
\ '.solhintrc.json',
\ '.solhintrc',
\]
let l:config = ale#path#Simplify(join([l:path, l:basename], s:sep))
if filereadable(l:config)
return l:config
endif
endfor
endfor
return ale#path#FindNearestFile(a:buffer, 'package.json')
endfunction
function! ale#handlers#solhint#GetExecutable(buffer) abort
return ale#path#FindExecutable(a:buffer, 'solidity_solhint', s:executables)
endfunction
" Given a buffer, return an appropriate working directory for solhint.
function! ale#handlers#solhint#GetCwd(buffer) abort
" If solhint is installed in a directory which contains the buffer, assume
" it is the solhint project root. Otherwise, use nearest node_modules.
" Note: If node_modules not present yet, can't load local deps anyway.
let l:executable = ale#path#FindNearestExecutable(a:buffer, s:executables)
if !empty(l:executable)
let l:nmi = strridx(l:executable, 'node_modules')
let l:project_dir = l:executable[0:l:nmi - 2]
else
let l:modules_dir = ale#path#FindNearestDirectory(a:buffer, 'node_modules')
let l:project_dir = !empty(l:modules_dir) ? fnamemodify(l:modules_dir, ':h:h') : ''
endif
return !empty(l:project_dir) ? l:project_dir : ''
endfunction
function! ale#handlers#solhint#GetCommand(buffer) abort
let l:executable = ale#handlers#solhint#GetExecutable(a:buffer)
let l:options = ale#Var(a:buffer, 'solidity_solhint_options')
return ale#node#Executable(a:buffer, l:executable)
\ . (!empty(l:options) ? ' ' . l:options : '')
\ . ' --formatter compact %s'
endfunction

View File

@ -6,7 +6,7 @@ call ale#Set('textlint_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('textlint_options', '')
function! ale#handlers#textlint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'textlint', [
return ale#path#FindExecutable(a:buffer, 'textlint', [
\ 'node_modules/.bin/textlint',
\ 'node_modules/textlint/bin/textlint.js',
\])

View File

@ -7,7 +7,7 @@ function! ale#handlers#tslint#InitVariables() abort
endfunction
function! ale#handlers#tslint#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'typescript_tslint', [
return ale#path#FindExecutable(a:buffer, 'typescript_tslint', [
\ 'node_modules/.bin/tslint',
\])
endfunction

View File

@ -11,7 +11,7 @@ endfunction
call ale#handlers#writegood#ResetOptions()
function! ale#handlers#writegood#GetExecutable(buffer) abort
return ale#node#FindExecutable(a:buffer, 'writegood', [
return ale#path#FindExecutable(a:buffer, 'writegood', [
\ 'node_modules/.bin/write-good',
\ 'node_modules/write-good/bin/write-good.js',
\])

View File

@ -9,7 +9,11 @@ call ale#Set('typescript_xo_options', '')
function! ale#handlers#xo#GetExecutable(buffer) abort
let l:type = ale#handlers#xo#GetType(a:buffer)
<<<<<<< HEAD
return ale#node#FindExecutable(a:buffer, l:type . '_xo', [
=======
return ale#path#FindExecutable(a:buffer, l:type . '_xo', [
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
\ 'node_modules/xo/cli.js',
\ 'node_modules/.bin/xo',
\])

View File

@ -41,7 +41,7 @@ let s:default_ale_linters = {
\ 'apkbuild': ['apkbuild_lint', 'secfixes_check'],
\ 'csh': ['shell'],
\ 'elixir': ['credo', 'dialyxir', 'dogma'],
\ 'go': ['gofmt', 'golint', 'go vet'],
\ 'go': ['gofmt', 'golint', 'gopls', 'govet'],
\ 'hack': ['hack'],
\ 'help': [],
\ 'inko': ['inko'],
@ -53,6 +53,7 @@ let s:default_ale_linters = {
\ 'text': [],
\ 'vue': ['eslint', 'vls'],
\ 'zsh': ['shell'],
\ 'v': ['v'],
\}
" Testing/debugging helper to unload all linters.
@ -151,17 +152,30 @@ function! ale#linter#PreProcess(filetype, linter) abort
endif
let l:obj.address = a:linter.address
if has_key(a:linter, 'cwd')
throw '`cwd` makes no sense for socket LSP connections'
endif
else
throw '`address` must be defined for getting the LSP address'
endif
if has_key(a:linter, 'cwd')
let l:obj.cwd = a:linter.cwd
if type(l:obj.cwd) isnot v:t_string
\&& type(l:obj.cwd) isnot v:t_func
throw '`cwd` must be a String or Function if defined'
endif
endif
if l:needs_lsp_details
" Default to using the filetype as the language.
let l:obj.language = get(a:linter, 'language', a:filetype)
if type(l:obj.language) isnot v:t_string
\&& type(l:obj.language) isnot v:t_func
throw '`language` must be a String or Funcref if defined'
throw '`language` must be a String or Function if defined'
endif
if has_key(a:linter, 'project_root')
@ -415,6 +429,12 @@ function! ale#linter#GetExecutable(buffer, linter) abort
\ : l:Executable
endfunction
function! ale#linter#GetCwd(buffer, linter) abort
let l:Cwd = get(a:linter, 'cwd', v:null)
return type(l:Cwd) is v:t_func ? l:Cwd(a:buffer) : l:Cwd
endfunction
" Given a buffer and linter, get the command String for the linter.
function! ale#linter#GetCommand(buffer, linter) abort
let l:Command = a:linter.command

View File

@ -357,6 +357,7 @@ function! ale#lsp#MarkConnectionAsTsserver(conn_id) abort
let l:conn.capabilities.completion = 1
let l:conn.capabilities.completion_trigger_characters = ['.']
let l:conn.capabilities.definition = 1
let l:conn.capabilities.typeDefinition = 1
let l:conn.capabilities.symbol_search = 1
let l:conn.capabilities.rename = 1
let l:conn.capabilities.code_actions = 1

View File

@ -64,6 +64,14 @@ function! ale#lsp#tsserver_message#Definition(buffer, line, column) abort
\}]
endfunction
function! ale#lsp#tsserver_message#TypeDefinition(buffer, line, column) abort
return [0, 'ts@typeDefinition', {
\ 'line': a:line,
\ 'offset': a:column,
\ 'file': expand('#' . a:buffer . ':p'),
\}]
endfunction
function! ale#lsp#tsserver_message#References(buffer, line, column) abort
return [0, 'ts@references', {
\ 'line': a:line,

View File

@ -201,7 +201,11 @@ function! ale#lsp_linter#GetConfig(buffer, linter) abort
endfunction
function! ale#lsp_linter#FindProjectRoot(buffer, linter) abort
let l:buffer_ale_root = getbufvar(a:buffer, 'ale_lsp_root', {})
let l:buffer_ale_root = getbufvar(
\ a:buffer,
\ 'ale_root',
\ getbufvar(a:buffer, 'ale_lsp_root', {})
\)
if type(l:buffer_ale_root) is v:t_string
return l:buffer_ale_root
@ -218,9 +222,15 @@ function! ale#lsp_linter#FindProjectRoot(buffer, linter) abort
endif
endif
let l:global_root = g:ale_root
if empty(g:ale_root) && exists('g:ale_lsp_root')
let l:global_root = g:ale_lsp_root
endif
" Try to get a global setting for the root
if has_key(g:ale_lsp_root, a:linter.name)
let l:Root = g:ale_lsp_root[a:linter.name]
if has_key(l:global_root, a:linter.name)
let l:Root = l:global_root[a:linter.name]
if type(l:Root) is v:t_func
return l:Root(a:buffer)
@ -284,13 +294,15 @@ function! s:StartLSP(options, address, executable, command) abort
call ale#lsp#MarkConnectionAsTsserver(l:conn_id)
endif
let l:cwd = ale#linter#GetCwd(l:buffer, l:linter)
let l:command = ale#command#FormatCommand(
\ l:buffer,
\ a:executable,
\ a:command,
\ 0,
\ v:false,
\ [],
\ l:cwd,
\ ale#GetFilenameMappings(l:buffer, l:linter.name),
\)[1]
let l:command = ale#job#PrepareCommand(l:buffer, l:command)
let l:ready = ale#lsp#StartProgram(l:conn_id, a:executable, l:command)

View File

@ -17,7 +17,6 @@ function! ale#maven#FindProjectRoot(buffer) abort
return ''
endfunction
" Given a buffer number, find the path to the executable.
" First search on the path for 'mvnw' (mvnw.cmd on Windows), if nothing is found,
" try the global command. Returns an empty string if cannot find the executable.
@ -36,16 +35,23 @@ function! ale#maven#FindExecutable(buffer) abort
return ''
endfunction
" Given a buffer number, build a command to print the classpath of the root
" project. Returns an empty string if cannot build the command.
" Given a buffer number, get a working directory and command to print the
" classpath of the root project.
"
" Returns an empty string for the command if Maven is not detected.
function! ale#maven#BuildClasspathCommand(buffer) abort
let l:executable = ale#maven#FindExecutable(a:buffer)
let l:project_root = ale#maven#FindProjectRoot(a:buffer)
if !empty(l:executable) && !empty(l:project_root)
return ale#path#CdString(l:project_root)
\ . l:executable . ' dependency:build-classpath'
if !empty(l:executable)
let l:project_root = ale#maven#FindProjectRoot(a:buffer)
if !empty(l:project_root)
return [
\ l:project_root,
\ ale#Escape(l:executable) . ' dependency:build-classpath'
\]
endif
endif
return ''
return ['', '']
endfunction

View File

@ -3,38 +3,6 @@
call ale#Set('windows_node_executable_path', 'node.exe')
" Given a buffer number, a base variable name, and a list of paths to search
" for in ancestor directories, detect the executable path for a Node program.
"
" The use_global and executable options for the relevant program will be used.
function! ale#node#FindExecutable(buffer, base_var_name, path_list) abort
if ale#Var(a:buffer, a:base_var_name . '_use_global')
return ale#Var(a:buffer, a:base_var_name . '_executable')
endif
let l:nearest = ale#node#FindNearestExecutable(a:buffer, a:path_list)
if !empty(l:nearest)
return l:nearest
endif
return ale#Var(a:buffer, a:base_var_name . '_executable')
endfunction
" Given a buffer number, a base variable name, and a list of paths to search
" for in ancestor directories, detect the executable path for a Node program.
function! ale#node#FindNearestExecutable(buffer, path_list) abort
for l:path in a:path_list
let l:executable = ale#path#FindNearestFile(a:buffer, l:path)
if !empty(l:executable)
return l:executable
endif
endfor
return ''
endfunction
" Create a executable string which executes a Node.js script command with a
" Node.js executable if needed.
"

View File

@ -77,24 +77,40 @@ function! ale#path#ResolveLocalPath(buffer, search_string, global_fallback) abor
return l:path
endfunction
" Output 'cd <directory> && '
" This function can be used changing the directory for a linter command.
function! ale#path#CdString(directory) abort
if has('win32')
return 'cd /d ' . ale#Escape(a:directory) . ' && '
endif
" Given a buffer number, a base variable name, and a list of paths to search
" for in ancestor directories, detect the executable path for a program.
function! ale#path#FindNearestExecutable(buffer, path_list) abort
for l:path in a:path_list
if ale#path#IsAbsolute(l:path)
let l:executable = filereadable(l:path) ? l:path : ''
else
let l:executable = ale#path#FindNearestFile(a:buffer, l:path)
endif
return 'cd ' . ale#Escape(a:directory) . ' && '
if !empty(l:executable)
return l:executable
endif
endfor
return ''
endfunction
" Output 'cd <buffer_filename_directory> && '
" This function can be used changing the directory for a linter command.
function! ale#path#BufferCdString(buffer) abort
if has('win32')
return 'cd /d %s:h && '
" Given a buffer number, a base variable name, and a list of paths to search
" for in ancestor directories, detect the executable path for a program.
"
" The use_global and executable options for the relevant program will be used.
function! ale#path#FindExecutable(buffer, base_var_name, path_list) abort
if ale#Var(a:buffer, a:base_var_name . '_use_global')
return ale#Var(a:buffer, a:base_var_name . '_executable')
endif
return 'cd %s:h && '
let l:nearest = ale#path#FindNearestExecutable(a:buffer, a:path_list)
if !empty(l:nearest)
return l:nearest
endif
return ale#Var(a:buffer, a:base_var_name . '_executable')
endfunction
" Return 1 if a path is an absolute path.
@ -136,7 +152,7 @@ function! ale#path#Dirname(path) abort
endif
" For /foo/bar/ we need :h:h to get /foo
if a:path[-1:] is# '/'
if a:path[-1:] is# '/' || (has('win32') && a:path[-1:] is# '\')
return fnamemodify(a:path, ':h:h')
endif

View File

@ -52,9 +52,13 @@ endif
function! ale#sign#SetUpDefaultColumnWithoutErrorsHighlight() abort
let l:verbose = &verbose
set verbose=0
<<<<<<< HEAD
redir => l:output
0verbose silent highlight SignColumn
redir end
=======
let l:output = execute('highlight SignColumn', 'silent')
>>>>>>> 1cca3b1df2973096bb9526a0d79c7b93c04e66b3
let &verbose = l:verbose
let l:highlight_syntax = join(split(l:output)[2:])
@ -171,10 +175,10 @@ endfunction
" Read sign data for a buffer to a list of lines.
function! ale#sign#ReadSigns(buffer) abort
redir => l:output
silent execute 'sign place ' . s:GroupCmd() . s:PriorityCmd()
\ . ' buffer=' . a:buffer
redir end
let l:output = execute(
\ 'sign place ' . s:GroupCmd() . s:PriorityCmd()
\ . ' buffer=' . a:buffer
\ )
return split(l:output, "\n")
endfunction
@ -203,6 +207,27 @@ function! ale#sign#ParsePattern() abort
return l:pattern
endfunction
" Given a buffer number, return a List of placed signs [line, id, group]
function! ale#sign#ParseSignsWithGetPlaced(buffer) abort
let l:signs = sign_getplaced(a:buffer, { 'group': s:supports_sign_groups ? 'ale' : '' })[0].signs
let l:result = []
let l:is_dummy_sign_set = 0
for l:sign in l:signs
if l:sign['name'] is# 'ALEDummySign'
let l:is_dummy_sign_set = 1
else
call add(l:result, [
\ str2nr(l:sign['lnum']),
\ str2nr(l:sign['id']),
\ l:sign['name'],
\])
endif
endfor
return [l:is_dummy_sign_set, l:result]
endfunction
" Given a list of lines for sign output, return a List of [line, id, group]
function! ale#sign#ParseSigns(line_list) abort
let l:pattern =ale#sign#ParsePattern()
@ -229,9 +254,13 @@ function! ale#sign#ParseSigns(line_list) abort
endfunction
function! ale#sign#FindCurrentSigns(buffer) abort
let l:line_list = ale#sign#ReadSigns(a:buffer)
if exists('*sign_getplaced')
return ale#sign#ParseSignsWithGetPlaced(a:buffer)
else
let l:line_list = ale#sign#ReadSigns(a:buffer)
return ale#sign#ParseSigns(l:line_list)
return ale#sign#ParseSigns(l:line_list)
endif
endfunction
" Given a loclist, group the List into with one List per line.

View File

@ -11,3 +11,60 @@ function! ale#swift#FindProjectRoot(buffer) abort
return ''
endfunction
" Support Apple Swift Format {{{1
call ale#Set('swift_appleswiftformat_executable', 'swift-format')
call ale#Set('swift_appleswiftformat_use_swiftpm', 0)
" Return the executable depending on whether or not to use Swift Package Manager.
"
" If not asked to use Swift Package Manager (use_swiftpm = 0), the returned
" value is the global executable, else the returned value is 'swift' because
" the final command line will be `swift run swift-format ...`.
"
" Failure is expected if use_swiftpm is `1` but no Package.swift can be located.
function! ale#swift#GetAppleSwiftFormatExecutable(buffer) abort
if !ale#Var(a:buffer, 'swift_appleswiftformat_use_swiftpm')
return ale#Var(a:buffer, 'swift_appleswiftformat_executable')
endif
if ale#path#FindNearestFile(a:buffer, 'Package.swift') is# ''
" If there is no Package.swift file, we don't use swift-format even if it exists,
" so we return '' to indicate failure.
return ''
endif
return 'swift'
endfunction
" Return the command depending on whether or not to use Swift Package Manager.
"
" If asked to use Swift Package Manager (use_swiftpm = 1), the command
" arguments are prefixed with 'swift run'.
"
" In either case, the configuration file is located and added to the command.
function! ale#swift#GetAppleSwiftFormatCommand(buffer) abort
let l:executable = ale#swift#GetAppleSwiftFormatExecutable(a:buffer)
let l:command_args = ''
if ale#Var(a:buffer, 'swift_appleswiftformat_use_swiftpm')
let l:command_args = ' ' . 'run swift-format'
endif
return ale#Escape(l:executable) . l:command_args
endfunction
" Locate the nearest '.swift-format' configuration file, and return the
" arguments, else return an empty string.
function! ale#swift#GetAppleSwiftFormatConfigArgs(buffer) abort
let l:config_filepath = ale#path#FindNearestFile(a:buffer, '.swift-format')
if l:config_filepath isnot# ''
return '--configuration' . ' ' . l:config_filepath
endif
return ''
endfunction
" }}}

View File

@ -34,12 +34,11 @@ function! ale#test#RestoreDirectory() abort
unlet! g:dir
endfunction
" Change the filename for the current buffer using a relative path to
" the script without running autocmd commands.
" Get a filename for the current buffer using a relative path to the script.
"
" If a g:dir variable is set, it will be used as the path to the directory
" containing the test file.
function! ale#test#SetFilename(path) abort
function! ale#test#GetFilename(path) abort
let l:dir = get(g:, 'dir', '')
if empty(l:dir)
@ -50,7 +49,17 @@ function! ale#test#SetFilename(path) abort
\ ? a:path
\ : l:dir . '/' . a:path
silent! noautocmd execute 'file ' . fnameescape(ale#path#Simplify(l:full_path))
return ale#path#Simplify(l:full_path)
endfunction
" Change the filename for the current buffer using a relative path to
" the script without running autocmd commands.
"
" If a g:dir variable is set, it will be used as the path to the directory
" containing the test file.
function! ale#test#SetFilename(path) abort
let l:full_path = ale#test#GetFilename(a:path)
silent! noautocmd execute 'file ' . fnameescape(l:full_path)
endfunction
function! s:RemoveModule(results) abort

View File

@ -340,6 +340,16 @@ function! ale#util#GetMatches(lines, patterns) abort
return l:matches
endfunction
" Given a single line, or a List of lines, and a single pattern, or a List of
" patterns, and a callback function for mapping the items matches, return the
" result of mapping all of the matches for the lines from the given patterns,
" using matchlist()
"
" Only the first pattern which matches a line will be returned.
function! ale#util#MapMatches(lines, patterns, Callback) abort
return map(ale#util#GetMatches(a:lines, a:patterns), 'a:Callback(v:val)')
endfunction
function! s:LoadArgCount(function) abort
try
let l:output = execute('function a:function')