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

Replace YanRing with yank-stack and update plugins

This commit is contained in:
amix
2017-12-13 15:05:24 +01:00
parent 2ca843a22a
commit 53894de44b
72 changed files with 1663 additions and 5015 deletions

View File

@ -41,8 +41,6 @@ function! go#cmd#Build(bang, ...) abort
" Vim 7.4 without async
else
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
let default_makeprg = &makeprg
let &makeprg = "go " . join(go#util#Shelllist(args), ' ')
@ -72,7 +70,6 @@ function! go#cmd#Build(bang, ...) abort
endif
let &makeprg = default_makeprg
let $GOPATH = old_gopath
endif
endfunction
@ -125,9 +122,6 @@ function! go#cmd#Run(bang, ...) abort
" anything. Once this is implemented we're going to make :GoRun async
endif
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
if go#util#IsWin()
exec '!go run ' . go#util#Shelljoin(go#tool#Files())
if v:shell_error
@ -136,7 +130,6 @@ function! go#cmd#Run(bang, ...) abort
redraws! | echon "vim-go: [run] " | echohl Function | echon "SUCCESS"| echohl None
endif
let $GOPATH = old_gopath
return
endif
@ -165,7 +158,6 @@ function! go#cmd#Run(bang, ...) abort
call go#list#JumpToFirst(l:listtype)
endif
let $GOPATH = old_gopath
let &makeprg = default_makeprg
endfunction
@ -190,8 +182,6 @@ function! go#cmd#Install(bang, ...) abort
return
endif
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
let default_makeprg = &makeprg
" :make expands '%' and '#' wildcards, so they must also be escaped
@ -220,10 +210,9 @@ function! go#cmd#Install(bang, ...) abort
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:listtype)
else
call go#util#EchoSuccess("installed to ". go#path#Detect())
call go#util#EchoSuccess("installed to ". go#path#Default())
endif
let $GOPATH = old_gopath
let &makeprg = default_makeprg
endfunction
@ -231,9 +220,6 @@ endfunction
function! go#cmd#Generate(bang, ...) abort
let default_makeprg = &makeprg
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
" :make expands '%' and '#' wildcards, so they must also be escaped
let goargs = go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
if go#util#ShellError() != 0
@ -264,7 +250,6 @@ function! go#cmd#Generate(bang, ...) abort
endif
let &makeprg = default_makeprg
let $GOPATH = old_gopath
endfunction
" ---------------------
@ -311,10 +296,6 @@ function s:cmd_job(args) abort
\ 'exit_cb': callbacks.exit_cb,
\ }
" modify GOPATH if needed
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
" pre start
let dir = getcwd()
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
@ -325,7 +306,6 @@ function s:cmd_job(args) abort
" post start
execute cd . fnameescape(dir)
let $GOPATH = old_gopath
endfunction
" vim: sw=2 ts=2 et

View File

@ -19,25 +19,25 @@ function! s:gocodeCommand(cmd, preargs, args) abort
return
endif
" we might hit cache problems, as gocode doesn't handle well different
" GOPATHS: https://github.com/nsf/gocode/issues/239
let old_gopath = $GOPATH
" We might hit cache problems, as gocode doesn't handle different GOPATHs
" well. See: https://github.com/nsf/gocode/issues/239
let old_goroot = $GOROOT
let $GOPATH = go#path#Detect()
let $GOROOT = go#util#env("goroot")
let socket_type = get(g:, 'go_gocode_socket_type', s:sock_type)
let cmd = printf('%s -sock %s %s %s %s',
\ go#util#Shellescape(bin_path),
\ socket_type,
\ join(a:preargs),
\ go#util#Shellescape(a:cmd),
\ join(a:args)
\ )
try
let socket_type = get(g:, 'go_gocode_socket_type', s:sock_type)
let cmd = printf('%s -sock %s %s %s %s',
\ go#util#Shellescape(bin_path),
\ socket_type,
\ join(a:preargs),
\ go#util#Shellescape(a:cmd),
\ join(a:args)
\ )
let result = go#util#System(cmd)
let $GOPATH = old_gopath
let $GOROOT = old_goroot
let result = go#util#System(cmd)
finally
let $GOROOT = old_goroot
endtry
if go#util#ShellError() != 0
return "[\"0\", []]"

View File

@ -300,10 +300,6 @@ function s:coverage_job(args)
\ 'exit_cb': callbacks.exit_cb,
\ }
" modify GOPATH if needed
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
" pre start
let dir = getcwd()
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
@ -320,7 +316,6 @@ function s:coverage_job(args)
" post start
execute cd . fnameescape(dir)
let $GOPATH = old_gopath
endfunction
" coverage_callback is called when the coverage execution is finished

View File

