mirror of
https://github.com/amix/vimrc
synced 2025-06-23 15:04:59 +08:00
Updated plugins
This commit is contained in:
@ -258,9 +258,9 @@ function! ale#GetLocItemMessage(item, format_string) abort
|
||||
|
||||
" Replace special markers with certain information.
|
||||
" \=l:variable is used to avoid escaping issues.
|
||||
let l:msg = substitute(l:msg, '\v\%([^\%]*)code([^\%]*)\%', l:code_repl, 'g')
|
||||
let l:msg = substitute(l:msg, '\V%severity%', '\=l:severity', 'g')
|
||||
let l:msg = substitute(l:msg, '\V%linter%', '\=l:linter_name', 'g')
|
||||
let l:msg = substitute(l:msg, '\v\%([^\%]*)code([^\%]*)\%', l:code_repl, 'g')
|
||||
" Replace %s with the text.
|
||||
let l:msg = substitute(l:msg, '\V%s', '\=a:item.text', 'g')
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
" Author: Andrew Lee <andrewl@mbda.fun>.
|
||||
" Author: Andrew Lee <andrew.lambda@tuta.io>.
|
||||
" Inspired by ale/gradle.vim by Michael Pardo <michael@michaelpardo.com>
|
||||
" Description: Functions for working with Ant projects.
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
" Author: Jerko Steiner <jerko.steiner@gmail.com>
|
||||
" Description: Code action support for LSP / tsserver
|
||||
|
||||
function! ale#code_action#HandleCodeAction(code_action) abort
|
||||
function! ale#code_action#HandleCodeAction(code_action, should_save) abort
|
||||
let l:current_buffer = bufnr('')
|
||||
let l:changes = a:code_action.changes
|
||||
|
||||
@ -17,11 +17,14 @@ function! ale#code_action#HandleCodeAction(code_action) abort
|
||||
|
||||
for l:file_code_edit in l:changes
|
||||
call ale#code_action#ApplyChanges(
|
||||
\ l:file_code_edit.fileName, l:file_code_edit.textChanges)
|
||||
\ l:file_code_edit.fileName,
|
||||
\ l:file_code_edit.textChanges,
|
||||
\ a:should_save,
|
||||
\ )
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! ale#code_action#ApplyChanges(filename, changes) abort
|
||||
function! ale#code_action#ApplyChanges(filename, changes, should_save) abort
|
||||
let l:current_buffer = bufnr('')
|
||||
" The buffer is used to determine the fileformat, if available.
|
||||
let l:buffer = bufnr(a:filename)
|
||||
@ -106,10 +109,17 @@ function! ale#code_action#ApplyChanges(filename, changes) abort
|
||||
call remove(l:lines, -1)
|
||||
endif
|
||||
|
||||
call ale#util#Writefile(l:buffer, l:lines, a:filename)
|
||||
if a:should_save
|
||||
call ale#util#Writefile(l:buffer, l:lines, a:filename)
|
||||
else
|
||||
call ale#util#SetBufferContents(l:buffer, l:lines)
|
||||
endif
|
||||
|
||||
if l:is_current_buffer
|
||||
call ale#util#Execute(':e!')
|
||||
if a:should_save
|
||||
call ale#util#Execute(':e!')
|
||||
endif
|
||||
|
||||
call setpos('.', [0, l:pos[0], l:pos[1], 0])
|
||||
endif
|
||||
endfunction
|
||||
|
@ -823,7 +823,7 @@ function! ale#completion#HandleUserData(completed_item) abort
|
||||
endif
|
||||
|
||||
for l:code_action in get(l:user_data, 'codeActions', [])
|
||||
call ale#code_action#HandleCodeAction(l:code_action)
|
||||
call ale#code_action#HandleCodeAction(l:code_action, v:false)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
|
@ -5,6 +5,7 @@ let s:go_to_definition_map = {}
|
||||
|
||||
" Enable automatic updates of the tagstack
|
||||
let g:ale_update_tagstack = get(g:, 'ale_update_tagstack', 1)
|
||||
let g:ale_default_navigation = get(g:, 'ale_default_navigation', 'buffer')
|
||||
|
||||
" Used to get the definition map in tests.
|
||||
function! ale#definition#GetMap() abort
|
||||
@ -134,6 +135,10 @@ function! s:GoToLSPDefinition(linter, options, capability) abort
|
||||
endfunction
|
||||
|
||||
function! ale#definition#GoTo(options) abort
|
||||
if !get(g:, 'ale_ignore_2_7_warnings') && has_key(a:options, 'deprecated_command')
|
||||
execute 'echom '':' . a:options.deprecated_command . ' is deprecated. Use `let g:ale_ignore_2_7_warnings = 1` to disable this message.'''
|
||||
endif
|
||||
|
||||
for l:linter in ale#linter#Get(&filetype)
|
||||
if !empty(l:linter.lsp)
|
||||
call s:GoToLSPDefinition(l:linter, a:options, 'definition')
|
||||
@ -142,6 +147,10 @@ function! ale#definition#GoTo(options) abort
|
||||
endfunction
|
||||
|
||||
function! ale#definition#GoToType(options) abort
|
||||
if !get(g:, 'ale_ignore_2_7_warnings') && has_key(a:options, 'deprecated_command')
|
||||
execute 'echom '':' . a:options.deprecated_command . ' is deprecated. Use `let g:ale_ignore_2_7_warnings = 1` to disable this message.'''
|
||||
endif
|
||||
|
||||
for l:linter in ale#linter#Get(&filetype)
|
||||
if !empty(l:linter.lsp)
|
||||
" TODO: handle typeDefinition for tsserver if supported by the
|
||||
@ -154,3 +163,33 @@ function! ale#definition#GoToType(options) abort
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! ale#definition#GoToCommandHandler(command, ...) abort
|
||||
let l:options = {}
|
||||
|
||||
if len(a:000) > 0
|
||||
for l:option in a:000
|
||||
if l:option is? '-tab'
|
||||
let l:options.open_in = 'tab'
|
||||
elseif l:option is? '-split'
|
||||
let l:options.open_in = 'split'
|
||||
elseif l:option is? '-vsplit'
|
||||
let l:options.open_in = 'vsplit'
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if !has_key(l:options, 'open_in')
|
||||
let l:default_navigation = ale#Var(bufnr(''), 'default_navigation')
|
||||
|
||||
if index(['tab', 'split', 'vsplit'], l:default_navigation) >= 0
|
||||
let l:options.open_in = l:default_navigation
|
||||
endif
|
||||
endif
|
||||
|
||||
if a:command is# 'type'
|
||||
call ale#definition#GoToType(l:options)
|
||||
else
|
||||
call ale#definition#GoTo(l:options)
|
||||
endif
|
||||
endfunction
|
||||
|
@ -4,40 +4,15 @@ call ale#Set('fix_on_save_ignore', {})
|
||||
" Vim doesn't let you modify hidden buffers.
|
||||
function! ale#fix#ApplyQueuedFixes(buffer) abort
|
||||
let l:data = get(g:ale_fix_buffer_data, a:buffer, {'done': 0})
|
||||
let l:has_bufline_api = exists('*deletebufline') && exists('*setbufline')
|
||||
|
||||
if !l:data.done || (!l:has_bufline_api && a:buffer isnot bufnr(''))
|
||||
if !l:data.done || (!ale#util#HasBuflineApi() && a:buffer isnot bufnr(''))
|
||||
return
|
||||
endif
|
||||
|
||||
call remove(g:ale_fix_buffer_data, a:buffer)
|
||||
|
||||
if l:data.changes_made
|
||||
" If the file is in DOS mode, we have to remove carriage returns from
|
||||
" the ends of lines before calling setline(), or we will see them
|
||||
" twice.
|
||||
let l:new_lines = getbufvar(a:buffer, '&fileformat') is# 'dos'
|
||||
\ ? map(copy(l:data.output), 'substitute(v:val, ''\r\+$'', '''', '''')')
|
||||
\ : l:data.output
|
||||
let l:first_line_to_remove = len(l:new_lines) + 1
|
||||
|
||||
" Use a Vim API for setting lines in other buffers, if available.
|
||||
if l:has_bufline_api
|
||||
call setbufline(a:buffer, 1, l:new_lines)
|
||||
call deletebufline(a:buffer, l:first_line_to_remove, '$')
|
||||
" Fall back on setting lines the old way, for the current buffer.
|
||||
else
|
||||
let l:old_line_length = len(l:data.lines_before)
|
||||
|
||||
if l:old_line_length >= l:first_line_to_remove
|
||||
let l:save = winsaveview()
|
||||
silent execute
|
||||
\ l:first_line_to_remove . ',' . l:old_line_length . 'd_'
|
||||
call winrestview(l:save)
|
||||
endif
|
||||
|
||||
call setline(1, l:new_lines)
|
||||
endif
|
||||
let l:new_lines = ale#util#SetBufferContents(a:buffer, l:data.output)
|
||||
|
||||
if l:data.should_save
|
||||
if a:buffer is bufnr('')
|
||||
|
@ -210,6 +210,12 @@ function! ale#highlight#SetHighlights(buffer, loclist) abort
|
||||
" Set the list in the buffer variable.
|
||||
call setbufvar(str2nr(a:buffer), 'ale_highlight_items', l:new_list)
|
||||
|
||||
let l:exclude_list = ale#Var(a:buffer, 'exclude_highlights')
|
||||
|
||||
if !empty(l:exclude_list)
|
||||
call filter(l:new_list, 'empty(ale#util#GetMatches(v:val.text, l:exclude_list))')
|
||||
endif
|
||||
|
||||
" Update highlights for the current buffer, which may or may not
|
||||
" be the buffer we just set highlights for.
|
||||
call ale#highlight#UpdateHighlights()
|
||||
|
@ -15,7 +15,7 @@ function! ale#organize_imports#HandleTSServerResponse(conn_id, response) abort
|
||||
call ale#code_action#HandleCodeAction({
|
||||
\ 'description': 'Organize Imports',
|
||||
\ 'changes': l:file_code_edits,
|
||||
\})
|
||||
\}, v:false)
|
||||
endfunction
|
||||
|
||||
function! s:OnReady(linter, lsp_details) abort
|
||||
|
@ -1,6 +1,14 @@
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: Preview windows for showing whatever information in.
|
||||
|
||||
if !has_key(s:, 'last_selection_list')
|
||||
let s:last_selection_list = []
|
||||
endif
|
||||
|
||||
if !has_key(s:, 'last_selection_open_in')
|
||||
let s:last_selection_open_in = 'current-buffer'
|
||||
endif
|
||||
|
||||
" Open a preview window and show some lines in it.
|
||||
" A second argument can be passed as a Dictionary with options. They are...
|
||||
"
|
||||
@ -67,9 +75,24 @@ function! ale#preview#ShowSelection(item_list, ...) abort
|
||||
|
||||
call ale#preview#Show(l:lines, {'filetype': 'ale-preview-selection'})
|
||||
let b:ale_preview_item_list = a:item_list
|
||||
let b:ale_preview_item_open_in = get(l:options, 'open_in', 'current-buffer')
|
||||
|
||||
" Remove the last preview
|
||||
let s:last_selection_list = b:ale_preview_item_list
|
||||
let s:last_selection_open_in = b:ale_preview_item_open_in
|
||||
endfunction
|
||||
|
||||
function! s:Open(open_in_tab) abort
|
||||
function! ale#preview#RepeatSelection() abort
|
||||
if empty(s:last_selection_list)
|
||||
return
|
||||
endif
|
||||
|
||||
call ale#preview#ShowSelection(s:last_selection_list, {
|
||||
\ 'open_in': s:last_selection_open_in,
|
||||
\})
|
||||
endfunction
|
||||
|
||||
function! s:Open(open_in) abort
|
||||
let l:item_list = get(b:, 'ale_preview_item_list', [])
|
||||
let l:item = get(l:item_list, getpos('.')[1] - 1, {})
|
||||
|
||||
@ -77,22 +100,20 @@ function! s:Open(open_in_tab) abort
|
||||
return
|
||||
endif
|
||||
|
||||
if !a:open_in_tab
|
||||
:q!
|
||||
endif
|
||||
:q!
|
||||
|
||||
call ale#util#Open(
|
||||
\ l:item.filename,
|
||||
\ l:item.line,
|
||||
\ l:item.column,
|
||||
\ {'open_in_tab': a:open_in_tab},
|
||||
\ {'open_in': a:open_in},
|
||||
\)
|
||||
endfunction
|
||||
|
||||
function! ale#preview#OpenSelectionInBuffer() abort
|
||||
call s:Open(0)
|
||||
function! ale#preview#OpenSelection() abort
|
||||
call s:Open(b:ale_preview_item_open_in)
|
||||
endfunction
|
||||
|
||||
function! ale#preview#OpenSelectionInTab() abort
|
||||
call s:Open(1)
|
||||
call s:Open('tab')
|
||||
endfunction
|
||||
|
@ -1,3 +1,5 @@
|
||||
let g:ale_default_navigation = get(g:, 'ale_default_navigation', 'buffer')
|
||||
|
||||
let s:references_map = {}
|
||||
|
||||
" Used to get the references map in tests.
|
||||
@ -99,7 +101,8 @@ function! s:OnReady(line, column, options, linter, lsp_details) abort
|
||||
let l:request_id = ale#lsp#Send(l:id, l:message)
|
||||
|
||||
let s:references_map[l:request_id] = {
|
||||
\ 'use_relative_paths': has_key(a:options, 'use_relative_paths') ? a:options.use_relative_paths : 0
|
||||
\ 'use_relative_paths': has_key(a:options, 'use_relative_paths') ? a:options.use_relative_paths : 0,
|
||||
\ 'open_in': get(a:options, 'open_in', 'current-buffer'),
|
||||
\}
|
||||
endfunction
|
||||
|
||||
@ -110,10 +113,24 @@ function! ale#references#Find(...) abort
|
||||
for l:option in a:000
|
||||
if l:option is? '-relative'
|
||||
let l:options.use_relative_paths = 1
|
||||
elseif l:option is? '-tab'
|
||||
let l:options.open_in = 'tab'
|
||||
elseif l:option is? '-split'
|
||||
let l:options.open_in = 'split'
|
||||
elseif l:option is? '-vsplit'
|
||||
let l:options.open_in = 'vsplit'
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
if !has_key(l:options, 'open_in')
|
||||
let l:default_navigation = ale#Var(bufnr(''), 'default_navigation')
|
||||
|
||||
if index(['tab', 'split', 'vsplit'], l:default_navigation) >= 0
|
||||
let l:options.open_in = l:default_navigation
|
||||
endif
|
||||
endif
|
||||
|
||||
let l:buffer = bufnr('')
|
||||
let [l:line, l:column] = getpos('.')[1:2]
|
||||
let l:column = min([l:column, len(getline(l:line))])
|
||||
|
@ -80,7 +80,7 @@ function! ale#rename#HandleTSServerResponse(conn_id, response) abort
|
||||
call ale#code_action#HandleCodeAction({
|
||||
\ 'description': 'rename',
|
||||
\ 'changes': l:changes,
|
||||
\})
|
||||
\}, v:true)
|
||||
endfunction
|
||||
|
||||
function! ale#rename#HandleLSPResponse(conn_id, response) abort
|
||||
@ -134,7 +134,7 @@ function! ale#rename#HandleLSPResponse(conn_id, response) abort
|
||||
call ale#code_action#HandleCodeAction({
|
||||
\ 'description': 'rename',
|
||||
\ 'changes': l:changes,
|
||||
\})
|
||||
\}, v:true)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -23,7 +23,7 @@ let g:ale_sign_offset = get(g:, 'ale_sign_offset', 1000000)
|
||||
let g:ale_sign_column_always = get(g:, 'ale_sign_column_always', 0)
|
||||
let g:ale_sign_highlight_linenrs = get(g:, 'ale_sign_highlight_linenrs', 0)
|
||||
|
||||
let s:supports_sign_groups = has('nvim-0.4.2') || (v:version >= 801 && has('patch614'))
|
||||
let s:supports_sign_groups = has('nvim-0.4.2') || has('patch-8.1.614')
|
||||
|
||||
if !hlexists('ALEErrorSign')
|
||||
highlight link ALEErrorSign error
|
||||
|
@ -91,17 +91,17 @@ endfunction
|
||||
" options['open_in'] can be:
|
||||
" current-buffer (default)
|
||||
" tab
|
||||
" vertical-split
|
||||
" horizontal-split
|
||||
" split
|
||||
" vsplit
|
||||
function! ale#util#Open(filename, line, column, options) abort
|
||||
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'
|
||||
elseif l:open_in is# 'split'
|
||||
call ale#util#Execute('split ' . l:args_to_open)
|
||||
elseif l:open_in is# 'vertical-split'
|
||||
elseif l:open_in is# 'vsplit'
|
||||
call ale#util#Execute('vsplit ' . l:args_to_open)
|
||||
elseif bufnr(a:filename) isnot bufnr('')
|
||||
" Open another file only if we need to.
|
||||
@ -336,15 +336,11 @@ function! ale#util#GetMatches(lines, patterns) abort
|
||||
endfunction
|
||||
|
||||
function! s:LoadArgCount(function) abort
|
||||
let l:Function = a:function
|
||||
|
||||
redir => l:output
|
||||
silent! function Function
|
||||
redir END
|
||||
|
||||
if !exists('l:output')
|
||||
try
|
||||
let l:output = execute('function a:function')
|
||||
catch /E123/
|
||||
return 0
|
||||
endif
|
||||
endtry
|
||||
|
||||
let l:match = matchstr(split(l:output, "\n")[0], '\v\([^)]+\)')[1:-2]
|
||||
let l:arg_list = filter(split(l:match, ', '), 'v:val isnot# ''...''')
|
||||
@ -480,3 +476,44 @@ endfunction
|
||||
function! ale#util#Input(message, value) abort
|
||||
return input(a:message, a:value)
|
||||
endfunction
|
||||
|
||||
function! ale#util#HasBuflineApi() abort
|
||||
return exists('*deletebufline') && exists('*setbufline')
|
||||
endfunction
|
||||
|
||||
" Sets buffer contents to lines
|
||||
function! ale#util#SetBufferContents(buffer, lines) abort
|
||||
let l:has_bufline_api = ale#util#HasBuflineApi()
|
||||
|
||||
if !l:has_bufline_api && a:buffer isnot bufnr('')
|
||||
return
|
||||
endif
|
||||
|
||||
" If the file is in DOS mode, we have to remove carriage returns from
|
||||
" the ends of lines before calling setline(), or we will see them
|
||||
" twice.
|
||||
let l:new_lines = getbufvar(a:buffer, '&fileformat') is# 'dos'
|
||||
\ ? map(copy(a:lines), 'substitute(v:val, ''\r\+$'', '''', '''')')
|
||||
\ : a:lines
|
||||
let l:first_line_to_remove = len(l:new_lines) + 1
|
||||
|
||||
" Use a Vim API for setting lines in other buffers, if available.
|
||||
if l:has_bufline_api
|
||||
call setbufline(a:buffer, 1, l:new_lines)
|
||||
call deletebufline(a:buffer, l:first_line_to_remove, '$')
|
||||
" Fall back on setting lines the old way, for the current buffer.
|
||||
else
|
||||
let l:old_line_length = line('$')
|
||||
|
||||
if l:old_line_length >= l:first_line_to_remove
|
||||
let l:save = winsaveview()
|
||||
silent execute
|
||||
\ l:first_line_to_remove . ',' . l:old_line_length . 'd_'
|
||||
call winrestview(l:save)
|
||||
endif
|
||||
|
||||
call setline(1, l:new_lines)
|
||||
endif
|
||||
|
||||
return l:new_lines
|
||||
endfunction
|
||||
|
Reference in New Issue
Block a user