mirror of
https://github.com/amix/vimrc
synced 2025-07-06 16:05:01 +08:00
updated plugins and added eslint goodies
This commit is contained in:
30
sources_non_forked/vim-go/autoload/go/alternate.vim
Normal file
30
sources_non_forked/vim-go/autoload/go/alternate.vim
Normal file
@ -0,0 +1,30 @@
|
||||
" By default use edit (current buffer view) to switch
|
||||
if !exists("g:go_alternate_mode")
|
||||
let g:go_alternate_mode = "edit"
|
||||
endif
|
||||
|
||||
" Test alternates between the implementation of code and the test code.
|
||||
function! go#alternate#Switch(bang, cmd)
|
||||
let l:file = go#alternate#Filename(fnameescape(expand("%")))
|
||||
if !filereadable(l:file) && !bufexists(l:file) && !a:bang
|
||||
redraws! | echon "vim-go: " | echohl ErrorMsg | echon "couldn't find ".file | echohl None
|
||||
return
|
||||
elseif empty(a:cmd)
|
||||
execute ":" . g:go_alternate_mode . " " . file
|
||||
else
|
||||
execute ":" . a:cmd . " " . file
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Filename returns the name of the test file or implementation file
|
||||
" depending on the arguments
|
||||
function! go#alternate#Filename(path)
|
||||
if empty(matchstr(a:path, "_test"))
|
||||
let l:root = split(a:path, ".go$")[0]
|
||||
let l:file = l:root . "_test.go"
|
||||
else
|
||||
let l:root = split(a:path, "_test.go$")[0]
|
||||
let l:file = l:root . ".go"
|
||||
endif
|
||||
return l:file
|
||||
endfunction
|
52
sources_non_forked/vim-go/autoload/go/asmfmt.vim
Normal file
52
sources_non_forked/vim-go/autoload/go/asmfmt.vim
Normal file
@ -0,0 +1,52 @@
|
||||
" asmfmt.vim: Vim command to format Go asm files with asmfmt
|
||||
" (github.com/klauspost/asmfmt).
|
||||
"
|
||||
" This filetype plugin adds new commands for asm buffers:
|
||||
"
|
||||
" :Fmt
|
||||
"
|
||||
" Filter the current asm buffer through asmfmt.
|
||||
" It tries to preserve cursor position and avoids
|
||||
" replacing the buffer with stderr output.
|
||||
"
|
||||
" Options:
|
||||
"
|
||||
" g:go_asmfmt_autosave [default=1]
|
||||
"
|
||||
" Flag to automatically call :Fmt when file is saved.
|
||||
|
||||
let s:got_fmt_error = 0
|
||||
|
||||
" This is a trimmed-down version of the logic in fmt.vim.
|
||||
|
||||
function! go#asmfmt#Format()
|
||||
" Save state.
|
||||
let l:curw = winsaveview()
|
||||
|
||||
" Write the current buffer to a tempfile.
|
||||
let l:tmpname = tempname()
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
|
||||
" Run asmfmt.
|
||||
let path = go#path#CheckBinPath("asmfmt")
|
||||
if empty(path)
|
||||
return
|
||||
endif
|
||||
let out = system(path . ' -w ' . l:tmpname)
|
||||
|
||||
" If there's no error, replace the current file with the output.
|
||||
if v:shell_error == 0
|
||||
" Remove undo point caused by BufWritePre.
|
||||
try | silent undojoin | catch | endtry
|
||||
|
||||
" Replace the current file with the temp file; then reload the buffer.
|
||||
let old_fileformat = &fileformat
|
||||
call rename(l:tmpname, expand('%'))
|
||||
silent edit!
|
||||
let &fileformat = old_fileformat
|
||||
let &syntax = &syntax
|
||||
endif
|
||||
|
||||
" Restore the cursor/window positions.
|
||||
call winrestview(l:curw)
|
||||
endfunction
|
@ -8,57 +8,92 @@ function! go#cmd#autowrite()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Build buils the source code without producting any output binary. We live in
|
||||
|
||||
" Build builds the source code without producting any output binary. We live in
|
||||
" an editor so the best is to build it to catch errors and fix them. By
|
||||
" default it tries to call simply 'go build', but it first tries to get all
|
||||
" dependent files for the current folder and passes it to go build.
|
||||
function! go#cmd#Build(bang, ...)
|
||||
let default_makeprg = &makeprg
|
||||
let gofiles = join(go#tool#Files(), '" "')
|
||||
" expand all wildcards(i.e: '%' to the current file name)
|
||||
let goargs = map(copy(a:000), "expand(v:val)")
|
||||
|
||||
" escape all shell arguments before we pass it to make
|
||||
let goargs = go#util#Shelllist(goargs, 1)
|
||||
|
||||
" create our command arguments. go build discards any results when it
|
||||
" compiles multiple packages. So we pass the `errors` package just as an
|
||||
" placeholder with the current folder (indicated with '.')
|
||||
let args = ["build"] + goargs + [".", "errors"]
|
||||
|
||||
" if we have nvim, call it asynchronously and return early ;)
|
||||
if has('nvim')
|
||||
call go#util#EchoProgress("building dispatched ...")
|
||||
call go#jobcontrol#Spawn(a:bang, "build", args)
|
||||
return
|
||||
endif
|
||||
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
let default_makeprg = &makeprg
|
||||
let &makeprg = "go " . join(args, ' ')
|
||||
|
||||
if v:shell_error
|
||||
let &makeprg = "go build . errors"
|
||||
else
|
||||
let &makeprg = "go build -o /dev/null " . join(a:000, ' ') . ' "' . gofiles . '"'
|
||||
endif
|
||||
let l:listtype = go#list#Type("quickfix")
|
||||
" execute make inside the source folder so we can parse the errors
|
||||
" correctly
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let dir = getcwd()
|
||||
try
|
||||
execute cd . fnameescape(expand("%:p:h"))
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
call go#util#EchoProgress("building dispatched ...")
|
||||
silent! exe 'Make'
|
||||
elseif l:listtype == "locationlist"
|
||||
silent! exe 'lmake!'
|
||||
else
|
||||
silent! exe 'make!'
|
||||
endif
|
||||
redraw!
|
||||
finally
|
||||
execute cd . fnameescape(dir)
|
||||
endtry
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "building ..."| echohl None
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
silent! exe 'Make'
|
||||
else
|
||||
silent! exe 'make!'
|
||||
endif
|
||||
redraw!
|
||||
let errors = go#list#Get(l:listtype)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if !empty(errors)
|
||||
if !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endif
|
||||
else
|
||||
redraws! | echon "vim-go: " | echohl Function | echon "[build] SUCCESS"| echohl None
|
||||
call go#util#EchoSuccess("[build] SUCCESS")
|
||||
endif
|
||||
|
||||
let &makeprg = default_makeprg
|
||||
let $GOPATH = old_gopath
|
||||
endfunction
|
||||
|
||||
|
||||
" Run runs the current file (and their dependencies if any) in a new terminal.
|
||||
function! go#cmd#RunTerm(bang, mode)
|
||||
let cmd = "go run ". go#util#Shelljoin(go#tool#Files())
|
||||
call go#term#newmode(a:bang, cmd, a:mode)
|
||||
endfunction
|
||||
|
||||
" Run runs the current file (and their dependencies if any) and outputs it.
|
||||
" This is intented to test small programs and play with them. It's not
|
||||
" suitable for long running apps, because vim is blocking by default and
|
||||
" calling long running apps will block the whole UI.
|
||||
function! go#cmd#Run(bang, ...)
|
||||
let goFiles = '"' . join(go#tool#Files(), '" "') . '"'
|
||||
if has('nvim')
|
||||
call go#cmd#RunTerm(a:bang, '')
|
||||
return
|
||||
endif
|
||||
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
if go#util#IsWin()
|
||||
exec '!go run ' . goFiles
|
||||
exec '!go run ' . go#util#Shelljoin(go#tool#Files())
|
||||
if v:shell_error
|
||||
redraws! | echon "vim-go: [run] " | echohl ErrorMsg | echon "FAILED"| echohl None
|
||||
else
|
||||
@ -69,23 +104,31 @@ function! go#cmd#Run(bang, ...)
|
||||
return
|
||||
endif
|
||||
|
||||
" :make expands '%' and '#' wildcards, so they must also be escaped
|
||||
let default_makeprg = &makeprg
|
||||
if !len(a:000)
|
||||
let &makeprg = 'go run ' . goFiles
|
||||
if a:0 == 0
|
||||
let &makeprg = 'go run ' . go#util#Shelljoin(go#tool#Files(), 1)
|
||||
else
|
||||
let &makeprg = "go run " . expand(a:1)
|
||||
let &makeprg = "go run " . go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
|
||||
endif
|
||||
|
||||
let l:listtype = go#list#Type("quickfix")
|
||||
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
silent! exe 'Make!'
|
||||
silent! exe 'Make'
|
||||
elseif l:listtype == "locationlist"
|
||||
silent! exe 'lmake!'
|
||||
else
|
||||
exe 'make!'
|
||||
silent! exe 'make!'
|
||||
endif
|
||||
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
let items = go#list#Get(l:listtype)
|
||||
let errors = go#tool#FilterValids(items)
|
||||
|
||||
call go#list#Populate(l:listtype, errors)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endif
|
||||
|
||||
let $GOPATH = old_gopath
|
||||
@ -93,66 +136,118 @@ function! go#cmd#Run(bang, ...)
|
||||
endfunction
|
||||
|
||||
" Install installs the package by simple calling 'go install'. If any argument
|
||||
" is given(which are passed directly to 'go insta'') it tries to install those
|
||||
" packages. Errors are populated in the quickfix window.
|
||||
" is given(which are passed directly to 'go install') it tries to install those
|
||||
" packages. Errors are populated in the location window.
|
||||
function! go#cmd#Install(bang, ...)
|
||||
let pkgs = join(a:000, '" "')
|
||||
let command = 'go install "' . pkgs . '"'
|
||||
call go#cmd#autowrite()
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
let default_makeprg = &makeprg
|
||||
|
||||
" :make expands '%' and '#' wildcards, so they must also be escaped
|
||||
let goargs = go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
|
||||
let &makeprg = "go install " . goargs
|
||||
|
||||
let l:listtype = go#list#Type("quickfix")
|
||||
" execute make inside the source folder so we can parse the errors
|
||||
" correctly
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let dir = getcwd()
|
||||
try
|
||||
execute cd . fnameescape(expand("%:p:h"))
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
call go#util#EchoProgress("building dispatched ...")
|
||||
silent! exe 'Make'
|
||||
elseif l:listtype == "locationlist"
|
||||
silent! exe 'lmake!'
|
||||
else
|
||||
silent! exe 'make!'
|
||||
endif
|
||||
return
|
||||
redraw!
|
||||
finally
|
||||
execute cd . fnameescape(dir)
|
||||
endtry
|
||||
|
||||
let errors = go#list#Get(l:listtype)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
if !empty(errors)
|
||||
if !a:bang
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endif
|
||||
else
|
||||
redraws! | echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None
|
||||
let &makeprg = default_makeprg
|
||||
endfunction
|
||||
|
||||
" Test runs `go test` in the current directory. If compile is true, it'll
|
||||
" compile the tests instead of running them (useful to catch errors in the
|
||||
" test files). Any other argument is appendend to the final `go test` command
|
||||
function! go#cmd#Test(bang, compile, ...)
|
||||
let command = "go test "
|
||||
let args = ["test"]
|
||||
|
||||
" don't run the test, only compile it. Useful to capture and fix errors or
|
||||
" to create a test binary.
|
||||
if a:compile
|
||||
let command .= "-c"
|
||||
call add(args, "-c")
|
||||
endif
|
||||
|
||||
if len(a:000)
|
||||
let command .= expand(a:1)
|
||||
if a:0
|
||||
" expand all wildcards(i.e: '%' to the current file name)
|
||||
let goargs = map(copy(a:000), "expand(v:val)")
|
||||
|
||||
call extend(args, goargs, 1)
|
||||
else
|
||||
" only add this if no custom flags are passed
|
||||
let timeout = get(g:, 'go_test_timeout', '10s')
|
||||
call add(args, printf("-timeout=%s", timeout))
|
||||
endif
|
||||
|
||||
if len(a:000) == 2
|
||||
let command .= a:2
|
||||
endif
|
||||
|
||||
call go#cmd#autowrite()
|
||||
if a:compile
|
||||
echon "vim-go: " | echohl Identifier | echon "compiling tests ..." | echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Identifier | echon "testing ..." | echohl None
|
||||
endif
|
||||
|
||||
if has('nvim')
|
||||
if get(g:, 'go_term_enabled', 0)
|
||||
call go#term#new(a:bang, ["go"] + args)
|
||||
else
|
||||
call go#jobcontrol#Spawn(a:bang, "test", args)
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
call go#cmd#autowrite()
|
||||
redraw
|
||||
|
||||
let command = "go " . join(args, ' ')
|
||||
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
|
||||
let l:listtype = "quickfix"
|
||||
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let dir = getcwd()
|
||||
try
|
||||
execute cd fnameescape(expand("%:p:h"))
|
||||
let errors = go#tool#ParseErrors(split(out, '\n'))
|
||||
let errors = go#tool#FilterValids(errors)
|
||||
finally
|
||||
execute cd . fnameescape(dir)
|
||||
endtry
|
||||
|
||||
call go#list#Populate(l:listtype, errors)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
elseif empty(errors)
|
||||
" failed to parse errors, output the original content
|
||||
call go#util#EchoError(out)
|
||||
endif
|
||||
echon "vim-go: " | echohl ErrorMsg | echon "[test] FAIL" | echohl None
|
||||
else
|
||||
call setqflist([])
|
||||
cwindow
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
|
||||
if a:compile
|
||||
echon "vim-go: " | echohl Function | echon "[test] SUCCESS" | echohl None
|
||||
@ -182,17 +277,13 @@ function! go#cmd#TestFunc(bang, ...)
|
||||
|
||||
let line = getline(test)
|
||||
let name = split(split(line, " ")[1], "(")[0]
|
||||
let flag = "-run \"" . name . "$\""
|
||||
let args = [a:bang, 0, "-run", name . "$"]
|
||||
|
||||
let a1 = ""
|
||||
if len(a:000)
|
||||
let a1 = a:1
|
||||
|
||||
" add extra space
|
||||
let flag = " " . flag
|
||||
if a:0
|
||||
call extend(args, a:000)
|
||||
endif
|
||||
|
||||
call go#cmd#Test(a:bang, 0, a1, flag)
|
||||
call call('go#cmd#Test', args)
|
||||
endfunction
|
||||
|
||||
" Coverage creates a new cover profile with 'go test -coverprofile' and opens
|
||||
@ -200,76 +291,64 @@ endfunction
|
||||
function! go#cmd#Coverage(bang, ...)
|
||||
let l:tmpname=tempname()
|
||||
|
||||
let command = "go test -coverprofile=".l:tmpname
|
||||
let command = "go test -coverprofile=" . l:tmpname . ' ' . go#util#Shelljoin(a:000)
|
||||
|
||||
|
||||
let l:listtype = "quickfix"
|
||||
call go#cmd#autowrite()
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
let errors = go#tool#ParseErrors(split(out, '\n'))
|
||||
call go#list#Populate(l:listtype, errors)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endif
|
||||
else
|
||||
" clear previous quick fix window
|
||||
call setqflist([])
|
||||
" clear previous location list
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
|
||||
let openHTML = 'go tool cover -html='.l:tmpname
|
||||
call go#tool#ExecuteInDir(openHTML)
|
||||
endif
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
if !empty(errors) && !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
|
||||
call delete(l:tmpname)
|
||||
endfunction
|
||||
|
||||
" Vet calls "go vet' on the current directory. Any warnings are populated in
|
||||
" the quickfix window
|
||||
function! go#cmd#Vet(bang)
|
||||
call go#cmd#autowrite()
|
||||
echon "vim-go: " | echohl Identifier | echon "calling vet..." | echohl None
|
||||
let out = go#tool#ExecuteInDir('go vet')
|
||||
if v:shell_error
|
||||
call go#tool#ShowErrors(out)
|
||||
else
|
||||
call setqflist([])
|
||||
endif
|
||||
|
||||
let errors = getqflist()
|
||||
if !empty(errors)
|
||||
if !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
endif
|
||||
else
|
||||
redraw | echon "vim-go: " | echohl Function | echon "[vet] PASS" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
"
|
||||
" Generate runs 'go generate' in similar fashion to go#cmd#Build()
|
||||
function! go#cmd#Generate(bang, ...)
|
||||
let default_makeprg = &makeprg
|
||||
let gofiles = join(go#tool#Files(), '" "')
|
||||
|
||||
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 v:shell_error
|
||||
let &makeprg = "go generate " . join(a:000, ' ')
|
||||
let &makeprg = "go generate " . goargs
|
||||
else
|
||||
let &makeprg = "go generate " . join(a:000, ' ') . ' "' . gofiles . '"'
|
||||
let gofiles = go#util#Shelljoin(go#tool#Files(), 1)
|
||||
let &makeprg = "go generate " . goargs . ' ' . gofiles
|
||||
endif
|
||||
|
||||
let l:listtype = go#list#Type("quickfix")
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "generating ..."| echohl None
|
||||
if g:go_dispatch_enabled && exists(':Make') == 2
|
||||
silent! exe 'Make'
|
||||
elseif l:listtype == "locationlist"
|
||||
silent! exe 'lmake!'
|
||||
else
|
||||
silent! exe 'make!'
|
||||
endif
|
||||
redraw!
|
||||
|
||||
cwindow
|
||||
let errors = getqflist()
|
||||
let errors = go#list#Get(l:listtype)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
if !empty(errors)
|
||||
if !a:bang
|
||||
cc 1 "jump to first error if there is any
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endif
|
||||
else
|
||||
redraws! | echon "vim-go: " | echohl Function | echon "[generate] SUCCESS"| echohl None
|
||||
@ -280,4 +359,3 @@ function! go#cmd#Generate(bang, ...)
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
"
|
||||
|
@ -19,13 +19,21 @@ fu! s:gocodeCurrentBuffer()
|
||||
return file
|
||||
endf
|
||||
|
||||
|
||||
if go#vimproc#has_vimproc()
|
||||
let s:vim_system = get(g:, 'gocomplete#system_function', 'vimproc#system2')
|
||||
let s:vim_shell_error = get(g:, 'gocomplete#shell_error_function', 'vimproc#get_last_status')
|
||||
else
|
||||
let s:vim_system = get(g:, 'gocomplete#system_function', 'system')
|
||||
let s:vim_shell_error = ''
|
||||
endif
|
||||
|
||||
fu! s:shell_error()
|
||||
if empty(s:vim_shell_error)
|
||||
return v:shell_error
|
||||
endif
|
||||
return call(s:vim_shell_error, [])
|
||||
endf
|
||||
|
||||
fu! s:system(str, ...)
|
||||
return call(s:vim_system, [a:str] + a:000)
|
||||
endf
|
||||
@ -65,7 +73,7 @@ fu! s:gocodeCommand(cmd, preargs, args)
|
||||
|
||||
let $GOPATH = old_gopath
|
||||
|
||||
if v:shell_error != 0
|
||||
if s:shell_error() != 0
|
||||
return "[\"0\", []]"
|
||||
else
|
||||
if &encoding != 'utf-8'
|
||||
@ -79,7 +87,7 @@ fu! s:gocodeCurrentBufferOpt(filename)
|
||||
return '-in=' . a:filename
|
||||
endf
|
||||
|
||||
fu! s:gocodeCursor()
|
||||
fu! go#complete#gocodeCursor()
|
||||
if &encoding != 'utf-8'
|
||||
let sep = &l:fileformat == 'dos' ? "\r\n" : "\n"
|
||||
let c = col('.')
|
||||
@ -87,6 +95,7 @@ fu! s:gocodeCursor()
|
||||
let buf .= c == 1 ? "" : getline('.')[:c-2]
|
||||
return printf('%d', len(iconv(buf, &encoding, "utf-8")))
|
||||
endif
|
||||
|
||||
return printf('%d', line2byte(line('.')) + (col('.')-2))
|
||||
endf
|
||||
|
||||
@ -94,16 +103,16 @@ fu! s:gocodeAutocomplete()
|
||||
let filename = s:gocodeCurrentBuffer()
|
||||
let result = s:gocodeCommand('autocomplete',
|
||||
\ [s:gocodeCurrentBufferOpt(filename), '-f=vim'],
|
||||
\ [expand('%:p'), s:gocodeCursor()])
|
||||
\ [expand('%:p'), go#complete#gocodeCursor()])
|
||||
call delete(filename)
|
||||
return result
|
||||
endf
|
||||
|
||||
function! go#complete#GetInfo()
|
||||
function! go#complete#GetInfoFromOffset(offset)
|
||||
let filename = s:gocodeCurrentBuffer()
|
||||
let result = s:gocodeCommand('autocomplete',
|
||||
\ [s:gocodeCurrentBufferOpt(filename), '-f=godit'],
|
||||
\ [expand('%:p'), s:gocodeCursor()])
|
||||
\ [expand('%:p'), a:offset])
|
||||
call delete(filename)
|
||||
|
||||
" first line is: Charcount,,NumberOfCandidates, i.e: 8,,1
|
||||
@ -139,6 +148,11 @@ function! go#complete#GetInfo()
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
function! go#complete#GetInfo()
|
||||
let offset = go#complete#gocodeCursor()
|
||||
return go#complete#GetInfoFromOffset(offset)
|
||||
endfunction
|
||||
|
||||
function! go#complete#Info()
|
||||
let result = go#complete#GetInfo()
|
||||
if !empty(result)
|
||||
|
@ -2,6 +2,15 @@ if !exists("g:go_godef_bin")
|
||||
let g:go_godef_bin = "godef"
|
||||
endif
|
||||
|
||||
if go#vimproc#has_vimproc()
|
||||
let s:vim_system = get(g:, 'gocomplete#system_function', 'vimproc#system2')
|
||||
else
|
||||
let s:vim_system = get(g:, 'gocomplete#system_function', 'system')
|
||||
endif
|
||||
|
||||
fu! s:system(str, ...)
|
||||
return call(s:vim_system, [a:str] + a:000)
|
||||
endf
|
||||
|
||||
" modified and improved version of vim-godef
|
||||
function! go#def#Jump(...)
|
||||
@ -21,10 +30,11 @@ function! go#def#Jump(...)
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let command = bin_path . " -f=" . shellescape(expand("%:p")) . " -i " . shellescape(arg)
|
||||
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
|
||||
let command = bin_path . " -f=" . shellescape(fname) . " -i " . shellescape(arg)
|
||||
|
||||
" get output of godef
|
||||
let out=system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding()))
|
||||
let out = s:system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding()))
|
||||
|
||||
" jump to it
|
||||
call s:godefJump(out, "")
|
||||
@ -43,10 +53,11 @@ function! go#def#JumpMode(mode)
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let command = bin_path . " -f=" . shellescape(expand("%:p")) . " -i " . shellescape(arg)
|
||||
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
|
||||
let command = bin_path . " -f=" . shellescape(fname) . " -i " . shellescape(arg)
|
||||
|
||||
" get output of godef
|
||||
let out=system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding()))
|
||||
let out = s:system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding()))
|
||||
|
||||
call s:godefJump(out, a:mode)
|
||||
let $GOPATH = old_gopath
|
||||
@ -74,7 +85,7 @@ function! s:godefJump(out, mode)
|
||||
let &errorformat = "%f:%l:%c"
|
||||
|
||||
if a:out =~ 'godef: '
|
||||
let out=substitute(a:out, go#util#LineEnding() . '$', '', '')
|
||||
let out = substitute(a:out, go#util#LineEnding() . '$', '', '')
|
||||
echom out
|
||||
else
|
||||
let parts = split(a:out, ':')
|
||||
|
@ -1,54 +0,0 @@
|
||||
if !exists("g:go_errcheck_bin")
|
||||
let g:go_errcheck_bin = "errcheck"
|
||||
endif
|
||||
|
||||
function! go#errcheck#Run(...) abort
|
||||
if a:0 == 0
|
||||
let package = go#package#ImportPath(expand('%:p:h'))
|
||||
if package == -1
|
||||
echohl Error | echomsg "vim-go: package is not inside GOPATH src" | echohl None
|
||||
return
|
||||
endif
|
||||
else
|
||||
let package = a:1
|
||||
end
|
||||
|
||||
let bin_path = go#path#CheckBinPath(g:go_errcheck_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "errcheck analysing ..." | echohl None
|
||||
let out = system(bin_path . ' ' . package)
|
||||
if v:shell_error
|
||||
let errors = []
|
||||
let mx = '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)'
|
||||
for line in split(out, '\n')
|
||||
let tokens = matchlist(line, mx)
|
||||
|
||||
if !empty(tokens)
|
||||
call add(errors, {"filename": expand(go#path#Default() . "/src/" . tokens[1]),
|
||||
\"lnum": tokens[2],
|
||||
\"col": tokens[3],
|
||||
\"text": tokens[4]})
|
||||
endif
|
||||
endfor
|
||||
|
||||
if empty(errors)
|
||||
echohl Error | echomsg "GoErrCheck returned error" | echohl None
|
||||
echo out
|
||||
endif
|
||||
|
||||
if !empty(errors)
|
||||
redraw | echo
|
||||
call setqflist(errors, 'r')
|
||||
endif
|
||||
else
|
||||
redraw | echo
|
||||
call setqflist([])
|
||||
endif
|
||||
|
||||
cwindow
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
@ -43,8 +43,6 @@ if !exists("g:go_fmt_experimental")
|
||||
let g:go_fmt_experimental = 0
|
||||
endif
|
||||
|
||||
let s:got_fmt_error = 0
|
||||
|
||||
" we have those problems :
|
||||
" http://stackoverflow.com/questions/12741977/prevent-vim-from-updating-its-undo-tree
|
||||
" http://stackoverflow.com/questions/18532692/golang-formatter-and-vim-how-to-destroy-history-record?rq=1
|
||||
@ -54,13 +52,17 @@ let s:got_fmt_error = 0
|
||||
" this and have VimL experience, please look at the function for
|
||||
" improvements, patches are welcome :)
|
||||
function! go#fmt#Format(withGoimport)
|
||||
" save cursor position and many other things
|
||||
let l:curw=winsaveview()
|
||||
|
||||
" needed for testing if gofmt fails or not
|
||||
let l:tmpname=tempname()
|
||||
call writefile(getline(1,'$'), l:tmpname)
|
||||
" save cursor position, folds and many other things
|
||||
let l:curw = {}
|
||||
try
|
||||
mkview!
|
||||
catch
|
||||
let l:curw=winsaveview()
|
||||
endtry
|
||||
|
||||
" Write current unsaved buffer to a temp file
|
||||
let l:tmpname = tempname()
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
|
||||
if g:go_fmt_experimental == 1
|
||||
" save our undo file to be restored after we are done. This is needed to
|
||||
@ -77,16 +79,15 @@ function! go#fmt#Format(withGoimport)
|
||||
let fmt_command = g:go_goimports_bin
|
||||
endif
|
||||
|
||||
" if it's something else than gofmt, we need to check the existing of that
|
||||
" binary. For example if it's goimports, let us check if it's installed,
|
||||
" check if the user has installed command binary.
|
||||
" For example if it's goimports, let us check if it's installed,
|
||||
" if not the user get's a warning via go#path#CheckBinPath()
|
||||
if fmt_command != "gofmt"
|
||||
" check if the user has installed goimports
|
||||
let bin_path = go#path#CheckBinPath(fmt_command)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
let bin_path = go#path#CheckBinPath(fmt_command)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
if fmt_command != "gofmt"
|
||||
" change GOPATH too, so goimports can pick up the correct library
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
@ -95,17 +96,19 @@ function! go#fmt#Format(withGoimport)
|
||||
endif
|
||||
|
||||
" populate the final command with user based fmt options
|
||||
let command = fmt_command . ' ' . g:go_fmt_options
|
||||
let command = fmt_command . ' -w '
|
||||
if a:withGoimport != 1
|
||||
let command = command . g:go_fmt_options
|
||||
endif
|
||||
|
||||
" execute our command...
|
||||
let out = system(command . " " . l:tmpname)
|
||||
let splitted = split(out, '\n')
|
||||
|
||||
if fmt_command != "gofmt"
|
||||
let $GOPATH = old_gopath
|
||||
endif
|
||||
|
||||
|
||||
let l:listtype = "locationlist"
|
||||
"if there is no error on the temp file replace the output with the current
|
||||
"file (if this fails, we can always check the outputs first line with:
|
||||
"splitted =~ 'package \w\+')
|
||||
@ -113,34 +116,22 @@ function! go#fmt#Format(withGoimport)
|
||||
" remove undo point caused via BufWritePre
|
||||
try | silent undojoin | catch | endtry
|
||||
|
||||
" do not include stderr to the buffer, this is due to goimports/gofmt
|
||||
" tha fails with a zero exit return value (sad yeah).
|
||||
let default_srr = &srr
|
||||
set srr=>%s
|
||||
" Replace current file with temp file, then reload buffer
|
||||
let old_fileformat = &fileformat
|
||||
call rename(l:tmpname, expand('%'))
|
||||
silent edit!
|
||||
let &fileformat = old_fileformat
|
||||
let &syntax = &syntax
|
||||
|
||||
" delete any leftover before we replace the whole file. Suppose the
|
||||
" file had 20 lines, but new output has 10 lines, only 1-10 are
|
||||
" replaced with setline, remaining lines 11-20 won't get touched. So
|
||||
" remove them.
|
||||
if line('$') > len(splitted)
|
||||
execute len(splitted) .',$delete'
|
||||
" clean up previous location list, but only if it's due to fmt
|
||||
if exists('b:got_fmt_error') && b:got_fmt_error
|
||||
let b:got_fmt_error = 0
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
endif
|
||||
|
||||
" setline iterates over the list and replaces each line
|
||||
call setline(1, splitted)
|
||||
|
||||
" only clear quickfix if it was previously set, this prevents closing
|
||||
" other quickfixes
|
||||
if s:got_fmt_error
|
||||
let s:got_fmt_error = 0
|
||||
call setqflist([])
|
||||
cwindow
|
||||
endif
|
||||
|
||||
" put back the users srr setting
|
||||
let &srr = default_srr
|
||||
elseif g:go_fmt_fail_silently == 0
|
||||
"otherwise get the errors and put them to quickfix window
|
||||
elseif g:go_fmt_fail_silently == 0
|
||||
let splitted = split(out, '\n')
|
||||
"otherwise get the errors and put them to location list
|
||||
let errors = []
|
||||
for line in splitted
|
||||
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
|
||||
@ -155,11 +146,15 @@ function! go#fmt#Format(withGoimport)
|
||||
% | " Couldn't detect gofmt error format, output errors
|
||||
endif
|
||||
if !empty(errors)
|
||||
call setqflist(errors, 'r')
|
||||
call go#list#Populate(l:listtype, errors)
|
||||
echohl Error | echomsg "Gofmt returned error" | echohl None
|
||||
endif
|
||||
let s:got_fmt_error = 1
|
||||
cwindow
|
||||
|
||||
let b:got_fmt_error = 1
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
|
||||
" We didn't use the temp file, so clean up
|
||||
call delete(l:tmpname)
|
||||
endif
|
||||
|
||||
if g:go_fmt_experimental == 1
|
||||
@ -168,9 +163,12 @@ function! go#fmt#Format(withGoimport)
|
||||
call delete(tmpundofile)
|
||||
endif
|
||||
|
||||
" restore our cursor/windows positions
|
||||
call delete(l:tmpname)
|
||||
call winrestview(l:curw)
|
||||
" restore our cursor/windows positions, folds, etc..
|
||||
if empty(l:curw)
|
||||
silent! loadview
|
||||
else
|
||||
call winrestview(l:curw)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
|
@ -2,46 +2,11 @@
|
||||
" Use of this source code is governed by a BSD-style
|
||||
" license that can be found in the LICENSE file.
|
||||
"
|
||||
" import.vim: Vim commands to import/drop Go packages.
|
||||
" Check out the docs for more information at /doc/vim-go.txt
|
||||
"
|
||||
" This filetype plugin adds three new commands for go buffers:
|
||||
"
|
||||
" :GoImport {path}
|
||||
"
|
||||
" Import ensures that the provided package {path} is imported
|
||||
" in the current Go buffer, using proper style and ordering.
|
||||
" If {path} is already being imported, an error will be
|
||||
" displayed and the buffer will be untouched.
|
||||
"
|
||||
" :GoImportAs {localname} {path}
|
||||
"
|
||||
" Same as Import, but uses a custom local name for the package.
|
||||
"
|
||||
" :GoDrop {path}
|
||||
"
|
||||
" Remove the import line for the provided package {path}, if
|
||||
" present in the current Go buffer. If {path} is not being
|
||||
" imported, an error will be displayed and the buffer will be
|
||||
" untouched.
|
||||
"
|
||||
" If you would like to add shortcuts, you can do so by doing the following:
|
||||
"
|
||||
" Import fmt
|
||||
" au Filetype go nnoremap <buffer> <LocalLeader>f :Import fmt<CR>
|
||||
"
|
||||
" Drop fmt
|
||||
" au Filetype go nnoremap <buffer> <LocalLeader>F :Drop fmt<CR>
|
||||
"
|
||||
" Import the word under your cursor
|
||||
" au Filetype go nnoremap <buffer> <LocalLeader>k
|
||||
" \ :exe 'Import ' . expand('<cword>')<CR>
|
||||
"
|
||||
" The backslash '\' is the default maplocalleader, so it is possible that
|
||||
" your vim is set to use a different character (:help maplocalleader).
|
||||
"
|
||||
function! go#import#SwitchImport(enabled, localname, path)
|
||||
function! go#import#SwitchImport(enabled, localname, path, bang)
|
||||
let view = winsaveview()
|
||||
let path = a:path
|
||||
let path = substitute(a:path, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
|
||||
" Quotes are not necessary, so remove them if provided.
|
||||
if path[0] == '"'
|
||||
@ -61,6 +26,12 @@ function! go#import#SwitchImport(enabled, localname, path)
|
||||
return
|
||||
endif
|
||||
|
||||
if a:bang == "!"
|
||||
let out = system("go get -u -v ".shellescape(path))
|
||||
if v:shell_error
|
||||
call s:Error("Can't find import: " . path . ":" . out)
|
||||
endif
|
||||
endif
|
||||
let exists = go#tool#Exists(path)
|
||||
if exists == -1
|
||||
call s:Error("Can't find import: " . path)
|
||||
|
179
sources_non_forked/vim-go/autoload/go/jobcontrol.vim
Normal file
179
sources_non_forked/vim-go/autoload/go/jobcontrol.vim
Normal file
@ -0,0 +1,179 @@
|
||||
" s:jobs is a global reference to all jobs started with Spawn() or with the
|
||||
" internal function s:spawn
|
||||
let s:jobs = {}
|
||||
|
||||
" Spawn is a wrapper around s:spawn. It can be executed by other files and
|
||||
" scripts if needed. Desc defines the description for printing the status
|
||||
" during the job execution (useful for statusline integration).
|
||||
function! go#jobcontrol#Spawn(bang, desc, args)
|
||||
" autowrite is not enabled for jobs
|
||||
call go#cmd#autowrite()
|
||||
|
||||
let job = s:spawn(a:bang, a:desc, a:args)
|
||||
return job.id
|
||||
endfunction
|
||||
|
||||
" Statusline returns the current status of the job
|
||||
function! go#jobcontrol#Statusline() abort
|
||||
if empty(s:jobs)
|
||||
return ''
|
||||
endif
|
||||
|
||||
let import_path = go#package#ImportPath(expand('%:p:h'))
|
||||
|
||||
for job in values(s:jobs)
|
||||
if job.importpath != import_path
|
||||
continue
|
||||
endif
|
||||
|
||||
if job.state == "SUCCESS"
|
||||
return ''
|
||||
endif
|
||||
|
||||
return printf("%s ... [%s]", job.desc, job.state)
|
||||
endfor
|
||||
|
||||
return ''
|
||||
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.
|
||||
function! s:spawn(bang, desc, args)
|
||||
let job = {
|
||||
\ 'desc': a:desc,
|
||||
\ 'bang': a:bang,
|
||||
\ 'winnr': winnr(),
|
||||
\ 'importpath': go#package#ImportPath(expand('%:p:h')),
|
||||
\ 'state': "RUNNING",
|
||||
\ 'stderr' : [],
|
||||
\ 'stdout' : [],
|
||||
\ 'on_stdout': function('s:on_stdout'),
|
||||
\ 'on_stderr': function('s:on_stderr'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
|
||||
" 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 '
|
||||
|
||||
" cleanup previous jobs for this file
|
||||
for jb in values(s:jobs)
|
||||
if jb.importpath == job.importpath
|
||||
unlet s:jobs[jb.id]
|
||||
endif
|
||||
endfor
|
||||
|
||||
let dir = getcwd()
|
||||
let jobdir = fnameescape(expand("%:p:h"))
|
||||
execute cd . jobdir
|
||||
|
||||
" append the subcommand, such as 'build'
|
||||
let argv = ['go'] + a:args
|
||||
|
||||
" run, forrest, run!
|
||||
let id = jobstart(argv, job)
|
||||
let job.id = id
|
||||
let job.dir = jobdir
|
||||
let s:jobs[id] = job
|
||||
|
||||
execute cd . fnameescape(dir)
|
||||
|
||||
" restore back GOPATH
|
||||
let $GOPATH = old_gopath
|
||||
|
||||
return job
|
||||
endfunction
|
||||
|
||||
" on_exit is the exit handler for jobstart(). It handles cleaning up the job
|
||||
" references and also displaying errors in the quickfix window collected by
|
||||
" on_stderr handler. If there are no errors and a quickfix window is open,
|
||||
" it'll be closed.
|
||||
function! s:on_exit(job_id, exit_status)
|
||||
let std_combined = self.stderr + self.stdout
|
||||
if a:exit_status == 0
|
||||
call go#list#Clean(0)
|
||||
call go#list#Window(0)
|
||||
|
||||
let self.state = "SUCCESS"
|
||||
call go#util#EchoSuccess("SUCCESS")
|
||||
return
|
||||
endif
|
||||
|
||||
let self.state = "FAILED"
|
||||
call go#util#EchoError("FAILED")
|
||||
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let dir = getcwd()
|
||||
try
|
||||
execute cd self.dir
|
||||
let errors = go#tool#ParseErrors(std_combined)
|
||||
let errors = go#tool#FilterValids(errors)
|
||||
finally
|
||||
execute cd . fnameescape(dir)
|
||||
endtry
|
||||
|
||||
if !len(errors)
|
||||
" failed to parse errors, output the original content
|
||||
call go#util#EchoError(std_combined[0])
|
||||
return
|
||||
endif
|
||||
|
||||
" if we are still in the same windows show the list
|
||||
if self.winnr == winnr()
|
||||
let l:listtype = "locationlist"
|
||||
call go#list#Populate(l:listtype, errors)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
if !empty(errors) && !self.bang
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" on_stdout is the stdout handler for jobstart(). It collects the output of
|
||||
" stderr and stores them to the jobs internal stdout list.
|
||||
function! s:on_stdout(job_id, data)
|
||||
call extend(self.stdout, a:data)
|
||||
endfunction
|
||||
|
||||
" on_stderr is the stderr handler for jobstart(). It collects the output of
|
||||
" stderr and stores them to the jobs internal stderr list.
|
||||
function! s:on_stderr(job_id, data)
|
||||
call extend(self.stderr, a:data)
|
||||
endfunction
|
||||
|
||||
" abort_all aborts all current jobs created with s:spawn()
|
||||
function! s:abort_all()
|
||||
if empty(s:jobs)
|
||||
return
|
||||
endif
|
||||
|
||||
for id in keys(s:jobs)
|
||||
if id > 0
|
||||
silent! call jobstop(id)
|
||||
endif
|
||||
endfor
|
||||
|
||||
let s:jobs = {}
|
||||
endfunction
|
||||
|
||||
" abort aborts the job with the given name, where name is the first argument
|
||||
" passed to s:spawn()
|
||||
function! s:abort(path)
|
||||
if empty(s:jobs)
|
||||
return
|
||||
endif
|
||||
|
||||
for job in values(s:jobs)
|
||||
if job.importpath == path && job.id > 0
|
||||
silent! call jobstop(job.id)
|
||||
unlet s:jobs['job.id']
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" vim:ts=2:sw=2:et
|
@ -1,30 +1,199 @@
|
||||
" Copyright 2013 The Go Authors. All rights reserved.
|
||||
" Use of this source code is governed by a BSD-style
|
||||
" license that can be found in the LICENSE file.
|
||||
"
|
||||
" lint.vim: Vim command to lint Go files with golint.
|
||||
"
|
||||
" https://github.com/golang/lint
|
||||
"
|
||||
" This filetype plugin add a new commands for go buffers:
|
||||
"
|
||||
" :GoLint
|
||||
"
|
||||
" Run golint for the current Go file.
|
||||
"
|
||||
if !exists("g:go_metalinter_command")
|
||||
let g:go_metalinter_command = ""
|
||||
endif
|
||||
|
||||
if !exists("g:go_metalinter_autosave_enabled")
|
||||
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
|
||||
endif
|
||||
|
||||
if !exists("g:go_metalinter_enabled")
|
||||
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
|
||||
endif
|
||||
|
||||
if !exists("g:go_metalinter_deadline")
|
||||
let g:go_metalinter_deadline = "5s"
|
||||
endif
|
||||
|
||||
if !exists("g:go_golint_bin")
|
||||
let g:go_golint_bin = "golint"
|
||||
endif
|
||||
|
||||
function! go#lint#Run() abort
|
||||
if !exists("g:go_errcheck_bin")
|
||||
let g:go_errcheck_bin = "errcheck"
|
||||
endif
|
||||
|
||||
function! go#lint#Gometa(autosave, ...) abort
|
||||
if a:0 == 0
|
||||
let goargs = expand('%:p:h')
|
||||
else
|
||||
let goargs = go#util#Shelljoin(a:000)
|
||||
endif
|
||||
|
||||
let meta_command = "gometalinter --disable-all"
|
||||
if a:autosave || empty(g:go_metalinter_command)
|
||||
let bin_path = go#path#CheckBinPath("gometalinter")
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
if a:autosave
|
||||
" include only messages for the active buffer
|
||||
let meta_command .= " --include='^" . expand('%:p') . ".*$'"
|
||||
endif
|
||||
|
||||
" linters
|
||||
let linters = a:autosave ? g:go_metalinter_autosave_enabled : g:go_metalinter_enabled
|
||||
for linter in linters
|
||||
let meta_command .= " --enable=".linter
|
||||
endfor
|
||||
|
||||
" deadline
|
||||
let meta_command .= " --deadline=" . g:go_metalinter_deadline
|
||||
|
||||
" path
|
||||
let meta_command .= " " . goargs
|
||||
else
|
||||
" the user wants something else, let us use it.
|
||||
let meta_command = g:go_metalinter_command
|
||||
endif
|
||||
|
||||
" comment out the following two lines for debugging
|
||||
" echo meta_command
|
||||
" return
|
||||
|
||||
let out = go#tool#ExecuteInDir(meta_command)
|
||||
|
||||
let l:listtype = "quickfix"
|
||||
if v:shell_error == 0
|
||||
redraw | echo
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
echon "vim-go: " | echohl Function | echon "[metalinter] PASS" | echohl None
|
||||
else
|
||||
" GoMetaLinter can output one of the two, so we look for both:
|
||||
" <file>:<line>:[<column>]: <message> (<linter>)
|
||||
" <file>:<line>:: <message> (<linter>)
|
||||
" This can be defined by the following errorformat:
|
||||
let errformat = "%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m"
|
||||
|
||||
" Parse and populate our location list
|
||||
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"))
|
||||
|
||||
let errors = go#list#Get(l:listtype)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
|
||||
if !a:autosave
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Golint calls 'golint' on the current directory. Any warnings are populated in
|
||||
" the location list
|
||||
function! go#lint#Golint(...) abort
|
||||
let bin_path = go#path#CheckBinPath(g:go_golint_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
silent cexpr system(bin_path . " " . shellescape(expand('%')))
|
||||
cwindow
|
||||
if a:0 == 0
|
||||
let goargs = shellescape(expand('%'))
|
||||
else
|
||||
let goargs = go#util#Shelljoin(a:000)
|
||||
endif
|
||||
|
||||
let out = system(bin_path . " " . goargs)
|
||||
if empty(out)
|
||||
echon "vim-go: " | echohl Function | echon "[lint] PASS" | echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
let l:listtype = "quickfix"
|
||||
call go#list#Parse(l:listtype, out)
|
||||
let errors = go#list#Get(l:listtype)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endfunction
|
||||
|
||||
" Vet calls 'go vet' on the current directory. Any warnings are populated in
|
||||
" the location list
|
||||
function! go#lint#Vet(bang, ...)
|
||||
call go#cmd#autowrite()
|
||||
echon "vim-go: " | echohl Identifier | echon "calling vet..." | echohl None
|
||||
if a:0 == 0
|
||||
let out = go#tool#ExecuteInDir('go vet')
|
||||
else
|
||||
let out = go#tool#ExecuteInDir('go tool vet ' . go#util#Shelljoin(a:000))
|
||||
endif
|
||||
|
||||
let l:listtype = "quickfix"
|
||||
if v:shell_error
|
||||
let errors = go#tool#ParseErrors(split(out, '\n'))
|
||||
call go#list#Populate(l:listtype, errors)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endif
|
||||
echon "vim-go: " | echohl ErrorMsg | echon "[vet] FAIL" | echohl None
|
||||
else
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
redraw | echon "vim-go: " | echohl Function | echon "[vet] PASS" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" ErrCheck calls 'errcheck' for the given packages. Any warnings are populated in
|
||||
" the location list
|
||||
function! go#lint#Errcheck(...) abort
|
||||
if a:0 == 0
|
||||
let goargs = go#package#ImportPath(expand('%:p:h'))
|
||||
if goargs == -1
|
||||
echohl Error | echomsg "vim-go: package is not inside GOPATH src" | echohl None
|
||||
return
|
||||
endif
|
||||
else
|
||||
let goargs = go#util#Shelljoin(a:000)
|
||||
endif
|
||||
|
||||
let bin_path = go#path#CheckBinPath(g:go_errcheck_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "errcheck analysing ..." | echohl None
|
||||
redraw
|
||||
|
||||
let command = bin_path . ' -abspath ' . goargs
|
||||
let out = go#tool#ExecuteInDir(command)
|
||||
|
||||
let l:listtype = "quickfix"
|
||||
if v:shell_error
|
||||
let errformat = "%f:%l:%c:\ %m, %f:%l:%c\ %#%m"
|
||||
|
||||
" Parse and populate our location list
|
||||
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"))
|
||||
|
||||
let errors = go#list#Get(l:listtype)
|
||||
|
||||
if empty(errors)
|
||||
echohl Error | echomsg "GoErrCheck returned error" | echohl None
|
||||
echo out
|
||||
return
|
||||
endif
|
||||
|
||||
if !empty(errors)
|
||||
call go#list#Populate(l:listtype, errors)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
if !empty(errors)
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endif
|
||||
endif
|
||||
else
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
echon "vim-go: " | echohl Function | echon "[errcheck] PASS" | echohl None
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
126
sources_non_forked/vim-go/autoload/go/list.vim
Normal file
126
sources_non_forked/vim-go/autoload/go/list.vim
Normal file
@ -0,0 +1,126 @@
|
||||
if !exists("g:go_list_type")
|
||||
let g:go_list_type = ""
|
||||
endif
|
||||
|
||||
" Window opens the list with the given height up to 10 lines maximum.
|
||||
" Otherwise g:go_loclist_height is used. If no or zero height is given it
|
||||
" closes the window
|
||||
function! go#list#Window(listtype, ...)
|
||||
let l:listtype = go#list#Type(a:listtype)
|
||||
" we don't use lwindow to close the location list as we need also the
|
||||
" ability to resize the window. So, we are going to use lopen and lclose
|
||||
" for a better user experience. If the number of errors in a current
|
||||
" location list increases/decreases, cwindow will not resize when a new
|
||||
" updated height is passed. lopen in the other hand resizes the screen.
|
||||
if !a:0 || a:1 == 0
|
||||
if l:listtype == "locationlist"
|
||||
lclose
|
||||
else
|
||||
cclose
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
let height = get(g:, "go_list_height", 0)
|
||||
if height == 0
|
||||
" prevent creating a large location height for a large set of numbers
|
||||
if a:1 > 10
|
||||
let height = 10
|
||||
else
|
||||
let height = a:1
|
||||
endif
|
||||
endif
|
||||
|
||||
if l:listtype == "locationlist"
|
||||
exe 'lopen ' . height
|
||||
else
|
||||
exe 'copen ' . height
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" Get returns the current list of items from the location list
|
||||
function! go#list#Get(listtype)
|
||||
let l:listtype = go#list#Type(a:listtype)
|
||||
if l:listtype == "locationlist"
|
||||
return getloclist(0)
|
||||
else
|
||||
return getqflist()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Populate populate the location list with the given items
|
||||
function! go#list#Populate(listtype, items)
|
||||
let l:listtype = go#list#Type(a:listtype)
|
||||
if l:listtype == "locationlist"
|
||||
call setloclist(0, a:items, 'r')
|
||||
else
|
||||
call setqflist(a:items, 'r')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! go#list#PopulateWin(winnr, items)
|
||||
call setloclist(a:winnr, a:items, 'r')
|
||||
endfunction
|
||||
|
||||
" Parse parses the given items based on the specified errorformat nad
|
||||
" populates the location list.
|
||||
function! go#list#ParseFormat(listtype, errformat, items)
|
||||
let l:listtype = go#list#Type(a:listtype)
|
||||
" backup users errorformat, will be restored once we are finished
|
||||
let old_errorformat = &errorformat
|
||||
|
||||
" parse and populate the location list
|
||||
let &errorformat = a:errformat
|
||||
if l:listtype == "locationlist"
|
||||
lgetexpr a:items
|
||||
else
|
||||
cgetexpr a:items
|
||||
endif
|
||||
|
||||
"restore back
|
||||
let &errorformat = old_errorformat
|
||||
endfunction
|
||||
|
||||
" Parse parses the given items based on the global errorformat and
|
||||
" populates the location list.
|
||||
function! go#list#Parse(listtype, items)
|
||||
let l:listtype = go#list#Type(a:listtype)
|
||||
if l:listtype == "locationlist"
|
||||
lgetexpr a:items
|
||||
else
|
||||
cgetexpr a:items
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" JumpToFirst jumps to the first item in the location list
|
||||
function! go#list#JumpToFirst(listtype)
|
||||
let l:listtype = go#list#Type(a:listtype)
|
||||
if l:listtype == "locationlist"
|
||||
ll 1
|
||||
else
|
||||
cc 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Clean cleans the location list
|
||||
function! go#list#Clean(listtype)
|
||||
let l:listtype = go#list#Type(a:listtype)
|
||||
if l:listtype == "locationlist"
|
||||
lex []
|
||||
else
|
||||
cex []
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! go#list#Type(listtype)
|
||||
if g:go_list_type == "locationlist"
|
||||
return "locationlist"
|
||||
elseif g:go_list_type == "quickfix"
|
||||
return "quickfix"
|
||||
else
|
||||
return a:listtype
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
@ -10,9 +10,9 @@ if !exists("g:go_oracle_bin")
|
||||
endif
|
||||
|
||||
" Parses (via regex) Oracle's 'plain' format output and puts them into a
|
||||
" quickfix list.
|
||||
func! s:qflist(output)
|
||||
let qflist = []
|
||||
" location list
|
||||
func! s:loclist(output)
|
||||
let llist = []
|
||||
" Parse GNU-style 'file:line.col-line.col: message' format.
|
||||
let mx = '^\(\a:[\\/][^:]\+\|[^:]\+\):\(\d\+\):\(\d\+\):\(.*\)$'
|
||||
for line in split(a:output, "\n")
|
||||
@ -33,17 +33,17 @@ func! s:qflist(output)
|
||||
if bnr != -1
|
||||
let item['bufnr'] = bnr
|
||||
endif
|
||||
call add(qflist, item)
|
||||
call add(llist, item)
|
||||
endfor
|
||||
call setqflist(qflist)
|
||||
cwindow
|
||||
call go#list#Populate("locationlist", llist)
|
||||
call go#list#Window("locationlist", len(llist))
|
||||
endfun
|
||||
|
||||
" This uses Vim's errorformat to parse the output from Oracle's 'plain output
|
||||
" and put it into quickfix list. I believe using errorformat is much more
|
||||
" and put it into location list. I believe using errorformat is much more
|
||||
" easier to use. If we need more power we can always switch back to parse it
|
||||
" via regex.
|
||||
func! s:qflistSecond(output)
|
||||
func! s:loclistSecond(output)
|
||||
" backup users errorformat, will be restored once we are finished
|
||||
let old_errorformat = &errorformat
|
||||
|
||||
@ -53,15 +53,13 @@ func! s:qflistSecond(output)
|
||||
" 'file:line:col: message'
|
||||
"
|
||||
" We discard line2 and col2 for the first errorformat, because it's not
|
||||
" useful and quickfix only has the ability to show one line and column
|
||||
" useful and location only has the ability to show one line and column
|
||||
" number
|
||||
let &errorformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
|
||||
let errformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
|
||||
call go#list#ParseFormat("locationlist", errformat, split(a:output, "\n"))
|
||||
|
||||
" create the quickfix list and open it
|
||||
cgetexpr split(a:output, "\n")
|
||||
cwindow
|
||||
|
||||
let &errorformat = old_errorformat
|
||||
let errors = go#list#Get("locationlist")
|
||||
call go#list#Window("locationlist", len(errors))
|
||||
endfun
|
||||
|
||||
func! s:getpos(l, c)
|
||||
@ -73,7 +71,7 @@ func! s:getpos(l, c)
|
||||
return line2byte(a:l) + (a:c-2)
|
||||
endfun
|
||||
|
||||
func! s:RunOracle(mode, selected) range abort
|
||||
func! s:RunOracle(mode, selected, needs_package) range abort
|
||||
let fname = expand('%:p')
|
||||
let dname = expand('%:p:h')
|
||||
let pkg = go#package#ImportPath(dname)
|
||||
@ -81,14 +79,10 @@ func! s:RunOracle(mode, selected) range abort
|
||||
if exists('g:go_oracle_scope')
|
||||
" let the user defines the scope, must be a space separated string,
|
||||
" example: 'fmt math net/http'
|
||||
let unescaped_scopes = split(get(g:, 'go_oracle_scope'))
|
||||
let scopes = []
|
||||
for unescaped_scope in unescaped_scopes
|
||||
call add(scopes, shellescape(unescaped_scope))
|
||||
endfor
|
||||
elseif exists('g:go_oracle_include_tests') && pkg != -1
|
||||
let scopes = split(get(g:, 'go_oracle_scope'))
|
||||
elseif a:needs_package || exists('g:go_oracle_include_tests') && pkg != -1
|
||||
" give import path so it includes all _test.go files too
|
||||
let scopes = [shellescape(pkg)]
|
||||
let scopes = [pkg]
|
||||
else
|
||||
" best usable way, only pass the package itself, without the test
|
||||
" files
|
||||
@ -100,27 +94,31 @@ func! s:RunOracle(mode, selected) range abort
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
if exists('g:go_oracle_tags')
|
||||
let tags = get(g:, 'go_oracle_tags')
|
||||
else
|
||||
let tags = ""
|
||||
endif
|
||||
|
||||
if a:selected != -1
|
||||
let pos1 = s:getpos(line("'<"), col("'<"))
|
||||
let pos2 = s:getpos(line("'>"), col("'>"))
|
||||
let cmd = printf('%s -format plain -pos=%s:#%d,#%d %s',
|
||||
let cmd = printf('%s -format plain -pos=%s:#%d,#%d -tags=%s %s',
|
||||
\ bin_path,
|
||||
\ shellescape(fname), pos1, pos2, a:mode)
|
||||
\ shellescape(fname), pos1, pos2, tags, a:mode)
|
||||
else
|
||||
let pos = s:getpos(line('.'), col('.'))
|
||||
let cmd = printf('%s -format plain -pos=%s:#%d %s',
|
||||
let cmd = printf('%s -format plain -pos=%s:#%d -tags=%s %s',
|
||||
\ bin_path,
|
||||
\ shellescape(fname), pos, a:mode)
|
||||
\ shellescape(fname), pos, tags, a:mode)
|
||||
endif
|
||||
|
||||
" now append each scope to the end as Oracle's scope parameter. It can be
|
||||
" a packages or go files, dependent on the User's own choice. For more
|
||||
" info check Oracle's User Manual section about scopes:
|
||||
" https://docs.google.com/document/d/1SLk36YRjjMgKqe490mSRzOPYEDe0Y_WQNRv-EiFYUyw/view#heading=h.nwso96pj07q8
|
||||
for scope in scopes
|
||||
let cmd .= ' ' . scope
|
||||
endfor
|
||||
let cmd .= ' ' . go#util#Shelljoin(scopes)
|
||||
|
||||
echon "vim-go: " | echohl Identifier | echon "analysing ..." | echohl None
|
||||
|
||||
@ -143,9 +141,9 @@ func! s:RunOracle(mode, selected) range abort
|
||||
endfunc
|
||||
|
||||
function! go#oracle#Scope(...)
|
||||
if len(a:000)
|
||||
if len(a:000) == 1 && a:1 == '""'
|
||||
let g:go_oracle_scope = ""
|
||||
if a:0
|
||||
if a:0 == 1 && a:1 == '""'
|
||||
unlet g:go_oracle_scope
|
||||
echon "vim-go: " | echohl Function | echon "oracle scope is cleared"| echohl None
|
||||
else
|
||||
let g:go_oracle_scope = join(a:000, ' ')
|
||||
@ -155,59 +153,85 @@ function! go#oracle#Scope(...)
|
||||
return
|
||||
endif
|
||||
|
||||
if !exists(g:go_oracle_scope)
|
||||
if !exists('g:go_oracle_scope')
|
||||
echon "vim-go: " | echohl Function | echon "oracle scope is not set"| echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Function | echon "current oracle scope: '". g:go_oracle_scope ."'" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! go#oracle#Tags(...)
|
||||
if a:0
|
||||
if a:0 == 1 && a:1 == '""'
|
||||
unlet g:go_oracle_tags
|
||||
echon "vim-go: " | echohl Function | echon "oracle tags is cleared"| echohl None
|
||||
else
|
||||
let g:go_oracle_tags = a:1
|
||||
echon "vim-go: " | echohl Function | echon "oracle tags changed to: '". g:go_oracle_tags ."'" | echohl None
|
||||
endif
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
if !exists('g:go_oracle_tags')
|
||||
echon "vim-go: " | echohl Function | echon "oracle tags is not set"| echohl None
|
||||
else
|
||||
echon "vim-go: " | echohl Function | echon "current oracle tags: '". g:go_oracle_tags ."'" | echohl None
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Show 'implements' relation for selected package
|
||||
function! go#oracle#Implements(selected)
|
||||
let out = s:RunOracle('implements', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('implements', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Describe selected syntax: definition, methods, etc
|
||||
function! go#oracle#Describe(selected)
|
||||
let out = s:RunOracle('describe', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('describe', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show possible targets of selected function call
|
||||
function! go#oracle#Callees(selected)
|
||||
let out = s:RunOracle('callees', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('callees', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show possible callers of selected function
|
||||
function! go#oracle#Callers(selected)
|
||||
let out = s:RunOracle('callers', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('callers', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show path from callgraph root to selected function
|
||||
function! go#oracle#Callstack(selected)
|
||||
let out = s:RunOracle('callstack', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('callstack', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show free variables of selection
|
||||
function! go#oracle#Freevars(selected)
|
||||
let out = s:RunOracle('freevars', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
" Freevars requires a selection
|
||||
if a:selected == -1
|
||||
echon "vim-go: " | echohl Statement | echon "GoFreevars requires a selection (range) of code "| echohl None
|
||||
return
|
||||
endif
|
||||
|
||||
let out = s:RunOracle('freevars', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show send/receive corresponding to selected channel op
|
||||
function! go#oracle#ChannelPeers(selected)
|
||||
let out = s:RunOracle('peers', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('peers', a:selected, 1)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" Show all refs to entity denoted by selected identifier
|
||||
function! go#oracle#Referrers(selected)
|
||||
let out = s:RunOracle('referrers', a:selected)
|
||||
call s:qflistSecond(out)
|
||||
let out = s:RunOracle('referrers', a:selected, 0)
|
||||
call s:loclistSecond(out)
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
@ -31,17 +31,19 @@ endif
|
||||
function! go#package#Paths()
|
||||
let dirs = []
|
||||
|
||||
if executable('go')
|
||||
let goroot = substitute(system('go env GOROOT'), '\n', '', 'g')
|
||||
if v:shell_error
|
||||
echomsg '''go env GOROOT'' failed'
|
||||
if !exists("s:goroot")
|
||||
if executable('go')
|
||||
let s:goroot = substitute(system('go env GOROOT'), '\n', '', 'g')
|
||||
if v:shell_error
|
||||
echomsg '''go env GOROOT'' failed'
|
||||
endif
|
||||
else
|
||||
let s:goroot = $GOROOT
|
||||
endif
|
||||
else
|
||||
let goroot = $GOROOT
|
||||
endif
|
||||
|
||||
if len(goroot) != 0 && isdirectory(goroot)
|
||||
let dirs += [goroot]
|
||||
if len(s:goroot) != 0 && isdirectory(s:goroot)
|
||||
let dirs += [s:goroot]
|
||||
endif
|
||||
|
||||
let workspaces = split($GOPATH, go#util#PathListSep())
|
||||
@ -66,7 +68,8 @@ function! go#package#ImportPath(arg)
|
||||
return -1
|
||||
endif
|
||||
|
||||
return substitute(path, workspace . '/src/', '', '')
|
||||
let srcdir = substitute(workspace . '/src/', '//', '/', '')
|
||||
return substitute(path, srcdir, '', '')
|
||||
endfunction
|
||||
|
||||
function! go#package#FromPath(arg)
|
||||
|
@ -65,10 +65,10 @@ function! go#path#HasPath(path)
|
||||
return hasA || hasB
|
||||
endfunction
|
||||
|
||||
" Detect returns the current GOPATH. If a package manager is used, such
|
||||
" as Godeps or something like gb (not supported yet), it will modify the
|
||||
" GOPATH so those directories take precedence over the current GOPATH. It also
|
||||
" detects diretories whose are outside GOPATH.
|
||||
" Detect returns the current GOPATH. If a package manager is used, such as
|
||||
" Godeps, GB, it will modify the GOPATH so those directories take precedence
|
||||
" over the current GOPATH. It also detects diretories whose are outside
|
||||
" GOPATH.
|
||||
function! go#path#Detect()
|
||||
let gopath = $GOPATH
|
||||
|
||||
@ -91,7 +91,7 @@ function! go#path#Detect()
|
||||
" gb vendor plugin
|
||||
" (https://github.com/constabulary/gb/tree/master/cmd/gb-vendor)
|
||||
let gb_vendor_root = src_path . "vendor" . go#util#PathSep()
|
||||
if !empty(gb_vendor_root) && !go#path#HasPath(gb_vendor_root)
|
||||
if isdirectory(gb_vendor_root) && !go#path#HasPath(gb_vendor_root)
|
||||
let gopath = gb_vendor_root . go#util#PathListSep() . gopath
|
||||
endif
|
||||
|
||||
|
@ -2,22 +2,32 @@ if !exists("g:go_gorename_bin")
|
||||
let g:go_gorename_bin = "gorename"
|
||||
endif
|
||||
|
||||
function! go#rename#Rename(...)
|
||||
if !exists("g:go_gorename_prefill")
|
||||
let g:go_gorename_prefill = 1
|
||||
endif
|
||||
|
||||
function! go#rename#Rename(bang, ...)
|
||||
let to = ""
|
||||
if a:0 == 0
|
||||
let from = expand("<cword>")
|
||||
let ask = printf("vim-go: rename '%s' to: ", from)
|
||||
let to = input(ask, from)
|
||||
redraw
|
||||
if g:go_gorename_prefill
|
||||
let to = input(ask, from)
|
||||
else
|
||||
let to = input(ask)
|
||||
endif
|
||||
redraw!
|
||||
if empty(to)
|
||||
return
|
||||
endif
|
||||
else
|
||||
let to = a:1
|
||||
endif
|
||||
|
||||
|
||||
"return with a warning if the bin doesn't exist
|
||||
let bin_path = go#path#CheckBinPath(g:go_gorename_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
let bin_path = go#path#CheckBinPath(g:go_gorename_bin)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
let fname = expand('%:p')
|
||||
@ -30,13 +40,28 @@ function! go#rename#Rename(...)
|
||||
" will trigger the 'Hit ENTER to continue' prompt
|
||||
let clean = split(out, '\n')
|
||||
|
||||
let l:listtype = "quickfix"
|
||||
if v:shell_error
|
||||
redraw | echon "vim-go: " | echohl Statement | echon clean[0] | echohl None
|
||||
let errors = go#tool#ParseErrors(split(out, '\n'))
|
||||
call go#list#Populate(l:listtype, errors)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
if !empty(errors) && !a:bang
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
elseif empty(errors)
|
||||
" failed to parse errors, output the original content
|
||||
call go#util#EchoError(out)
|
||||
endif
|
||||
return
|
||||
else
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
redraw | echon "vim-go: " | echohl Function | echon clean[0] | echohl None
|
||||
endif
|
||||
|
||||
" 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
|
||||
|
||||
|
128
sources_non_forked/vim-go/autoload/go/term.vim
Normal file
128
sources_non_forked/vim-go/autoload/go/term.vim
Normal file
@ -0,0 +1,128 @@
|
||||
if has('nvim') && !exists("g:go_term_mode")
|
||||
let g:go_term_mode = 'vsplit'
|
||||
endif
|
||||
|
||||
" s:jobs is a global reference to all jobs started with new()
|
||||
let s:jobs = {}
|
||||
|
||||
" new creates a new terminal with the given command. Mode is set based on the
|
||||
" global variable g:go_term_mode, which is by default set to :vsplit
|
||||
function! go#term#new(bang, cmd)
|
||||
return go#term#newmode(a:bang, a:cmd, g:go_term_mode)
|
||||
endfunction
|
||||
|
||||
" new creates a new terminal with the given command and window mode.
|
||||
function! go#term#newmode(bang, cmd, mode)
|
||||
let mode = a:mode
|
||||
if empty(mode)
|
||||
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 cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let dir = getcwd()
|
||||
|
||||
execute cd . fnameescape(expand("%:p:h"))
|
||||
|
||||
execute mode.' __go_term__'
|
||||
|
||||
setlocal filetype=goterm
|
||||
setlocal bufhidden=delete
|
||||
setlocal winfixheight
|
||||
setlocal noswapfile
|
||||
setlocal nobuflisted
|
||||
|
||||
let job = {
|
||||
\ 'stderr' : [],
|
||||
\ 'stdout' : [],
|
||||
\ 'bang' : a:bang,
|
||||
\ 'on_stdout': function('s:on_stdout'),
|
||||
\ 'on_stderr': function('s:on_stderr'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ }
|
||||
|
||||
let id = termopen(a:cmd, job)
|
||||
|
||||
execute cd . fnameescape(dir)
|
||||
|
||||
" restore back GOPATH
|
||||
let $GOPATH = old_gopath
|
||||
|
||||
let job.id = id
|
||||
startinsert
|
||||
|
||||
" resize new term if needed.
|
||||
let height = get(g:, 'go_term_height', winheight(0))
|
||||
let width = get(g:, 'go_term_width', winwidth(0))
|
||||
|
||||
" we are careful how to resize. for example it's vertical we don't change
|
||||
" the height. The below command resizes the buffer
|
||||
if a:mode == "split"
|
||||
exe 'resize ' . height
|
||||
elseif a:mode == "vertical"
|
||||
exe 'vertical resize ' . width
|
||||
endif
|
||||
|
||||
" we also need to resize the pty, so there you go...
|
||||
call jobresize(id, width, height)
|
||||
|
||||
let s:jobs[id] = job
|
||||
return id
|
||||
endfunction
|
||||
|
||||
function! s:on_stdout(job_id, data)
|
||||
if !has_key(s:jobs, a:job_id)
|
||||
return
|
||||
endif
|
||||
let job = s:jobs[a:job_id]
|
||||
|
||||
call extend(job.stdout, a:data)
|
||||
endfunction
|
||||
|
||||
function! s:on_stderr(job_id, data)
|
||||
if !has_key(s:jobs, a:job_id)
|
||||
return
|
||||
endif
|
||||
let job = s:jobs[a:job_id]
|
||||
|
||||
call extend(job.stderr, a:data)
|
||||
endfunction
|
||||
|
||||
function! s:on_exit(job_id, data)
|
||||
if !has_key(s:jobs, a:job_id)
|
||||
return
|
||||
endif
|
||||
let job = s:jobs[a:job_id]
|
||||
|
||||
let l:listtype = "locationlist"
|
||||
" usually there is always output so never branch into this clause
|
||||
if empty(job.stdout)
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
else
|
||||
let errors = go#tool#ParseErrors(job.stdout)
|
||||
let errors = go#tool#FilterValids(errors)
|
||||
if !empty(errors)
|
||||
" close terminal we don't need it
|
||||
close
|
||||
|
||||
call go#list#Populate(l:listtype, errors)
|
||||
call go#list#Window(l:listtype, len(errors))
|
||||
if !self.bang
|
||||
call go#list#JumpToFirst(l:listtype)
|
||||
endif
|
||||
else
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
unlet s:jobs[a:job_id]
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
@ -40,28 +40,24 @@ function! go#tool#Imports()
|
||||
return imports
|
||||
endfunction
|
||||
|
||||
function! go#tool#ShowErrors(out)
|
||||
" cd into the current files directory. This is important so fnamemodify
|
||||
" does create a full path for outputs when the token is only a single file
|
||||
" name (such as for a go test output, i.e.: 'demo_test.go'). For other
|
||||
" outputs, such as 'go install' we already get an absolute path (i.e.:
|
||||
" '../foo/foo.go') and fnamemodify successfuly creates the full path.
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let current_dir = getcwd()
|
||||
execute cd . fnameescape(expand("%:p:h"))
|
||||
|
||||
function! go#tool#ParseErrors(lines)
|
||||
let errors = []
|
||||
|
||||
for line in split(a:out, '\n')
|
||||
for line in a:lines
|
||||
let fatalerrors = matchlist(line, '^\(fatal error:.*\)$')
|
||||
let tokens = matchlist(line, '^\s*\(.\{-}\):\(\d\+\):\s*\(.*\)')
|
||||
|
||||
if !empty(fatalerrors)
|
||||
call add(errors, {"text": fatalerrors[1]})
|
||||
elseif !empty(tokens)
|
||||
call add(errors, {"filename" : fnamemodify(tokens[1], ':p'),
|
||||
\"lnum": tokens[2],
|
||||
\"text": tokens[3]})
|
||||
" strip endlines of form ^M
|
||||
let out=substitute(tokens[3], '\r$', '', '')
|
||||
|
||||
call add(errors, {
|
||||
\ "filename" : fnamemodify(tokens[1], ':p'),
|
||||
\ "lnum" : tokens[2],
|
||||
\ "text" : out,
|
||||
\ })
|
||||
elseif !empty(errors)
|
||||
" Preserve indented lines.
|
||||
" This comes up especially with multi-line test output.
|
||||
@ -71,18 +67,43 @@ function! go#tool#ShowErrors(out)
|
||||
endif
|
||||
endfor
|
||||
|
||||
" return back to old dir once we are finished with populating the errors
|
||||
execute cd . fnameescape(current_dir)
|
||||
return errors
|
||||
endfunction
|
||||
|
||||
if !empty(errors)
|
||||
call setqflist(errors, 'r')
|
||||
return
|
||||
endif
|
||||
"FilterValids filters the given items with only items that have a valid
|
||||
"filename. Any non valid filename is filtered out.
|
||||
function! go#tool#FilterValids(items)
|
||||
" Remove any nonvalid filename from the location list to avoid opening an
|
||||
" empty buffer. See https://github.com/fatih/vim-go/issues/287 for
|
||||
" details.
|
||||
let filtered = []
|
||||
let is_readable = {}
|
||||
|
||||
if empty(errors)
|
||||
" Couldn't detect error format, output errors
|
||||
echo a:out
|
||||
endif
|
||||
for item in a:items
|
||||
if has_key(item, 'bufnr')
|
||||
let filename = bufname(item.bufnr)
|
||||
elseif has_key(item, 'filename')
|
||||
let filename = item.filename
|
||||
else
|
||||
" nothing to do, add item back to the list
|
||||
call add(filtered, item)
|
||||
continue
|
||||
endif
|
||||
|
||||
if !has_key(is_readable, filename)
|
||||
let is_readable[filename] = filereadable(filename)
|
||||
endif
|
||||
if is_readable[filename]
|
||||
call add(filtered, item)
|
||||
endif
|
||||
endfor
|
||||
|
||||
for k in keys(filter(is_readable, '!v:val'))
|
||||
echo "vim-go: " | echohl Identifier | echon "[run] Dropped " | echohl Constant | echon '"' . k . '"'
|
||||
echohl Identifier | echon " from location list (nonvalid filename)" | echohl None
|
||||
endfor
|
||||
|
||||
return filtered
|
||||
endfunction
|
||||
|
||||
function! go#tool#ExecuteInDir(cmd) abort
|
||||
|
@ -1,51 +1,101 @@
|
||||
" PathSep returns the appropriate OS specific path separator.
|
||||
function! go#util#PathSep()
|
||||
if go#util#IsWin()
|
||||
return '\'
|
||||
endif
|
||||
return '/'
|
||||
if go#util#IsWin()
|
||||
return '\'
|
||||
endif
|
||||
return '/'
|
||||
endfunction
|
||||
|
||||
" PathListSep returns the appropriate OS specific path list separator.
|
||||
function! go#util#PathListSep()
|
||||
if go#util#IsWin()
|
||||
return ";"
|
||||
endif
|
||||
return ":"
|
||||
if go#util#IsWin()
|
||||
return ";"
|
||||
endif
|
||||
return ":"
|
||||
endfunction
|
||||
|
||||
" LineEnding returns the correct line ending, based on the current fileformat
|
||||
function! go#util#LineEnding()
|
||||
if &fileformat == 'dos'
|
||||
return "\r\n"
|
||||
elseif &fileformat == 'mac'
|
||||
return "\r"
|
||||
endif
|
||||
if &fileformat == 'dos'
|
||||
return "\r\n"
|
||||
elseif &fileformat == 'mac'
|
||||
return "\r"
|
||||
endif
|
||||
|
||||
return "\n"
|
||||
return "\n"
|
||||
endfunction
|
||||
|
||||
" IsWin returns 1 if current OS is Windows or 0 otherwise
|
||||
function! go#util#IsWin()
|
||||
let win = ['win16', 'win32', 'win32unix', 'win64', 'win95']
|
||||
for w in win
|
||||
if (has(w))
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
let win = ['win16', 'win32', 'win64', 'win95']
|
||||
for w in win
|
||||
if (has(w))
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
return 0
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
" StripPath strips the path's last character if it's a path separator.
|
||||
" example: '/foo/bar/' -> '/foo/bar'
|
||||
function! go#util#StripPathSep(path)
|
||||
let last_char = strlen(a:path) - 1
|
||||
if a:path[last_char] == go#util#PathSep()
|
||||
return strpart(a:path, 0, last_char)
|
||||
endif
|
||||
let last_char = strlen(a:path) - 1
|
||||
if a:path[last_char] == go#util#PathSep()
|
||||
return strpart(a:path, 0, last_char)
|
||||
endif
|
||||
|
||||
return a:path
|
||||
return a:path
|
||||
endfunction
|
||||
|
||||
" Shelljoin returns a shell-safe string representation of arglist. The
|
||||
" {special} argument of shellescape() may optionally be passed.
|
||||
function! go#util#Shelljoin(arglist, ...)
|
||||
try
|
||||
let ssl_save = &shellslash
|
||||
set noshellslash
|
||||
if a:0
|
||||
return join(map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')'), ' ')
|
||||
endif
|
||||
|
||||
return join(map(copy(a:arglist), 'shellescape(v:val)'), ' ')
|
||||
finally
|
||||
let &shellslash = ssl_save
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" Shelllist returns a shell-safe representation of the items in the given
|
||||
" arglist. The {special} argument of shellescape() may optionally be passed.
|
||||
function! go#util#Shelllist(arglist, ...)
|
||||
try
|
||||
let ssl_save = &shellslash
|
||||
set noshellslash
|
||||
if a:0
|
||||
return map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')')
|
||||
endif
|
||||
return map(copy(a:arglist), 'shellescape(v:val)')
|
||||
finally
|
||||
let &shellslash = ssl_save
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" TODO(arslan): I couldn't parameterize the highlight types. Check if we can
|
||||
" simplify the following functions
|
||||
|
||||
function! go#util#EchoSuccess(msg)
|
||||
redraws! | echon "vim-go: " | echohl Function | echon a:msg | echohl None
|
||||
endfunction
|
||||
|
||||
function! go#util#EchoError(msg)
|
||||
redraws! | echon "vim-go: " | echohl ErrorMsg | echon a:msg | echohl None
|
||||
endfunction
|
||||
|
||||
function! go#util#EchoWarning(msg)
|
||||
redraws! | echon "vim-go: " | echohl WarningMsg | echon a:msg | echohl None
|
||||
endfunction
|
||||
|
||||
function! go#util#EchoProgress(msg)
|
||||
redraws! | echon "vim-go: " | echohl Identifier | echon a:msg | echohl None
|
||||
endfunction
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
|
Reference in New Issue
Block a user