@ -2,9 +2,6 @@ let s:go_stack = []
let s:go_stack_level = 0
function! go#def#Jump(mode) abort
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
" so guru right now is slow for some people. previously we were using
@ -22,7 +19,6 @@ function! go#def#Jump(mode) abort
let bin_path = go#path#CheckBinPath("godef")
if empty(bin_path)
let $GOPATH = old_gopath
return
endif
let command = printf("%s -f=%s -o=%s -t", go#util#Shellescape(bin_path),
@ -34,7 +30,6 @@ function! go#def#Jump(mode) abort
elseif bin_name == 'guru'
let bin_path = go#path#CheckBinPath("guru")
if empty(bin_path)
let $GOPATH = old_gopath
return
endif
@ -88,7 +83,6 @@ function! go#def#Jump(mode) abort
endif
call go#def#jump_to_declaration(out, a:mode, bin_name)
let $GOPATH = old_gopath
endfunction
function! s:jump_to_declaration_cb(mode, bin_name, job, exit_status, data) abort

View File

@ -29,7 +29,19 @@ function! go#doc#OpenBrowser(...) abort
let name = out["name"]
let decl = out["decl"]
let godoc_url = "https://godoc.org/" . import
let godoc_url = get(g:, 'go_doc_url', 'https://godoc.org')
if godoc_url isnot 'https://godoc.org'
" strip last '/' character if available
let last_char = strlen(godoc_url) - 1
if godoc_url[last_char] == '/'
let godoc_url = strpart(godoc_url, 0, last_char)
endif
" custom godoc installations expects it
let godoc_url .= "/pkg"
endif
let godoc_url .= "/" . import
if decl !~ "^package"
let godoc_url .= "#" . name
endif

View File

@ -58,7 +58,7 @@ function! go#fmt#Format(withGoimport) abort
endif
" Write current unsaved buffer to a temp file
let l:tmpname = tempname()
let l:tmpname = tempname() . '.go'
call writefile(go#util#GetLines(), l:tmpname)
if go#util#IsWin()
let l:tmpname = tr(l:tmpname, '\', '/')
@ -101,6 +101,9 @@ function! go#fmt#Format(withGoimport) abort
" be smart and jump to the line the new statement was added/removed
call cursor(line('.') + diff_offset, current_col)
" Syntax highlighting breaks less often.
syntax sync fromstart
endfunction
" update_file updates the target file with the given formatted source
@ -158,21 +161,11 @@ function! go#fmt#run(bin_name, source, target)
return
endif
if cmd[0] == "goimports"
" change GOPATH too, so goimports can pick up the correct library
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
endif
let command = join(cmd, " ")
" execute our command...
let out = go#util#System(command)
if cmd[0] == "goimports"
let $GOPATH = old_gopath
endif
return out
endfunction

View File

@ -212,16 +212,12 @@ endfunc
" run_guru runs the given guru argument
function! s:run_guru(args) abort
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
if go#util#has_job()
let res = s:async_guru(a:args)
else
let res = s:sync_guru(a:args)
endif
let $GOPATH = old_gopath
return res
endfunction
@ -366,7 +362,7 @@ function! go#guru#DescribeInfo() abort
\ 'mode': 'describe',
\ 'format': 'json',
\ 'selected': -1,
\ 'needs_scope': 1,
\ 'needs_scope': 0,
\ 'custom_parse': function('s:info'),
\ 'disable_progress': 1,
\ }

View File

@ -1,16 +1,11 @@
function! go#impl#Impl(...) abort
let binpath = go#path#CheckBinPath('impl')
if empty(binpath)
return
endif
let recv = ""
let iface = ""
let interactive = 0
let pos = getpos('.')
if a:0 == 0
if a:0 is 0
" Interactive mode if user didn't pass any arguments.
let recv = s:getReceiver()
let iface = input("vim-go: generating method stubs for interface: ")
@ -19,7 +14,7 @@ function! go#impl#Impl(...) abort
call go#util#EchoError('usage: interface type is not provided')
return
endif
elseif a:0 == 1
elseif a:0 is 1
" we assume the user only passed the interface type,
" i.e: ':GoImpl io.Writer'
let recv = s:getReceiver()
@ -41,19 +36,19 @@ function! go#impl#Impl(...) abort
try
let dirname = fnameescape(expand('%:p:h'))
let result = go#util#System(join(go#util#Shelllist([binpath, '-dir', dirname, recv, iface], ' ')))
let [result, err] = go#util#Exec(['impl', '-dir', dirname, recv, iface])
let result = substitute(result, "\n*$", "", "")
if go#util#ShellError() != 0
if err
call go#util#EchoError(result)
return
endif
if result ==# ''
if result is# ''
return
end
put =''
put =result
silent put =result
finally
call setpos('.', pos)
endtry
@ -99,10 +94,6 @@ function! s:root_dirs() abort
endif
let paths = map(split(go#util#env("gopath"), go#util#PathListSep()), "substitute(v:val, '\\\\', '/', 'g')")
if go#util#ShellError()
return []
endif
if !empty(filter(paths, 'isdirectory(v:val)'))
call extend(dirs, paths)
endif
@ -120,11 +111,12 @@ function! s:go_packages(dirs) abort
endfunction
function! s:interface_list(pkg) abort
let contents = split(go#util#System('go doc ' . a:pkg), "\n")
if go#util#ShellError()
let [contents, err] = go#util#Exec(['go', 'doc', a:pkg])
if err
return []
endif
let contents = split(contents, "\n")
call filter(contents, 'v:val =~# ''^type\s\+\h\w*\s\+interface''')
return map(contents, 'a:pkg . "." . matchstr(v:val, ''^type\s\+\zs\h\w*\ze\s\+interface'')')
endfunction

View File

@ -0,0 +1,37 @@
func! Test_impl() abort
try
let l:tmp = gotest#write_file('a/a.go', [
\ 'package a',
\ '',
\ ''])
call go#impl#Impl('r', 'reader', 'io.Reader')
call gotest#assert_buffer(1, [
\ 'func (r reader) Read(p []byte) (n int, err error) {',
\ ' panic("not implemented")',
\ '}'])
finally
call delete(l:tmp, 'rf')
endtry
endfunc
func! Test_impl_get() abort
try
let l:tmp = gotest#write_file('a/a.go', [
\ 'package a',
\ '',
\ 'type reader struct {}'])
call go#impl#Impl('io.Reader')
call gotest#assert_buffer(0, [
\ 'package a',
\ '',
\ 'type reader struct {}',
\ '',
\ 'func (r *reader) Read(p []byte) (n int, err error) {',
\ ' panic("not implemented")',
\ '}'])
finally
call delete(l:tmp, 'rf')
endtry
endfunc

