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

Updated plugins

This commit is contained in:
Amir Salihefendic
2018-08-25 18:13:42 +02:00
parent 587a185a98
commit 6bd9eda8c3
169 changed files with 2625 additions and 2334 deletions

View File

@ -81,15 +81,15 @@ function! go#complete#GetInfo() abort
return s:sync_info(0)
endfunction
function! go#complete#Info(auto) abort
function! go#complete#Info() abort
if go#util#has_job(1)
return s:async_info(a:auto)
return s:async_info(1)
else
return s:sync_info(a:auto)
return s:sync_info(1)
endif
endfunction
function! s:async_info(auto)
function! s:async_info(echo)
if exists("s:async_info_job")
call job_stop(s:async_info_job)
unlet s:async_info_job
@ -100,7 +100,7 @@ function! s:async_info(auto)
\ 'exit_status': 0,
\ 'closed': 0,
\ 'messages': [],
\ 'auto': a:auto
\ 'echo': a:echo
\ }
function! s:callback(chan, msg) dict
@ -132,8 +132,8 @@ function! s:async_info(auto)
return
endif
let result = s:info_filter(self.auto, join(self.messages, "\n"))
call s:info_complete(self.auto, result)
let result = s:info_filter(self.echo, join(self.messages, "\n"))
call s:info_complete(self.echo, result)
endfunction
" add 1 to the offset, so that the position at the cursor will be included
@ -171,9 +171,7 @@ function! s:gocodeFile()
return file
endfunction
function! s:sync_info(auto)
" auto is true if we were called by g:go_auto_type_info's autocmd
function! s:sync_info(echo)
" add 1 to the offset, so that the position at the cursor will be included
" in gocode's search
let offset = go#util#OffsetCursor()+1
@ -182,11 +180,11 @@ function! s:sync_info(auto)
\ [expand('%:p'), offset],
\ go#util#GetLines())
let result = s:info_filter(a:auto, result)
call s:info_complete(a:auto, result)
let result = s:info_filter(a:echo, result)
return s:info_complete(a:echo, result)
endfunction
function! s:info_filter(auto, result) abort
function! s:info_filter(echo, result) abort
if empty(a:result)
return ""
endif
@ -200,7 +198,7 @@ function! s:info_filter(auto, result) abort
if len(l:candidates) == 1
" When gocode panics in vim mode, it returns
" [0, [{'word': 'PANIC', 'abbr': 'PANIC PANIC PANIC', 'info': 'PANIC PANIC PANIC'}]]
if a:auto && l:candidates[0].info ==# "PANIC PANIC PANIC"
if a:echo && l:candidates[0].info ==# "PANIC PANIC PANIC"
return ""
endif
@ -220,10 +218,12 @@ function! s:info_filter(auto, result) abort
return l:filtered[0].info
endfunction
function! s:info_complete(auto, result) abort
if !empty(a:result)
function! s:info_complete(echo, result) abort
if a:echo && !empty(a:result)
echo "vim-go: " | echohl Function | echon a:result | echohl None
endif
return a:result
endfunction
function! s:trim_bracket(val) abort

View File

