mirror of
https://github.com/amix/vimrc
synced 2025-09-16 17:15:00 +08:00
modified
This commit is contained in:
@ -48,26 +48,38 @@ endfunction
|
||||
|
||||
function! ale#c#ParseCFlags(path_prefix, cflag_line) abort
|
||||
let l:cflags_list = []
|
||||
let l:previous_options = []
|
||||
let l:previous_options = ''
|
||||
|
||||
let l:split_lines = split(a:cflag_line, '-')
|
||||
let l:split_lines = split(a:cflag_line, ' ')
|
||||
let l:option_index = 0
|
||||
|
||||
while l:option_index < len(l:split_lines)
|
||||
let l:option = l:split_lines[l:option_index]
|
||||
let l:option = l:previous_options . l:split_lines[l:option_index]
|
||||
let l:option_index = l:option_index + 1
|
||||
call add(l:previous_options, l:option)
|
||||
" Check if cflag contained a '-' and should not have been splitted
|
||||
let l:option_list = split(l:option, '\zs')
|
||||
|
||||
if len(l:option_list) > 0 && l:option_list[-1] isnot# ' ' && l:option_index < len(l:split_lines)
|
||||
" Check if cflag contained an unmatched characters and should not have been splitted
|
||||
let l:option_special = substitute(l:option, '\\"', '', 'g')
|
||||
let l:option_special = substitute(l:option_special, '[^"''()`]', '', 'g')
|
||||
let l:option_special = substitute(l:option_special, '""', '', 'g')
|
||||
let l:option_special = substitute(l:option_special, '''''', '', 'g')
|
||||
let l:option_special = substitute(l:option_special, '``', '', 'g')
|
||||
let l:option_special = substitute(l:option_special, '((', '(', 'g')
|
||||
let l:option_special = substitute(l:option_special, '))', ')', 'g')
|
||||
let l:option_special = substitute(l:option_special, '()', '', 'g')
|
||||
|
||||
if len(l:option_special) > 0 && l:option_index < len(l:split_lines)
|
||||
let l:previous_options = l:option . ' '
|
||||
continue
|
||||
endif
|
||||
|
||||
let l:option = join(l:previous_options, '-')
|
||||
let l:previous_options = []
|
||||
" Check if there was spaces after -D/-I and the flag should not have been splitted
|
||||
if l:option is# '-D' || l:option is# '-I'
|
||||
let l:previous_options = l:option
|
||||
continue
|
||||
endif
|
||||
|
||||
let l:previous_options = ''
|
||||
|
||||
let l:option = '-' . substitute(l:option, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
|
||||
" Fix relative paths if needed
|
||||
if stridx(l:option, '-I') >= 0 &&
|
||||
|
@ -86,7 +86,7 @@ function! s:OnReady(linter, lsp_details, line, column, options, ...) abort
|
||||
let l:request_id = ale#lsp#Send(l:id, l:message)
|
||||
|
||||
let s:go_to_definition_map[l:request_id] = {
|
||||
\ 'open_in_tab': get(a:options, 'open_in_tab', 0),
|
||||
\ 'open_in': get(a:options, 'open_in', 'current-buffer'),
|
||||
\}
|
||||
endfunction
|
||||
|
||||
|
@ -315,10 +315,10 @@ function! s:RunFixer(options) abort
|
||||
\ ? call(l:Function, [l:buffer, a:options.output])
|
||||
\ : call(l:Function, [l:buffer, a:options.output, copy(l:input)])
|
||||
else
|
||||
" Chained commands accept (buffer, [input])
|
||||
" Chained commands accept (buffer, [done, input])
|
||||
let l:result = ale#util#FunctionArgCount(l:Function) == 1
|
||||
\ ? call(l:Function, [l:buffer])
|
||||
\ : call(l:Function, [l:buffer, copy(l:input)])
|
||||
\ : call(l:Function, [l:buffer, v:null, copy(l:input)])
|
||||
endif
|
||||
|
||||
if type(l:result) is v:t_number && l:result == 0
|
||||
|
@ -4,22 +4,28 @@
|
||||
call ale#Set('python_black_executable', 'black')
|
||||
call ale#Set('python_black_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
call ale#Set('python_black_options', '')
|
||||
call ale#Set('python_black_auto_pipenv', 0)
|
||||
|
||||
function! ale#fixers#black#GetExecutable(buffer) abort
|
||||
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_black_auto_pipenv'))
|
||||
\ && ale#python#PipenvPresent(a:buffer)
|
||||
return 'pipenv'
|
||||
endif
|
||||
|
||||
return ale#python#FindExecutable(a:buffer, 'python_black', ['black'])
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#black#Fix(buffer) abort
|
||||
let l:executable = ale#python#FindExecutable(
|
||||
\ a:buffer,
|
||||
\ 'python_black',
|
||||
\ ['black'],
|
||||
\)
|
||||
let l:executable = ale#fixers#black#GetExecutable(a:buffer)
|
||||
|
||||
if !executable(l:executable)
|
||||
return 0
|
||||
endif
|
||||
let l:exec_args = l:executable =~? 'pipenv$'
|
||||
\ ? ' run black'
|
||||
\ : ''
|
||||
|
||||
let l:options = ale#Var(a:buffer, 'python_black_options')
|
||||
|
||||
return {
|
||||
\ 'command': ale#Escape(l:executable)
|
||||
\ 'command': ale#Escape(l:executable) . l:exec_args
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . ' -',
|
||||
\}
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: Generic functions for fixing files with.
|
||||
|
||||
function! ale#fixers#generic#RemoveTrailingBlankLines(buffer, lines) abort
|
||||
function! ale#fixers#generic#RemoveTrailingBlankLines(buffer, done, lines) abort
|
||||
let l:end_index = len(a:lines) - 1
|
||||
|
||||
while l:end_index > 0 && empty(a:lines[l:end_index])
|
||||
@ -12,7 +12,7 @@ function! ale#fixers#generic#RemoveTrailingBlankLines(buffer, lines) abort
|
||||
endfunction
|
||||
|
||||
" Remove all whitespaces at the end of lines
|
||||
function! ale#fixers#generic#TrimWhitespace(buffer, lines) abort
|
||||
function! ale#fixers#generic#TrimWhitespace(buffer, done, lines) abort
|
||||
let l:index = 0
|
||||
let l:lines_new = range(len(a:lines))
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
" Description: Generic fixer functions for Python.
|
||||
|
||||
" Add blank lines before control statements.
|
||||
function! ale#fixers#generic_python#AddLinesBeforeControlStatements(buffer, lines) abort
|
||||
function! ale#fixers#generic_python#AddLinesBeforeControlStatements(buffer, done, lines) abort
|
||||
let l:new_lines = []
|
||||
let l:last_indent_size = 0
|
||||
let l:last_line_is_blank = 0
|
||||
@ -41,7 +41,7 @@ endfunction
|
||||
|
||||
" This function breaks up long lines so that autopep8 or other tools can
|
||||
" fix the badly-indented code which is produced as a result.
|
||||
function! ale#fixers#generic_python#BreakUpLongLines(buffer, lines) abort
|
||||
function! ale#fixers#generic_python#BreakUpLongLines(buffer, done, lines) abort
|
||||
" Default to a maximum line length of 79
|
||||
let l:max_line_length = 79
|
||||
let l:conf = ale#path#FindNearestFile(a:buffer, 'setup.cfg')
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: Generic fixer functions for Vim help documents.
|
||||
|
||||
function! ale#fixers#help#AlignTags(buffer, lines) abort
|
||||
function! ale#fixers#help#AlignTags(buffer, done, lines) abort
|
||||
let l:new_lines = []
|
||||
|
||||
for l:line in a:lines
|
||||
|
@ -14,9 +14,11 @@ endfunction
|
||||
|
||||
function! ale#fixers#standard#Fix(buffer) abort
|
||||
let l:executable = ale#fixers#standard#GetExecutable(a:buffer)
|
||||
let l:options = ale#Var(a:buffer, 'javascript_standard_options')
|
||||
|
||||
return {
|
||||
\ 'command': ale#node#Executable(a:buffer, l:executable)
|
||||
\ . (!empty(l:options) ? ' ' . l:options : '')
|
||||
\ . ' --fix %t',
|
||||
\ 'read_temporary_file': 1,
|
||||
\}
|
||||
|
@ -173,10 +173,6 @@ endfunction
|
||||
function! ale#job#PrepareCommand(buffer, command) abort
|
||||
let l:wrapper = ale#Var(a:buffer, 'command_wrapper')
|
||||
|
||||
let l:command = !empty(l:wrapper)
|
||||
\ ? s:PrepareWrappedCommand(l:wrapper, a:command)
|
||||
\ : a:command
|
||||
|
||||
" The command will be executed in a subshell. This fixes a number of
|
||||
" issues, including reading the PATH variables correctly, %PATHEXT%
|
||||
" expansion on Windows, etc.
|
||||
@ -184,6 +180,17 @@ function! ale#job#PrepareCommand(buffer, command) abort
|
||||
" NeoVim handles this issue automatically if the command is a String,
|
||||
" but we'll do this explicitly, so we use the same exact command for both
|
||||
" versions.
|
||||
let l:command = !empty(l:wrapper)
|
||||
\ ? s:PrepareWrappedCommand(l:wrapper, a:command)
|
||||
\ : a:command
|
||||
|
||||
" If a custom shell is specified, use that.
|
||||
if exists('g:ale_shell')
|
||||
let l:shell_arguments = get(g:, 'ale_shell_arguments', &shellcmdflag)
|
||||
|
||||
return split(g:ale_shell) + split(l:shell_arguments) + [l:command]
|
||||
endif
|
||||
|
||||
if has('win32')
|
||||
return 'cmd /s/c "' . l:command . '"'
|
||||
endif
|
||||
|
@ -27,6 +27,7 @@ function! ale#references#HandleTSServerResponse(conn_id, response) abort
|
||||
\ 'filename': l:response_item.file,
|
||||
\ 'line': l:response_item.start.line,
|
||||
\ 'column': l:response_item.start.offset,
|
||||
\ 'match': substitute(l:response_item.lineText, '^\s*\(.\{-}\)\s*$', '\1', ''),
|
||||
\})
|
||||
endfor
|
||||
|
||||
|
@ -87,12 +87,25 @@ function! ale#util#GetFunction(string_or_ref) abort
|
||||
return a:string_or_ref
|
||||
endfunction
|
||||
|
||||
" Open the file (at the given line).
|
||||
" options['open_in'] can be:
|
||||
" current-buffer (default)
|
||||
" tab
|
||||
" vertical-split
|
||||
" horizontal-split
|
||||
function! ale#util#Open(filename, line, column, options) abort
|
||||
if get(a:options, 'open_in_tab', 0)
|
||||
call ale#util#Execute('tabedit +' . a:line . ' ' . fnameescape(a:filename))
|
||||
let l:open_in = get(a:options, 'open_in', 'current-buffer')
|
||||
let l:args_to_open = '+' . a:line . ' ' . fnameescape(a:filename)
|
||||
|
||||
if l:open_in is# 'tab'
|
||||
call ale#util#Execute('tabedit ' . l:args_to_open)
|
||||
elseif l:open_in is# 'horizontal-split'
|
||||
call ale#util#Execute('split ' . l:args_to_open)
|
||||
elseif l:open_in is# 'vertical-split'
|
||||
call ale#util#Execute('vsplit ' . l:args_to_open)
|
||||
elseif bufnr(a:filename) isnot bufnr('')
|
||||
" Open another file only if we need to.
|
||||
call ale#util#Execute('edit +' . a:line . ' ' . fnameescape(a:filename))
|
||||
call ale#util#Execute('edit ' . l:args_to_open)
|
||||
else
|
||||
normal! m`
|
||||
endif
|
||||
|
Reference in New Issue
Block a user