View File

@ -33,10 +33,9 @@ function! go#jobcontrol#RemoveHandler(id) abort
unlet s:handlers[a:id]
endfunction
" spawn spawns a go subcommand with the name and arguments with jobstart. Once
" a job is started a reference will be stored inside s:jobs. spawn changes the
" GOPATH when g:go_autodetect_gopath is enabled. The job is started inside the
" current files folder.
" spawn spawns a go subcommand with the name and arguments with jobstart. Once a
" job is started a reference will be stored inside s:jobs. The job is started
" inside the current files folder.
function! s:spawn(bang, desc, for, args) abort
let status_type = a:args[0]
let status_dir = expand('%:p:h')
@ -65,10 +64,6 @@ function! s:spawn(bang, desc, for, args) abort
\ 'for' : a:for,
\ }
" modify GOPATH if needed
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
" execute go build in the files directory
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
@ -94,9 +89,6 @@ function! s:spawn(bang, desc, for, args) abort
execute cd . fnameescape(dir)
" restore back GOPATH
let $GOPATH = old_gopath
return job
endfunction

View File

@ -1,11 +1,8 @@
function! go#keyify#Keyify()
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
let bin_path = go#path#CheckBinPath("keyify")
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
if empty(bin_path) || !exists('*json_decode')
let $GOPATH = old_gopath
return
endif
@ -18,7 +15,6 @@ function! go#keyify#Keyify()
" We want to output the error message in case the result isn't a JSON
if type(result) != type({})
call go#util#EchoError(s:chomp(output))
let $GOPATH = old_gopath
return
endif
@ -51,7 +47,6 @@ function! go#keyify#Keyify()
call setpos("'<", vis_start)
call setpos("'>", vis_end)
let $GOPATH = old_gopath
endfunction
function! s:chomp(string)

View File

@ -46,7 +46,7 @@ function! go#package#Paths() abort
let dirs += [s:goroot]
endif
let workspaces = split(go#path#Detect(), go#util#PathListSep())
let workspaces = split(go#path#Default(), go#util#PathListSep())
if workspaces != []
let dirs += workspaces
endif

View File

@ -4,14 +4,14 @@
" :GoPath is used
let s:initial_go_path = ""
" GoPath sets or returns the current GOPATH. If no arguments are passed it
" GoPath sets or echos the current GOPATH. If no arguments are passed it
" echoes the current GOPATH, if an argument is passed it replaces the current
" GOPATH with it. If two double quotes are passed (the empty string in go),
" it'll clear the GOPATH and will restore to the initial GOPATH.
function! go#path#GoPath(...) abort
" no argument, show GOPATH
if len(a:000) == 0
echo go#path#Detect()
echo go#path#Default()
return
endif
@ -72,11 +72,6 @@ endfunction
function! go#path#Detect() abort
let gopath = go#path#Default()
" don't lookup for godeps if autodetect is disabled.
if !get(g:, "go_autodetect_gopath", 0)
return gopath
endif
let current_dir = fnameescape(expand('%:p:h'))
" TODO(arslan): this should be changed so folders or files should be
@ -124,7 +119,6 @@ function! go#path#Detect() abort
return gopath
endfunction
" BinPath returns the binary path of installed go tools.
function! go#path#BinPath() abort
let bin_path = ""

View File

@ -100,10 +100,6 @@ function s:rename_job(args)
\ 'exit_cb': funcref("s:exit_cb"),
\ }
" modify GOPATH if needed
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
call go#statusline#Update(status_dir, {
\ 'desc': "current status",
\ 'type': "gorename",
@ -111,8 +107,6 @@ function s:rename_job(args)
\})
call job_start(a:args.cmd, start_options)
let $GOPATH = old_gopath
endfunction
function s:parse_errors(exit_val, bang, out)