@ -42,10 +42,11 @@ function! go#def#Jump(mode) abort
call extend(cmd, ["definition", fname . ':#' . go#util#OffsetCursor()])
if go#util#has_job()
if go#util#has_job() || has('nvim')
let l:spawn_args = {
\ 'cmd': cmd,
\ 'complete': function('s:jump_to_declaration_cb', [a:mode, bin_name]),
\ 'for': '_',
\ }
if &modified

View File

@ -34,4 +34,33 @@ func! Test_jump_to_declaration_godef() abort
endtry
endfunc
func! Test_Jump_leaves_lists() abort
try
let filename = 'def/jump.go'
let l:tmp = gotest#load_fixture(l:filename)
let expected = [{'lnum': 10, 'bufnr': bufnr('%'), 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'quux'}]
call setloclist(winnr(), copy(expected), 'r' )
call setqflist(copy(expected), 'r' )
let l:bufnr = bufnr('%')
call cursor(6, 3)
call go#def#Jump('')
let start = reltime()
while bufnr('%') == l:bufnr && reltimefloat(reltime(start)) < 10
sleep 100m
endwhile
let actual = getloclist(winnr())
call gotest#assert_quickfix(actual, expected)
let actual = getqflist()
call gotest#assert_quickfix(actual, expected)
finally
call delete(l:tmp, 'rf')
endtry
endfunc
" vim: sw=2 ts=2 et

View File

@ -14,8 +14,6 @@ endfunction
" logic.
"
" args is a dictionary with the these keys:
" 'cmd':
" The value to pass to job_start().
" 'bang':
" Set to 0 to jump to the first error in the error list.
" Defaults to 0.
@ -24,6 +22,7 @@ endfunction
" See statusline.vim.
" 'for':
" The g:go_list_type_command key to use to get the error list type to use.
" Errors will not be handled when the value is '_'.
" Defaults to '_job'
" 'errorformat':
" The errorformat string to use when parsing errors. Defaults to
@ -32,9 +31,9 @@ endfunction
" 'complete':
" A function to call after the job exits and the channel is closed. The
" function will be passed three arguments: the job, its exit code, and the
" list of messages received from the channel. The default value will
" process the messages and manage the error list after the job exits and
" the channel is closed.
" list of messages received from the channel. The default is a no-op. A
" custom value can modify the messages before they are processed by the
" returned exit_cb and close_cb callbacks.
" The return value is a dictionary with these keys:
" 'callback':
@ -47,7 +46,9 @@ endfunction
" A function suitable to be passed as a job close_cb handler. See
" job-close_cb.
" 'cwd':
" The path to the directory which contains the current buffer.
" The path to the directory which contains the current buffer. The
" callbacks are configured to expect this directory is the working
" directory for the job; it should not be modified by callers.
function! go#job#Options(args)
let cbs = {}
let state = {
@ -184,7 +185,15 @@ function! go#job#Options(args)
let cbs.close_cb = function('s:close_cb', [], state)
function state.show_errors(job, exit_status, data)
if self.for == '_'
return
endif
let l:winid = win_getid(winnr())
" Always set the active window to the window that was active when the job
" was started. Among other things, this makes sure that the correct
" window's location list will be populated when the list type is
" 'location' and the user has moved windows since starting the job.
call win_gotoid(self.winid)
let l:listtype = go#list#Type(self.for)
@ -221,6 +230,8 @@ function! go#job#Options(args)
return
endif
" only open the error window if user was still in the window from which
" the job was started.
if self.winid == l:winid
call go#list#Window(l:listtype, len(errors))
if !self.bang
@ -229,17 +240,20 @@ function! go#job#Options(args)
endif
endfunction
if has('nvim')
return s:neooptions(cbs)
endif
return cbs
endfunction
" go#job#Start runs a job. The options are expected to be the options
" suitable for Vim8 jobs. When called from Neovim, Vim8 options will be
" transformed to their Neovim equivalents.
function! go#job#Start(cmd, options)
let l:cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
let l:options = copy(a:options)
if has('nvim')
let l:options = s:neooptions(l:options)
endif
if !has_key(l:options, 'cwd')
" pre start
let dir = getcwd()
@ -249,10 +263,11 @@ function! go#job#Start(cmd, options)
if has_key(l:options, '_start')
call l:options._start()
" remove _start to play nicely with vim (when vim encounters an unexpected
" job option it reports an "E475: invalid argument" error.
" job option it reports an "E475: invalid argument" error).
unlet l:options._start
endif
if has('nvim')
let l:input = []
if has_key(l:options, 'in_io') && l:options.in_io ==# 'file' && !empty(l:options.in_name)
@ -286,6 +301,11 @@ function! s:neooptions(options)
let l:options['stderr_buf'] = ''
for key in keys(a:options)
if key == 'cwd'
let l:options['cwd'] = a:options['cwd']
continue
endif
if key == 'callback'
let l:options['callback'] = a:options['callback']
@ -402,5 +422,4 @@ function! s:neooptions(options)
return l:options
endfunction
" vim: sw=2 ts=2 et

View File

@ -41,7 +41,11 @@ function! go#lint#Gometa(autosave, ...) abort
redraw
" Include only messages for the active buffer for autosave.
let cmd += [printf('--include=^%s:.*$', fnamemodify(expand('%:p'), ":."))]
let include = [printf('--include=^%s:.*$', fnamemodify(expand('%:p'), ":."))]
if go#util#has_job() || has('nvim')
let include = [printf('--include=^%s:.*$', expand('%:p:t'))]
endif
let cmd += include
endif
" Call gometalinter asynchronously.
@ -52,7 +56,7 @@ function! go#lint#Gometa(autosave, ...) abort
let cmd += goargs
if go#util#has_job() && has('lambda')
if go#util#has_job() || has('nvim')
call s:lint_job({'cmd': cmd}, a:autosave)
return
endif
@ -193,113 +197,46 @@ function! go#lint#ToggleMetaLinterAutoSave() abort
endfunction
function! s:lint_job(args, autosave)
let state = {
\ 'status_dir': expand('%:p:h'),
\ 'started_at': reltime(),
\ 'messages': [],
\ 'exited': 0,
\ 'closed': 0,
\ 'exit_status': 0,
\ 'winid': win_getid(winnr()),
\ 'autosave': a:autosave
\ }
call go#statusline#Update(state.status_dir, {
\ 'desc': "current status",
\ 'type': "gometalinter",
\ 'state': "analysing",
\})
" autowrite is not enabled for jobs
call go#cmd#autowrite()
let l:opts = {
\ 'statustype': "gometalinter",
\ 'errorformat': '%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m',
\ 'for': "GoMetaLinter",
\ }
if a:autosave
let state.listtype = go#list#Type("GoMetaLinterAutoSave")
else
let state.listtype = go#list#Type("GoMetaLinter")
let l:opts.for = "GoMetaLinterAutoSave"
endif
function! s:callback(chan, msg) dict closure
call add(self.messages, a:msg)
endfunction
function! s:exit_cb(job, exitval) dict
let self.exited = 1
let self.exit_status = a:exitval
let status = {
\ 'desc': 'last status',
\ 'type': "gometaliner",
\ 'state': "finished",
\ }
if a:exitval
let status.state = "failed"
endif
let elapsed_time = reltimestr(reltime(self.started_at))
" strip whitespace
let elapsed_time = substitute(elapsed_time, '^\s*\(.\{-}\)\s*$', '\1', '')
let status.state .= printf(" (%ss)", elapsed_time)
call go#statusline#Update(self.status_dir, status)
if self.closed
call self.show_errors()
endif
endfunction
function! s:close_cb(ch) dict
let self.closed = 1
if self.exited
call self.show_errors()
endif
endfunction
function state.show_errors()
let l:winid = win_getid(winnr())
" make sure the current window is the window from which gometalinter was
" run when the listtype is locationlist so that the location list for the
" correct window will be populated.
if self.listtype == 'locationlist'
call win_gotoid(self.winid)
endif
let l:errorformat = '%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m'
call go#list#ParseFormat(self.listtype, l:errorformat, self.messages, 'GoMetaLinter')
let errors = go#list#Get(self.listtype)
call go#list#Window(self.listtype, len(errors))
let l:cbs = go#job#Options(l:opts)
if a:autosave
" move to the window that was active before processing the errors, because
" the user may have moved around within the window or even moved to a
" different window since saving. Moving back to current window as of the
" start of this function avoids the perception that the quickfix window
" steals focus when linting takes a while.
if self.autosave
call win_gotoid(self.winid)
endif
if go#config#EchoCommandInfo()
call go#util#EchoSuccess("linting finished")
endif
endfunction
function! s:exit_cb(next, job, exitval)
let l:winid = win_getid(winnr())
call call(a:next, [a:job, a:exitval])
call win_gotoid(l:winid)
endfunction
" wrap l:cbs.exit_cb in s:exit_cb.
let l:cbs.exit_cb = funcref('s:exit_cb', [l:cbs.exit_cb])
" explicitly bind the callbacks to state so that self within them always
" refers to state. See :help Partial for more information.
let start_options = {
\ 'callback': funcref("s:callback", [], state),
\ 'exit_cb': funcref("s:exit_cb", [], state),
\ 'close_cb': funcref("s:close_cb", [], state),
\ }
call job_start(a:args.cmd, start_options)
if go#config#EchoCommandInfo()
call go#util#EchoProgress("linting started ...")
function! s:close_cb(next, ch)
let l:winid = win_getid(winnr())
call call(a:next, [a:ch])
call win_gotoid(l:winid)
endfunction
" wrap l:cbs.close_cb in s:close_cb.
let l:cbs.close_cb = funcref('s:close_cb', [l:cbs.close_cb])
endif
" autowrite is not enabled for jobs
call go#cmd#autowrite()
call go#job#Start(a:args.cmd, l:cbs)
endfunction
" vim: sw=2 ts=2 et

View File

@ -9,13 +9,6 @@ func! Test_Gometa() abort
" clear the quickfix lists
call setqflist([], 'r')
" call go#lint#ToggleMetaLinterAutoSave from lint.vim so that the file will
" be autoloaded and the default for g:go_metalinter_enabled will be set so
" we can capture it to restore it after the test is run.
silent call go#lint#ToggleMetaLinterAutoSave()
" And restore it back to its previous value
silent call go#lint#ToggleMetaLinterAutoSave()
let g:go_metalinter_enabled = ['golint']
call go#lint#Gometa(0, $GOPATH . '/src/foo')
@ -42,13 +35,6 @@ func! Test_GometaWithDisabled() abort
" clear the quickfix lists
call setqflist([], 'r')
" call go#lint#ToggleMetaLinterAutoSave from lint.vim so that the file will
" be autoloaded and the default for g:go_metalinter_disabled will be set so
" we can capture it to restore it after the test is run.
silent call go#lint#ToggleMetaLinterAutoSave()
" And restore it back to its previous value
silent call go#lint#ToggleMetaLinterAutoSave()
let g:go_metalinter_disabled = ['vet']
call go#lint#Gometa(0, $GOPATH . '/src/foo')
@ -77,13 +63,6 @@ func! Test_GometaAutoSave() abort
" clear the location lists
call setloclist(l:winnr, [], 'r')
" call go#lint#ToggleMetaLinterAutoSave from lint.vim so that the file will
" be autoloaded and the default for g:go_metalinter_autosave_enabled will be
" set so we can capture it to restore it after the test is run.
silent call go#lint#ToggleMetaLinterAutoSave()
" And restore it back to its previous value
silent call go#lint#ToggleMetaLinterAutoSave()
let g:go_metalinter_autosave_enabled = ['golint']
call go#lint#Gometa(1)

View File

@ -27,7 +27,7 @@ function! go#rename#Rename(bang, ...) abort
let offset = printf('%s:#%d', fname, pos)
let cmd = [bin_path, "-offset", offset, "-to", to_identifier, '-tags', go#config#BuildTags()]
if go#util#has_job()
if go#util#has_job() || has('nvim')
call go#util#EchoProgress(printf("renaming to '%s' ...", to_identifier))
call s:rename_job({
\ 'cmd': cmd,
@ -41,63 +41,37 @@ function! go#rename#Rename(bang, ...) abort
endfunction
function s:rename_job(args)
let state = {
\ 'exited': 0,
\ 'closed': 0,
\ 'exitval': 0,
\ 'messages': [],
\ 'status_dir': expand('%:p:h'),
\ 'bang': a:args.bang
\ }
function! s:callback(chan, msg) dict
call add(self.messages, a:msg)
endfunction
function! s:exit_cb(job, exitval) dict
let self.exited = 1
let self.exitval = a:exitval
let status = {
\ 'desc': 'last status',
\ 'type': "gorename",
\ 'state': "finished",
\ }
if a:exitval
let status.state = "failed"
endif
call go#statusline#Update(self.status_dir, status)
if self.closed
call s:parse_errors(self.exitval, self.bang, self.messages)
endif
endfunction
function! s:close_cb(ch) dict
let self.closed = 1
if self.exited
call s:parse_errors(self.exitval, self.bang, self.messages)
endif
endfunction
" explicitly bind the callbacks to state so that self within them always
" refers to state. See :help Partial for more information.
let start_options = {
\ 'callback': funcref("s:callback", [], state),
\ 'exit_cb': funcref("s:exit_cb", [], state),
\ 'close_cb': funcref("s:close_cb", [], state),
let l:job_opts = {
\ 'bang': a:args.bang,
\ 'for': 'GoRename',
\ 'statustype': 'gorename',
\ }
call go#statusline#Update(state.status_dir, {
\ 'desc': "current status",
\ 'type': "gorename",
\ 'state': "started",
\})
" autowrite is not enabled for jobs
call go#cmd#autowrite()
let l:cbs = go#job#Options(l:job_opts)
call job_start(a:args.cmd, start_options)
" wrap l:cbs.exit_cb in s:exit_cb.
let l:cbs.exit_cb = funcref('s:exit_cb', [l:cbs.exit_cb])
call go#job#Start(a:args.cmd, l:cbs)
endfunction
function! s:reload_changed() abort
" reload all files to reflect the new changes. We explicitly call
" checktime to trigger a reload of all files. See
" http://www.mail-archive.com/vim@vim.org/msg05900.html for more info
" about the autoread bug
let current_autoread = &autoread
set autoread
silent! checktime
let &autoread = current_autoread
endfunction
" s:exit_cb reloads any changed buffers and then calls next.
function! s:exit_cb(next, job, exitval) abort
call s:reload_changed()
call call(a:next, [a:job, a:exitval])
endfunction
function s:parse_errors(exit_val, bang, out)
@ -132,9 +106,6 @@ function s:parse_errors(exit_val, bang, out)
call go#util#EchoSuccess(a:out[0])
" refresh the buffer so we can see the new content
" TODO(arslan): also find all other buffers and refresh them too. For this
" we need a way to get the list of changes from gorename upon an success
" change.
silent execute ":e"
endfunction

View File

@ -34,6 +34,10 @@ function! go#test#Test(bang, compile, ...) abort
endif
endif
if has('nvim') && go#config#TermEnabled()
call go#term#new(a:bang, ["go"] + args)
endif
if go#util#has_job() || has('nvim')
" use vim's job functionality to call it asynchronously
let job_options = {

View File

@ -76,10 +76,10 @@ function! go#tool#Imports() abort
return imports
endfunction
function! go#tool#Info(auto) abort
function! go#tool#Info() abort
let l:mode = go#config#InfoMode()
if l:mode == 'gocode'
call go#complete#Info(a:auto)
call go#complete#Info()
elseif l:mode == 'guru'
call go#guru#DescribeInfo()
else

View File

@ -61,7 +61,7 @@ endfunction
" Check if Vim jobs API is supported.
"
" The (optional) first paramter can be added to indicate the 'cwd' or 'env'
" The (optional) first parameter can be added to indicate the 'cwd' or 'env'
" parameters will be used, which wasn't added until a later version.
function! go#util#has_job(...) abort
" cwd and env parameters to job_start was added in this version.