View File

@ -18,10 +18,6 @@ function! go#term#newmode(bang, cmd, mode) abort
let mode = g:go_term_mode
endif
" modify GOPATH if needed
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
" execute go build in the files directory
let l:winnr = winnr()
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
@ -54,9 +50,6 @@ function! go#term#newmode(bang, cmd, mode) abort
execute cd . fnameescape(dir)
" restore back GOPATH
let $GOPATH = old_gopath
let job.id = id
let job.cmd = a:cmd
startinsert

View File

@ -207,10 +207,6 @@ function s:test_job(args) abort
\ 'exit_cb': funcref("s:exit_cb"),
\ }
" modify GOPATH if needed
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
" pre start
let dir = getcwd()
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
@ -221,7 +217,6 @@ function s:test_job(args) abort
" post start
execute cd . fnameescape(dir)
let $GOPATH = old_gopath
endfunction
" show_errors parses the given list of lines of a 'go test' output and returns
@ -295,20 +290,27 @@ function! s:parse_errors(lines) abort
" '\t/usr/local/go/src/time.go:1313 +0x5d'
let tokens = matchlist(line, '^\t\+\(.\{-}\.go\):\(\d\+\) \(+0x.*\)')
else
" matches lines produced by `go test`. All lines produced by `go test`
" that we're interested in start with zero or more spaces (increasing
" depth of subtests is represented by a similar increase in the number
" of spaces at the start of output lines. Top level tests start with
" zero leading spaces). Lines that indicate test status (e.g. RUN, FAIL,
" PASS) start after the spaces. Lines that indicate test failure
" location or test log message location (e.g. "testing.T".Log) begin
" with the appropriate number of spaces for the current test level,
" followed by a tab, a filename , a colon, the line number, another
" colon, a space, and the failure or log message.
" Matches lines produced by `go test`. When the test binary cannot be
" compiled, the errors will be a filename, followed by a colon, followed
" by the line number, followed by another colon, a space, and then the
" compiler error.
" e.g.:
" 'quux.go:123: undefined: foo'
"
" When the test binary can be successfully compiled, but tests fail, all
" lines produced by `go test` that we're interested in start with zero
" or more spaces (increasing depth of subtests is represented by a
" similar increase in the number of spaces at the start of output lines.
" Top level tests start with zero leading spaces). Lines that indicate
" test status (e.g. RUN, FAIL, PASS) start after the spaces. Lines that
" indicate test failure location or test log message location (e.g.
" "testing.T".Log) begin with the appropriate number of spaces for the
" current test level, followed by a tab, a filename , a colon, the line
" number, another colon, a space, and the failure or log message.
"
" e.g.:
" '\ttime_test.go:30: Likely problem: the time zone files have not been installed.'
let tokens = matchlist(line, '^ *\t\+\(.\{-}\.go\):\(\d\+\):\s*\(.*\)')
let tokens = matchlist(line, '^\%( *\t\+\)\?\(.\{-}\.go\):\(\d\+\):\s*\(.*\)')
endif
if !empty(tokens) " Check whether the line may refer to a file.

View File

@ -174,11 +174,6 @@ function! go#tool#ExecuteInDir(cmd) abort
return ''
endif
let old_gopath = $GOPATH
let old_goroot = $GOROOT
let $GOPATH = go#path#Detect()
let $GOROOT = go#util#env("goroot")
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
try
@ -187,9 +182,6 @@ function! go#tool#ExecuteInDir(cmd) abort
finally
execute cd . fnameescape(dir)
endtry
let $GOROOT = old_goroot
let $GOPATH = old_gopath
return out
endfunction

View File

@ -15,7 +15,7 @@ fun! gotest#write_file(path, contents) abort
call mkdir(fnamemodify(l:full_path, ':h'), 'p')
call writefile(a:contents, l:full_path)
exe 'cd ' . l:dir . '/src'
silent exe 'e ' . a:path
silent exe 'e! ' . a:path
" Set cursor.
let l:lnum = 1