mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated plugins
This commit is contained in:
27
sources_non_forked/vim-go/CHANGELOG.md
Normal file
27
sources_non_forked/vim-go/CHANGELOG.md
Normal file
@ -0,0 +1,27 @@
|
||||
## 1.6 (unreleased)
|
||||
|
||||
FEATURES:
|
||||
|
||||
* New `CHANGELOG.md` file (which you're reading now). This will make it easier
|
||||
for me to track changes and release versions
|
||||
* **`:GoCoverage`**: is now highlighting the current source file for
|
||||
covered/uncovered lines. If called again it clears the highlighting. This is
|
||||
a pretty good addition to vim-go and I suggest to check out the gif that shows
|
||||
it in action: https://twitter.com/fatih/status/716722650383564800 [gh-786]
|
||||
* **`:GoCoverageBrowser`**: opens a new annotated HTML page. This is the old
|
||||
`:GoCoverage` behavior [gh-786]
|
||||
* **`GoDoc`**: uses now `[gogetdoc](https://github.com/zmb3/gogetdoc)` to
|
||||
lookup and display the comment documentation for the identifier under the
|
||||
cursor. This is more superior as it support looking up dot imports, named
|
||||
imports and imports where package name and file name are different [gh-782]
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
||||
* **`:GoCoverage`** is now executed async when used within Neovim [gh-686]
|
||||
|
||||
BUG FIXES:
|
||||
|
||||
* Fix not showing documentation for dot, named and package/file name being different imports [gh-332]
|
||||
* Term mode: fix closing location list if result is successful after a failed attempt [gh-768]
|
||||
* Syntax: fix gotexttmpl identifier highlighting [gh-778]
|
||||
|
@ -9,8 +9,6 @@ disabled/enabled easily.
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
* Improved Syntax highlighting with items such as Functions, Operators, Methods.
|
||||
@ -26,8 +24,8 @@ disabled/enabled easily.
|
||||
* Automatic `GOPATH` detection based on the directory structure (i.e. `gb`
|
||||
projects, `godep` vendored projects)
|
||||
* Change or display `GOPATH` with `:GoPath`
|
||||
* Create a coverage profile and display annotated source code in browser to see
|
||||
which functions are covered with `:GoCoverage`
|
||||
* Create a coverage profile and display annotated source code to see which
|
||||
functions are covered with `:GoCoverage`
|
||||
* Call `gometalinter` with `:GoMetaLinter`, which invokes all possible linters
|
||||
(golint, vet, errcheck, deadcode, etc..) and shows the warnings/errors
|
||||
* Lint your code with `:GoLint`
|
||||
@ -45,6 +43,7 @@ disabled/enabled easily.
|
||||
* Tagbar support to show tags of the source code in a sidebar with `gotags`
|
||||
* Custom vim text objects such as `a function` or `inner function`
|
||||
list.
|
||||
* Jump to function or type declarations with `:GoDecls` or `:GoDeclsDir`
|
||||
* A async launcher for the go command is implemented for Neovim, fully async
|
||||
building and testing (beta).
|
||||
* Integrated with the Neovim terminal, launch `:GoRun` and other go commands
|
||||
|
13
sources_non_forked/vim-go/Rakefile
Normal file
13
sources_non_forked/vim-go/Rakefile
Normal file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env rake
|
||||
|
||||
task :ci => [:dump, :test]
|
||||
|
||||
task :dump do
|
||||
sh 'vim --version'
|
||||
end
|
||||
|
||||
# Firstly, `bundle install; bundle install --deployment`
|
||||
# Then, `rake test`
|
||||
task :test do
|
||||
sh 'bundle exec vim-flavor test'
|
||||
end
|
@ -213,11 +213,11 @@ function! go#cmd#Test(bang, compile, ...)
|
||||
|
||||
if has('nvim')
|
||||
if get(g:, 'go_term_enabled', 0)
|
||||
call go#term#new(a:bang, ["go"] + args)
|
||||
let id = go#term#new(a:bang, ["go"] + args)
|
||||
else
|
||||
call go#jobcontrol#Spawn(a:bang, "test", args)
|
||||
let id = go#jobcontrol#Spawn(a:bang, "test", args)
|
||||
endif
|
||||
return
|
||||
return id
|
||||
endif
|
||||
|
||||
call go#cmd#autowrite()
|
||||
@ -290,36 +290,6 @@ function! go#cmd#TestFunc(bang, ...)
|
||||
call call('go#cmd#Test', args)
|
||||
endfunction
|
||||
|
||||
" Coverage creates a new cover profile with 'go test -coverprofile' and opens
|
||||
" a new HTML coverage page from that profile.
|
||||
function! go#cmd#Coverage(bang, ...)
|
||||
let l:tmpname=tempname()
|
||||
|
||||
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
|
||||
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 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
|
||||
|
||||
call delete(l:tmpname)
|
||||
endfunction
|
||||
|
||||
" Generate runs 'go generate' in similar fashion to go#cmd#Build()
|
||||
function! go#cmd#Generate(bang, ...)
|
||||
let default_makeprg = &makeprg
|
||||
|
251
sources_non_forked/vim-go/autoload/go/coverage.vim
Normal file
251
sources_non_forked/vim-go/autoload/go/coverage.vim
Normal file
@ -0,0 +1,251 @@
|
||||
let s:toggle = 0
|
||||
|
||||
" Buffer creates a new cover profile with 'go test -coverprofile' and changes
|
||||
" teh current buffers highlighting to show covered and uncovered sections of
|
||||
" the code. If run again it clears the annotation
|
||||
function! go#coverage#Buffer(bang, ...)
|
||||
if s:toggle
|
||||
call go#coverage#Clear()
|
||||
return
|
||||
endif
|
||||
|
||||
let s:toggle = 1
|
||||
let l:tmpname=tempname()
|
||||
let args = [a:bang, 0, "-coverprofile", l:tmpname]
|
||||
|
||||
if a:0
|
||||
call extend(args, a:000)
|
||||
endif
|
||||
|
||||
let disabled_term = 0
|
||||
if get(g:, 'go_term_enabled')
|
||||
let disabled_term = 1
|
||||
let g:go_term_enabled = 0
|
||||
endif
|
||||
|
||||
let id = call('go#cmd#Test', args)
|
||||
|
||||
if disabled_term
|
||||
let g:go_term_enabled = 1
|
||||
endif
|
||||
|
||||
if has('nvim')
|
||||
call go#jobcontrol#AddHandler(function('s:coverage_handler'))
|
||||
let s:coverage_handler_jobs[id] = l:tmpname
|
||||
return
|
||||
endif
|
||||
|
||||
if !v:shell_error
|
||||
call go#coverage#overlay(l:tmpname)
|
||||
endif
|
||||
|
||||
call delete(l:tmpname)
|
||||
endfunction
|
||||
|
||||
" Clear clears and resets the buffer annotation matches
|
||||
function! go#coverage#Clear()
|
||||
if exists("g:syntax_on") | syntax enable | endif
|
||||
|
||||
if exists("s:toggle") | let s:toggle = 0 | endif
|
||||
|
||||
" remove the autocmd we defined
|
||||
if exists("#BufWinLeave#<buffer>")
|
||||
autocmd! BufWinLeave <buffer>
|
||||
endif
|
||||
|
||||
call clearmatches()
|
||||
endfunction
|
||||
|
||||
" Browser creates a new cover profile with 'go test -coverprofile' and opens
|
||||
" a new HTML coverage page from that profile in a new browser
|
||||
function! go#coverage#Browser(bang, ...)
|
||||
let l:tmpname=tempname()
|
||||
let args = [a:bang, 0, "-coverprofile", l:tmpname]
|
||||
|
||||
if a:0
|
||||
call extend(args, a:000)
|
||||
endif
|
||||
let id = call('go#cmd#Test', args)
|
||||
if has('nvim')
|
||||
call go#jobcontrol#AddHandler(function('s:coverage_browser_handler'))
|
||||
let s:coverage_browser_handler_jobs[id] = l:tmpname
|
||||
return
|
||||
endif
|
||||
if !v:shell_error
|
||||
let openHTML = 'go tool cover -html='.l:tmpname
|
||||
call go#tool#ExecuteInDir(openHTML)
|
||||
endif
|
||||
|
||||
call delete(l:tmpname)
|
||||
endfunction
|
||||
|
||||
" Parses a single line from the cover file generated via go test -coverprofile
|
||||
" and returns a single coverage profile block.
|
||||
function! go#coverage#parsegocoverline(line)
|
||||
" file:startline.col,endline.col numstmt count
|
||||
let mx = '\([^:]\+\):\(\d\+\)\.\(\d\+\),\(\d\+\)\.\(\d\+\)\s\(\d\+\)\s\(\d\+\)'
|
||||
let tokens = matchlist(a:line, mx)
|
||||
let ret = {}
|
||||
let ret.file = tokens[1]
|
||||
let ret.startline = str2nr(tokens[2])
|
||||
let ret.startcol = str2nr(tokens[3])
|
||||
let ret.endline = str2nr(tokens[4])
|
||||
let ret.endcol = str2nr(tokens[5])
|
||||
let ret.numstmt = tokens[6]
|
||||
let ret.cnt = tokens[7]
|
||||
return ret
|
||||
endfunction
|
||||
|
||||
" Generates matches to be added to matchaddpos for the given coverage profile
|
||||
" block
|
||||
function! go#coverage#genmatch(cov)
|
||||
let color = 'covered'
|
||||
if a:cov.cnt == 0
|
||||
let color = 'uncover'
|
||||
endif
|
||||
|
||||
let matches = []
|
||||
|
||||
" if start and end are the same, also specify the byte length
|
||||
" example: foo.go:92.2,92.65 1 0
|
||||
if a:cov.startline == a:cov.endline
|
||||
call add(matches, {
|
||||
\ 'group': color,
|
||||
\ 'pos': [[a:cov.startline, a:cov.startcol, a:cov.endcol - a:cov.startcol]],
|
||||
\ 'priority': 2,
|
||||
\ })
|
||||
return matches
|
||||
endif
|
||||
|
||||
" add start columns. Because we don't know the length of the of
|
||||
" the line, we assume it is at maximum 200 bytes. I know this is hacky,
|
||||
" but that's only way of fixing the issue
|
||||
call add(matches, {
|
||||
\ 'group': color,
|
||||
\ 'pos': [[a:cov.startline, a:cov.startcol, 200]],
|
||||
\ 'priority': 2,
|
||||
\ })
|
||||
|
||||
" and then the remaining lines
|
||||
let start_line = a:cov.startline
|
||||
while start_line < a:cov.endline
|
||||
let start_line += 1
|
||||
call add(matches, {
|
||||
\ 'group': color,
|
||||
\ 'pos': [[start_line]],
|
||||
\ 'priority': 2,
|
||||
\ })
|
||||
endwhile
|
||||
|
||||
" finally end columns
|
||||
call add(matches, {
|
||||
\ 'group': color,
|
||||
\ 'pos': [[a:cov.endline, a:cov.endcol-1]],
|
||||
\ 'priority': 2,
|
||||
\ })
|
||||
|
||||
return matches
|
||||
endfunction
|
||||
|
||||
" Reads the given coverprofile file and annotates the current buffer
|
||||
function! go#coverage#overlay(file)
|
||||
if !filereadable(a:file)
|
||||
return
|
||||
endif
|
||||
let lines = readfile(a:file)
|
||||
|
||||
" cover mode, by default it's 'set'. Just here for debugging purposes
|
||||
let mode = lines[0]
|
||||
|
||||
" contains matches for matchaddpos()
|
||||
let matches = []
|
||||
|
||||
" first mark all lines as normaltext. We use a custom group to not
|
||||
" interfere with other buffers highlightings. Because the priority is
|
||||
" lower than the cover and uncover matches, it'll be overriden.
|
||||
let cnt = 1
|
||||
while cnt <= line('$')
|
||||
call add(matches, {'group': 'normaltext', 'pos': [cnt], 'priority': 1})
|
||||
let cnt += 1
|
||||
endwhile
|
||||
|
||||
let fname = expand('%:t')
|
||||
|
||||
" when called for a _test.go file, run the coverage for the actuall file
|
||||
" file
|
||||
if fname =~# '^\f\+_test\.go$'
|
||||
let l:root = split(fname, '_test.go$')[0]
|
||||
let fname = l:root . ".go"
|
||||
|
||||
if !filereadable(fname)
|
||||
call go#util#EchoError("couldn't find ".fname)
|
||||
return
|
||||
endif
|
||||
|
||||
" open the alternate file to show the coverage
|
||||
exe ":edit ". fnamemodify(fname, ":p")
|
||||
endif
|
||||
|
||||
for line in lines[1:]
|
||||
let cov = go#coverage#parsegocoverline(line)
|
||||
|
||||
" TODO(arslan): for now only include the coverage for the current
|
||||
" buffer
|
||||
if fname != fnamemodify(cov.file, ':t')
|
||||
continue
|
||||
endif
|
||||
|
||||
call extend(matches, go#coverage#genmatch(cov))
|
||||
endfor
|
||||
|
||||
syntax manual
|
||||
highlight normaltext term=bold ctermfg=59 guifg=#75715E
|
||||
highlight covered term=bold ctermfg=118 guifg=#A6E22E
|
||||
highlight uncover term=bold ctermfg=197 guifg=#F92672
|
||||
|
||||
" clear the matches if we leave the buffer
|
||||
autocmd BufWinLeave <buffer> call go#coverage#Clear()
|
||||
|
||||
for m in matches
|
||||
call matchaddpos(m.group, m.pos)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
|
||||
" -----------------------
|
||||
" | Neovim job handlers |
|
||||
" -----------------------
|
||||
|
||||
let s:coverage_handler_jobs = {}
|
||||
let s:coverage_browser_handler_jobs = {}
|
||||
|
||||
function! s:coverage_handler(job, exit_status, data)
|
||||
if !has_key(s:coverage_handler_jobs, a:job.id)
|
||||
return
|
||||
endif
|
||||
let l:tmpname = s:coverage_handler_jobs[a:job.id]
|
||||
if a:exit_status == 0
|
||||
call go#coverage#overlay(l:tmpname)
|
||||
endif
|
||||
|
||||
call delete(l:tmpname)
|
||||
unlet s:coverage_handler_jobs[a:job.id]
|
||||
endfunction
|
||||
|
||||
function! s:coverage_browser_handler(job, exit_status, data)
|
||||
if !has_key(s:coverage_browser_handler_jobs, a:job.id)
|
||||
return
|
||||
endif
|
||||
|
||||
let l:tmpname = s:coverage_browser_handler_jobs[a:job.id]
|
||||
if a:exit_status == 0
|
||||
let openHTML = 'go tool cover -html='.l:tmpname
|
||||
call go#tool#ExecuteInDir(openHTML)
|
||||
endif
|
||||
|
||||
call delete(l:tmpname)
|
||||
unlet s:coverage_browser_handler_jobs[a:job.id]
|
||||
endfunction
|
||||
|
||||
|
||||
" vim:ts=4:sw=4:et
|
@ -29,13 +29,17 @@ function! go#def#Jump(...)
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
|
||||
let command = bin_path . " -f=" . shellescape(fname) . " -i " . shellescape(arg)
|
||||
let command = bin_path . " -t -f=" . shellescape(fname) . " -i " . shellescape(arg)
|
||||
|
||||
" get output of godef
|
||||
let out = s:system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding()))
|
||||
|
||||
" First line is <file>:<line>:<col>
|
||||
" Second line is <identifier><space><type>
|
||||
let godefout=split(out, go#util#LineEnding())
|
||||
|
||||
" jump to it
|
||||
call s:godefJump(out, "")
|
||||
call s:godefJump(godefout, "")
|
||||
let $GOPATH = old_gopath
|
||||
endfunction
|
||||
|
||||
@ -52,12 +56,17 @@ function! go#def#JumpMode(mode)
|
||||
let $GOPATH = go#path#Detect()
|
||||
|
||||
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
|
||||
let command = bin_path . " -f=" . shellescape(fname) . " -i " . shellescape(arg)
|
||||
let command = bin_path . " -t -f=" . shellescape(fname) . " -i " . shellescape(arg)
|
||||
|
||||
" get output of godef
|
||||
let out = s:system(command, join(getbufline(bufnr('%'), 1, '$'), go#util#LineEnding()))
|
||||
|
||||
call s:godefJump(out, a:mode)
|
||||
" First line is <file>:<line>:<col>
|
||||
" Second line is <identifier><space><type>
|
||||
let godefout=split(out, go#util#LineEnding())
|
||||
|
||||
" jump to it
|
||||
call s:godefJump(godefout, a:mode)
|
||||
let $GOPATH = old_gopath
|
||||
endfunction
|
||||
|
||||
@ -71,41 +80,181 @@ function! s:godefJump(out, mode)
|
||||
let old_errorformat = &errorformat
|
||||
let &errorformat = "%f:%l:%c"
|
||||
|
||||
if a:out =~ 'godef: '
|
||||
let out = substitute(a:out, go#util#LineEnding() . '$', '', '')
|
||||
echom out
|
||||
else
|
||||
let parts = split(a:out, ':')
|
||||
" parts[0] contains filename
|
||||
let fileName = parts[0]
|
||||
" Location is the first line of godef output. Ideally in the proper format
|
||||
" but it could also be an error
|
||||
let location = a:out[0]
|
||||
|
||||
" put the error format into location list so we can jump automatically to
|
||||
" it
|
||||
lgetexpr a:out
|
||||
" Echo the godef error if we had one.
|
||||
if location =~ 'godef: '
|
||||
let gderr=substitute(location, go#util#LineEnding() . '$', '', '')
|
||||
call go#util#EchoError(gderr)
|
||||
return
|
||||
endif
|
||||
|
||||
" needed for restoring back user setting this is because there are two
|
||||
" modes of switchbuf which we need based on the split mode
|
||||
let old_switchbuf = &switchbuf
|
||||
let parts = split(a:out[0], ':')
|
||||
|
||||
if a:mode == "tab"
|
||||
let &switchbuf = "usetab"
|
||||
" parts[0] contains filename
|
||||
let fileName = parts[0]
|
||||
|
||||
if bufloaded(fileName) == 0
|
||||
tab split
|
||||
endif
|
||||
else
|
||||
if a:mode == "split"
|
||||
split
|
||||
elseif a:mode == "vsplit"
|
||||
vsplit
|
||||
endif
|
||||
endif
|
||||
" Don't jump if it's the same identifier we just jumped to
|
||||
if len(w:go_stack) > 0 && w:go_stack[w:go_stack_level-1]['ident'] == a:out[1] && w:go_stack[w:go_stack_level-1]['file'] == fileName
|
||||
return
|
||||
endif
|
||||
|
||||
" jump to file now
|
||||
sil ll 1
|
||||
normal! zz
|
||||
" needed for restoring back user setting this is because there are two
|
||||
" modes of switchbuf which we need based on the split mode
|
||||
let old_switchbuf = &switchbuf
|
||||
|
||||
let &switchbuf = old_switchbuf
|
||||
end
|
||||
let &errorformat = old_errorformat
|
||||
if a:mode == "tab"
|
||||
let &switchbuf = "usetab"
|
||||
|
||||
if bufloaded(fileName) == 0
|
||||
tab split
|
||||
endif
|
||||
elseif a:mode == "split"
|
||||
split
|
||||
elseif a:mode == "vsplit"
|
||||
vsplit
|
||||
else
|
||||
" Don't jump in this window if it's been modified
|
||||
if getbufvar(bufnr('%'), "&mod")
|
||||
call go#util#EchoError("No write since last change")
|
||||
return
|
||||
endif
|
||||
endif
|
||||
|
||||
let stack_entry = {'line': line("."), 'col': col("."),
|
||||
\'file': expand('%:p'), 'ident': a:out[1]}
|
||||
|
||||
" jump to file now
|
||||
call s:goToFileLocation(location)
|
||||
"
|
||||
" Remove anything newer than the current position, just like basic
|
||||
" vim tag support
|
||||
if w:go_stack_level == 0
|
||||
let w:go_stack = []
|
||||
else
|
||||
let w:go_stack = w:go_stack[0:w:go_stack_level-1]
|
||||
endif
|
||||
|
||||
" increment the stack counter
|
||||
let w:go_stack_level += 1
|
||||
|
||||
" push it on to the jumpstack
|
||||
call add(w:go_stack, stack_entry)
|
||||
|
||||
let &switchbuf = old_switchbuf
|
||||
endfunction
|
||||
|
||||
function! go#def#StackUI()
|
||||
if len(w:go_stack) == 0
|
||||
call go#util#EchoError("godef stack empty")
|
||||
return
|
||||
endif
|
||||
|
||||
let stackOut = ['" <Up>,<Down>:navigate <Enter>:jump <Esc>,q:exit']
|
||||
|
||||
let i = 0
|
||||
while i < len(w:go_stack)
|
||||
let entry = w:go_stack[i]
|
||||
let prefix = ""
|
||||
if i == w:go_stack_level
|
||||
let prefix = ">"
|
||||
else
|
||||
let prefix = " "
|
||||
endif
|
||||
call add(stackOut, printf("%s %d %s|%d col %d|%s", prefix, i+1, entry["file"], entry["line"], entry["col"], entry["ident"]))
|
||||
let i += 1
|
||||
endwhile
|
||||
if w:go_stack_level == i
|
||||
call add(stackOut, "> ")
|
||||
endif
|
||||
|
||||
call go#ui#OpenWindow("GoDef Stack", stackOut, "godefstack")
|
||||
noremap <buffer> <silent> <CR> :<C-U>call go#def#SelectStackEntry()<CR>
|
||||
noremap <buffer> <silent> <Esc> :<C-U>call go#ui#CloseWindow()<CR>
|
||||
noremap <buffer> <silent> q :<C-U>call go#ui#CloseWindow()<CR>
|
||||
endfunction
|
||||
|
||||
function! go#def#StackPop(...)
|
||||
if len(w:go_stack) == 0
|
||||
call go#util#EchoError("godef stack empty")
|
||||
return
|
||||
endif
|
||||
if w:go_stack_level == 0
|
||||
call go#util#EchoError("at bottom of the godef stack")
|
||||
return
|
||||
endif
|
||||
if !len(a:000)
|
||||
let numPop = 1
|
||||
else
|
||||
let numPop = a:1
|
||||
endif
|
||||
let newLevel = str2nr(w:go_stack_level) - str2nr(numPop)
|
||||
call go#def#StackJump(newLevel + 1)
|
||||
endfunction
|
||||
|
||||
function! go#def#StackJump(...)
|
||||
if len(w:go_stack) == 0
|
||||
call go#util#EchoError("godef stack empty")
|
||||
return
|
||||
endif
|
||||
if !len(a:000)
|
||||
" Display interactive stack
|
||||
call go#def#StackUI()
|
||||
return
|
||||
else
|
||||
let jumpTarget= a:1
|
||||
endif
|
||||
|
||||
if jumpTarget !~ '^\d\+$'
|
||||
if jumpTarget !~ '^\s*$'
|
||||
call go#util#EchoError("location must be a number")
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
let jumpTarget=str2nr(jumpTarget) - 1
|
||||
if jumpTarget >= 0 && jumpTarget < len(w:go_stack)
|
||||
let w:go_stack_level = jumpTarget
|
||||
let target = w:go_stack[w:go_stack_level]
|
||||
|
||||
" jump
|
||||
call s:goToFileLocation(target["file"], target["line"], target["col"])
|
||||
else
|
||||
call go#util#EchoError("invalid godef stack location. Try :GoDefJump to see the list of valid entries")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:goToFileLocation(...)
|
||||
let old_errorformat = &errorformat
|
||||
let &errorformat = "%f:%l:%c"
|
||||
|
||||
" put the error format into location list so we can jump automatically to
|
||||
" it
|
||||
if a:0 == 3
|
||||
lgetexpr printf("%s:%s:%s", a:1, a:2, a:3)
|
||||
elseif a:0 == 1
|
||||
lgetexpr a:1
|
||||
else
|
||||
lgetexpr ""
|
||||
endif
|
||||
|
||||
sil ll 1
|
||||
normal zz
|
||||
|
||||
let &errorformat = old_errorformat
|
||||
endfunction
|
||||
|
||||
function! go#def#SelectStackEntry()
|
||||
let target_window = go#ui#GetReturnWindow()
|
||||
if empty(target_window)
|
||||
let target_window = winnr()
|
||||
endif
|
||||
let highlighted_stack_entry = matchstr(getline("."), '^..\zs\(\d\+\)')
|
||||
if !empty(highlighted_stack_entry)
|
||||
execute target_window . "wincmd w"
|
||||
call go#def#StackJump(str2nr(highlighted_stack_entry))
|
||||
endif
|
||||
call go#ui#CloseWindow()
|
||||
endfunction
|
||||
|
@ -1,22 +1,6 @@
|
||||
" Copyright 2011 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.
|
||||
"
|
||||
" godoc.vim: Vim command to see godoc.
|
||||
"
|
||||
"
|
||||
" Commands:
|
||||
"
|
||||
" :GoDoc
|
||||
"
|
||||
" Open the relevant Godoc for either the word[s] passed to the command or
|
||||
" the, by default, the word under the cursor.
|
||||
"
|
||||
" Options:
|
||||
"
|
||||
" g:go_godoc_commands [default=1]
|
||||
"
|
||||
" Flag to indicate whether to enable the commands listed above.
|
||||
|
||||
let s:buf_nr = -1
|
||||
|
||||
@ -33,10 +17,9 @@ endif
|
||||
" ie: github.com/fatih/set and New
|
||||
function! s:godocWord(args)
|
||||
if !executable('godoc')
|
||||
echohl WarningMsg
|
||||
echo "godoc command not found."
|
||||
echo " install with: go get golang.org/x/tools/cmd/godoc"
|
||||
echohl None
|
||||
let msg = "godoc command not found."
|
||||
let msg .= " install with: go get golang.org/x/tools/cmd/godoc"
|
||||
call go#util#echoWarning(msg)
|
||||
return []
|
||||
endif
|
||||
|
||||
@ -94,47 +77,24 @@ function! go#doc#OpenBrowser(...)
|
||||
endfunction
|
||||
|
||||
function! go#doc#Open(newmode, mode, ...)
|
||||
let pkgs = s:godocWord(a:000)
|
||||
if empty(pkgs)
|
||||
" check if we have 'gogetdoc' and use it automatically
|
||||
let bin_path = go#path#CheckBinPath('gogetdoc')
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
let pkg = pkgs[0]
|
||||
let exported_name = pkgs[1]
|
||||
let offset = go#util#OffsetCursor()
|
||||
let fname = expand("%:p")
|
||||
|
||||
let command = g:go_doc_command . ' ' . g:go_doc_options . ' ' . pkg
|
||||
let command = printf("%s -pos %s:#%s", bin_path, fname, offset)
|
||||
|
||||
silent! let content = system(command)
|
||||
if v:shell_error || s:godocNotFound(content)
|
||||
echo 'No documentation found for "' . pkg . '".'
|
||||
return -1
|
||||
let out = system(command)
|
||||
if v:shell_error != 0
|
||||
call go#util#EchoError(out)
|
||||
return
|
||||
endif
|
||||
|
||||
call s:GodocView(a:newmode, a:mode, content)
|
||||
|
||||
if exported_name == ''
|
||||
silent! normal! gg
|
||||
return -1
|
||||
endif
|
||||
|
||||
" jump to the specified name
|
||||
if search('^func ' . exported_name . '(')
|
||||
silent! normal! zt
|
||||
return -1
|
||||
endif
|
||||
|
||||
if search('^type ' . exported_name)
|
||||
silent! normal! zt
|
||||
return -1
|
||||
endif
|
||||
|
||||
if search('^\%(const\|var\|type\|\s\+\) ' . pkg . '\s\+=\s')
|
||||
silent! normal! zt
|
||||
return -1
|
||||
endif
|
||||
|
||||
" nothing found, jump to top
|
||||
silent! normal! gg
|
||||
call s:GodocView(a:newmode, a:mode, out)
|
||||
endfunction
|
||||
|
||||
function! s:GodocView(newposition, position, content)
|
||||
@ -150,6 +110,15 @@ function! s:GodocView(newposition, position, content)
|
||||
execute bufwinnr(s:buf_nr) . 'wincmd w'
|
||||
endif
|
||||
|
||||
" cap buffer height to 20, but resize it for smaller contents
|
||||
let max_height = 20
|
||||
let content_height = len(split(a:content, "\n"))
|
||||
if content_height > max_height
|
||||
exe 'resize ' . max_height
|
||||
else
|
||||
exe 'resize ' . content_height
|
||||
endif
|
||||
|
||||
setlocal filetype=godoc
|
||||
setlocal bufhidden=delete
|
||||
setlocal buftype=nofile
|
||||
@ -165,7 +134,10 @@ function! s:GodocView(newposition, position, content)
|
||||
call append(0, split(a:content, "\n"))
|
||||
sil $delete _
|
||||
setlocal nomodifiable
|
||||
|
||||
" close easily with <esc> or enter
|
||||
noremap <buffer> <silent> <CR> :<C-U>close<CR>
|
||||
noremap <buffer> <silent> <Esc> :<C-U>close<CR>
|
||||
endfunction
|
||||
|
||||
|
||||
" vim:ts=4:sw=4:et
|
||||
" vim:ts=2:sw=2:et
|
||||
|
@ -127,7 +127,10 @@ function! go#fmt#Format(withGoimport)
|
||||
endif
|
||||
|
||||
if exists('b:goimports_vendor_compatible') && b:goimports_vendor_compatible
|
||||
let command = command . '-srcdir ' . fnameescape(expand("%:p:h"))
|
||||
let ssl_save = &shellslash
|
||||
set noshellslash
|
||||
let command = command . '-srcdir ' . shellescape(expand("%:p:h"))
|
||||
let &shellslash = ssl_save
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -2,6 +2,10 @@
|
||||
" internal function s:spawn
|
||||
let s:jobs = {}
|
||||
|
||||
" s:handlers is a global event handlers for all jobs started with Spawn() or
|
||||
" with the internal function s:spawn
|
||||
let s:handlers = {}
|
||||
|
||||
" 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).
|
||||
@ -36,6 +40,22 @@ function! go#jobcontrol#Statusline() abort
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
" AddHandler adds a on_exit callback handler and returns the id.
|
||||
function! go#jobcontrol#AddHandler(handler)
|
||||
let i = len(s:handlers)
|
||||
while has_key(s:handlers, string(i))
|
||||
let i += 1
|
||||
break
|
||||
endwhile
|
||||
let s:handlers[string(i)] = a:handler
|
||||
return string(i)
|
||||
endfunction
|
||||
|
||||
" RemoveHandler removes a callback handler by id.
|
||||
function! go#jobcontrol#RemoveHandler(id)
|
||||
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
|
||||
@ -95,6 +115,8 @@ endfunction
|
||||
" it'll be closed.
|
||||
function! s:on_exit(job_id, exit_status)
|
||||
let std_combined = self.stderr + self.stdout
|
||||
call s:callback_handlers_on_exit(s:jobs[a:job_id], a:exit_status, std_combined)
|
||||
|
||||
if a:exit_status == 0
|
||||
call go#list#Clean(0)
|
||||
call go#list#Window(0)
|
||||
@ -134,6 +156,17 @@ function! s:on_exit(job_id, exit_status)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" callback_handlers_on_exit runs all handlers for job on exit event.
|
||||
function! s:callback_handlers_on_exit(job, exit_status, data)
|
||||
if empty(s:handlers)
|
||||
return
|
||||
endif
|
||||
|
||||
for s:handler in values(s:handlers)
|
||||
call s:handler(a:job, a:exit_status, a:data)
|
||||
endfor
|
||||
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)
|
||||
|
@ -92,36 +92,46 @@ function! s:on_stderr(job_id, data)
|
||||
call extend(job.stderr, a:data)
|
||||
endfunction
|
||||
|
||||
function! s:on_exit(job_id, data)
|
||||
function! s:on_exit(job_id, exit_status)
|
||||
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
|
||||
|
||||
unlet s:jobs[a:job_id]
|
||||
return
|
||||
endif
|
||||
|
||||
let errors = go#tool#ParseErrors(job.stdout)
|
||||
let errors = go#tool#FilterValids(errors)
|
||||
|
||||
if !empty(errors)
|
||||
" close terminal we don't need it anymore
|
||||
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
|
||||
unlet s:jobs[a:job_id]
|
||||
return
|
||||
endif
|
||||
|
||||
" tests are passing clean the list and close the list. But we only can
|
||||
" close them from a normal view, so jump back, close the list and then
|
||||
" again jump back to the terminal
|
||||
wincmd p
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
wincmd p
|
||||
|
||||
unlet s:jobs[a:job_id]
|
||||
endfunction
|
||||
|
||||
|
@ -1,7 +1,12 @@
|
||||
let s:buf_nr = -1
|
||||
|
||||
"OpenWindow opens a new scratch window and put's the content into the window
|
||||
function! go#ui#OpenWindow(title, content)
|
||||
function! go#ui#OpenWindow(title, content, filetype)
|
||||
" Ensure there's only one return window in this session/tabpage
|
||||
call go#util#Windo("unlet! w:vim_go_return_window")
|
||||
" Mark the window we're leaving as such
|
||||
let w:vim_go_return_window = 1
|
||||
|
||||
" reuse existing buffer window if it exists otherwise create a new one
|
||||
if !bufexists(s:buf_nr)
|
||||
execute 'botright new'
|
||||
@ -14,46 +19,65 @@ function! go#ui#OpenWindow(title, content)
|
||||
execute bufwinnr(s:buf_nr) . 'wincmd w'
|
||||
endif
|
||||
|
||||
" Resize window to content length
|
||||
exe 'resize' . len(a:content)
|
||||
|
||||
" Keep minimum height to 10, if there is more just increase it that it
|
||||
" occupies all results
|
||||
let buffer_height = 10
|
||||
if len(a:content) < buffer_height
|
||||
exe 'resize ' . buffer_height
|
||||
else
|
||||
exe 'resize ' . len(a:content)
|
||||
endif
|
||||
|
||||
" some sane default values for a readonly buffer
|
||||
setlocal filetype=vimgo
|
||||
execute "setlocal filetype=".a:filetype
|
||||
|
||||
" some sane default values for a readonly buffer
|
||||
setlocal bufhidden=delete
|
||||
setlocal buftype=nofile
|
||||
setlocal noswapfile
|
||||
setlocal nobuflisted
|
||||
setlocal winfixheight
|
||||
setlocal cursorline " make it easy to distinguish
|
||||
setlocal nonumber
|
||||
setlocal norelativenumber
|
||||
setlocal showbreak=""
|
||||
|
||||
" we need this to purge the buffer content
|
||||
setlocal modifiable
|
||||
|
||||
"delete everything first from the buffer
|
||||
%delete _
|
||||
%delete _
|
||||
|
||||
" add the content
|
||||
call append(0, a:content)
|
||||
|
||||
" delete last line that comes from the append call
|
||||
$delete _
|
||||
$delete _
|
||||
|
||||
" set it back to non modifiable
|
||||
setlocal nomodifiable
|
||||
|
||||
" Remove the '... [New File]' message line from the command line
|
||||
echon
|
||||
endfunction
|
||||
|
||||
function! go#ui#GetReturnWindow()
|
||||
for l:wn in range(1, winnr("$"))
|
||||
if !empty(getwinvar(l:wn, "vim_go_return_window"))
|
||||
return l:wn
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" CloseWindow closes the current window
|
||||
function! go#ui#CloseWindow()
|
||||
close
|
||||
echo ""
|
||||
" Close any window associated with the ui buffer, if it's there
|
||||
if bufexists(s:buf_nr)
|
||||
let ui_window_number = bufwinnr(s:buf_nr)
|
||||
if ui_window_number != -1
|
||||
execute ui_window_number . 'close'
|
||||
endif
|
||||
endif
|
||||
|
||||
"return to original window, if it's there
|
||||
let l:rw = go#ui#GetReturnWindow()
|
||||
if !empty(l:rw)
|
||||
execute l:rw . 'wincmd w'
|
||||
unlet! w:vim_go_return_window
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" OpenDefinition parses the current line and jumps to it by openening a new
|
||||
@ -64,7 +88,7 @@ function! go#ui#OpenDefinition(filter)
|
||||
" don't touch our first line or any blank line
|
||||
if curline =~ a:filter || curline =~ "^$"
|
||||
" supress information about calling this function
|
||||
echo ""
|
||||
echo ""
|
||||
return
|
||||
endif
|
||||
|
||||
@ -83,7 +107,7 @@ function! go#ui#OpenDefinition(filter)
|
||||
tab split
|
||||
ll 1
|
||||
|
||||
" center the word
|
||||
norm! zz
|
||||
" center the word
|
||||
norm! zz
|
||||
endfunction
|
||||
|
||||
|
@ -101,6 +101,18 @@ function! go#util#OffsetCursor()
|
||||
return go#util#Offset(line('.'), col('.'))
|
||||
endfunction
|
||||
|
||||
" Windo is like the built-in :windo, only it returns to the window the command
|
||||
" was issued from
|
||||
function! go#util#Windo(command)
|
||||
let s:currentWindow = winnr()
|
||||
try
|
||||
execute "windo " . a:command
|
||||
finally
|
||||
execute s:currentWindow. "wincmd w"
|
||||
unlet s:currentWindow
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
" TODO(arslan): I couldn't parameterize the highlight types. Check if we can
|
||||
" simplify the following functions
|
||||
|
||||
|
@ -47,7 +47,7 @@ easily.
|
||||
* Automatic `GOPATH` detection based on the directory structure (i.e. `gb`
|
||||
projects, `godep` vendored projects)
|
||||
* Change or display `GOPATH` with `:GoPath`
|
||||
* Create a coverage profile and display annotated source code in browser to see
|
||||
* Create a coverage profile and display annotated source code in to see
|
||||
which functions are covered with `:GoCoverage`
|
||||
* Call `gometalinter` with `:GoMetaLinter`, which invokes all possible linters
|
||||
(golint, vet, errcheck, deadcode, etc..) and shows the warnings/errors
|
||||
@ -211,11 +211,62 @@ COMMANDS *go-commands*
|
||||
|
||||
*:GoDef*
|
||||
:GoDef [identifier]
|
||||
gd
|
||||
CTRL-]
|
||||
|
||||
Goto declaration/definition for the given [identifier]. If no argument is
|
||||
given, it will jump to the declaration under the cursor. By default the
|
||||
mapping `gd` is enabled to invoke GoDef for the identifier under the cursor.
|
||||
See |g:go_def_mapping_enabled| to disable it.
|
||||
CTRL-] key and the mapping `gd` are enabled to invoke :GoDef for the
|
||||
identifier under the cursor. See |g:go_def_mapping_enabled| to disable them.
|
||||
|
||||
vim-go also keeps a per-window location stack, roughly analagous to how
|
||||
vim's internal |tags| functionality works. This is pushed to every time a
|
||||
jump is made using the GoDef functionality. In essence, this is a LIFO list
|
||||
of file locations you have visited with :GoDef that is retained to help you
|
||||
navigate software. For more information on displaying the stack, see
|
||||
|:GoDefJump|
|
||||
|
||||
*:GoDefJump*
|
||||
:GoDefJump [number]
|
||||
|
||||
This command Jumps to a given location in the jumpstack, retaining all other
|
||||
entries. Jumps to non-existent entries will print an informative message,
|
||||
but are otherwise a noop.
|
||||
|
||||
If no argument is given, it will print out an interactive list of all items
|
||||
in the stack. Its output looks like this:
|
||||
|
||||
1 /path/to/first/file.go|1187 col 16|AddThing func(t *Thing)
|
||||
> 2 /path/to/thing/thing.go|624 col 19|String() string
|
||||
3 /path/to/thing/thing.go|744 col 6|func Sprintln(a ...interface{}) string
|
||||
|
||||
This list shows the identifiers that you jumped to and the file and cursor
|
||||
position before that jump. The older jumps are at the top, the newer at the
|
||||
bottom.
|
||||
|
||||
The '>' points to the active entry. This entry and any newer entries below
|
||||
it will be replaced if |:GoDef| is done from this location. The CTRL-t and
|
||||
|:GoDefPop| command will jump to the position above the active entry.
|
||||
|
||||
Jumps to non-existent entries will print an informative message, but are
|
||||
otherwise a noop.
|
||||
|
||||
*:GoDefPop*
|
||||
:GoDefPop [count]
|
||||
CTRL-t
|
||||
|
||||
Navigate to the [count] earlier entry in the jump stack, retaining the newer
|
||||
entries. If no argument is given, it will jump to the next most recent entry
|
||||
(`:GoDefPop 1`). If [count] is greater than the number of prior entries,
|
||||
an error will be printed and no jump will be performed.
|
||||
|
||||
If you have used :GoDefPop to jump to an earlier location, and you issue
|
||||
another :GoDef command, the current entry will be replaced, and all newer
|
||||
entries will be removed, effectively resuming the stack at that location.
|
||||
|
||||
By default [count]CTRL-t is enabled to invoke :GoDefPop. Similarly, hitting
|
||||
CTRL-t without a prior count is equivalent to `:GoDefPop 1`. See
|
||||
|g:go_def_mapping_enabled| to disable this.
|
||||
|
||||
*:GoRun*
|
||||
:GoRun[!] [expand]
|
||||
@ -323,13 +374,22 @@ COMMANDS *go-commands*
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
If using neovim `:GoTestCompile` will run in a new terminal or run asynchronously
|
||||
in the background according to |g:go_term_enabled|. You can set the mode of
|
||||
the new terminal with |g:go_term_mode|.
|
||||
If using neovim `:GoTestCompile` will run in a new terminal or run
|
||||
asynchronously in the background according to |g:go_term_enabled|. You can
|
||||
set the mode of the new terminal with |g:go_term_mode|.
|
||||
|
||||
*:GoCoverage*
|
||||
:GoCoverage[!] [options]
|
||||
|
||||
Create a coverage profile and annotates the current file's source code. If
|
||||
called again clears the annotation (works as a toggle)
|
||||
|
||||
If [!] is not given the first error is jumped to.
|
||||
|
||||
|
||||
*:GoCoverageBrowser*
|
||||
:GoCoverageBrowser[!] [options]
|
||||
|
||||
Create a coverage profile and open a browser to display the annotated
|
||||
source code of the current package.
|
||||
|
||||
@ -846,8 +906,9 @@ In Go, using `godoc` is more idiomatic. Default is enabled. >
|
||||
<
|
||||
*'g:go_def_mapping_enabled'*
|
||||
|
||||
Use this option to enable/disable the default mapping of (`gd`) for GoDef.
|
||||
Disabling it allows you to map something else to `gd`. Default is enabled. >
|
||||
Use this option to enable/disable the default mapping of CTRL-] and (`gd`) for
|
||||
GoDef and CTRL-t for :GoDefPop. Disabling it allows you to map something else to
|
||||
these keys or mappings. Default is enabled. >
|
||||
|
||||
let g:go_def_mapping_enabled = 1
|
||||
<
|
||||
@ -980,7 +1041,13 @@ also enabled. By default it's enabled. >
|
||||
|
||||
let g:go_highlight_string_spellcheck = 1
|
||||
<
|
||||
*'g:go_highlight_format_strings*
|
||||
|
||||
Use this option to highlight printf-style operators inside string literals.
|
||||
By default it's enabled. >
|
||||
|
||||
let g:go_highlight_format_strings = 1
|
||||
<
|
||||
*'g:go_autodetect_gopath'*
|
||||
|
||||
Automatically modifies GOPATH for certain directory structures, such as for
|
||||
|
@ -29,7 +29,9 @@ if get(g:, "go_doc_keywordprg_enabled", 1)
|
||||
endif
|
||||
|
||||
if get(g:, "go_def_mapping_enabled", 1)
|
||||
nnoremap <buffer> <silent> gd :GoDef<cr>
|
||||
nnoremap <buffer> <silent> gd :GoDef<cr>
|
||||
nnoremap <buffer> <silent> <C-]> :GoDef<cr>
|
||||
nnoremap <buffer> <silent> <C-t> :<C-U>call go#def#StackPop(v:count1)<cr>
|
||||
endif
|
||||
|
||||
if get(g:, "go_textobj_enabled", 1)
|
||||
|
@ -26,13 +26,18 @@ command! -nargs=* -bang GoInstall call go#cmd#Install(<bang>0, <f-args>)
|
||||
command! -nargs=* -bang GoTest call go#cmd#Test(<bang>0, 0, <f-args>)
|
||||
command! -nargs=* -bang GoTestFunc call go#cmd#TestFunc(<bang>0, <f-args>)
|
||||
command! -nargs=* -bang GoTestCompile call go#cmd#Test(<bang>0, 1, <f-args>)
|
||||
command! -nargs=* -bang GoCoverage call go#cmd#Coverage(<bang>0, <f-args>)
|
||||
|
||||
" -- cover
|
||||
command! -nargs=* -bang GoCoverage call go#coverage#Buffer(<bang>0, <f-args>)
|
||||
command! -nargs=* -bang GoCoverageBrowser call go#coverage#Browser(<bang>0, <f-args>)
|
||||
|
||||
" -- play
|
||||
command! -nargs=0 -range=% GoPlay call go#play#Share(<count>, <line1>, <line2>)
|
||||
|
||||
" -- def
|
||||
command! -nargs=* -range GoDef :call go#def#Jump(<f-args>)
|
||||
command! -nargs=? GoDefPop :call go#def#StackPop(<f-args>)
|
||||
command! -nargs=? GoDefJump :call go#def#StackJump(<f-args>)
|
||||
|
||||
" -- doc
|
||||
command! -nargs=* -range -complete=customlist,go#package#Complete GoDoc call go#doc#Open('new', 'split', <f-args>)
|
||||
|
@ -23,7 +23,9 @@ nnoremap <silent> <Plug>(go-install) :<C-u>call go#cmd#Install(!g:go_jump_to_err
|
||||
nnoremap <silent> <Plug>(go-test) :<C-u>call go#cmd#Test(!g:go_jump_to_error, 0)<CR>
|
||||
nnoremap <silent> <Plug>(go-test-func) :<C-u>call go#cmd#TestFunc(!g:go_jump_to_error)<CR>
|
||||
nnoremap <silent> <Plug>(go-test-compile) :<C-u>call go#cmd#Test(!g:go_jump_to_error, 1)<CR>
|
||||
nnoremap <silent> <Plug>(go-coverage) :<C-u>call go#cmd#Coverage(!g:go_jump_to_error)<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-coverage) :<C-u>call go#coverage#Buffer(!g:go_jump_to_error)<CR>
|
||||
nnoremap <silent> <Plug>(go-coverage-browser) :<C-u>call go#coverage#Browser(!g:go_jump_to_error)<CR>
|
||||
|
||||
nnoremap <silent> <Plug>(go-files) :<C-u>call go#tool#Files()<CR>
|
||||
nnoremap <silent> <Plug>(go-deps) :<C-u>call go#tool#Deps()<CR>
|
||||
|
@ -19,6 +19,7 @@ let s:packages = [
|
||||
\ "github.com/jstemmer/gotags",
|
||||
\ "github.com/klauspost/asmfmt/cmd/asmfmt",
|
||||
\ "github.com/fatih/motion",
|
||||
\ "github.com/zmb3/gogetdoc",
|
||||
\ ]
|
||||
|
||||
" These commands are available on any filetypes
|
||||
@ -167,6 +168,10 @@ augroup vim-go
|
||||
if get(g:, "go_metalinter_autosave", 0)
|
||||
autocmd BufWritePost *.go call go#lint#Gometa(1)
|
||||
endif
|
||||
|
||||
" initialize window-local godef stack
|
||||
au BufReadPre,WinEnter *.go if !exists('w:go_stack') | let w:go_stack = [] | endif
|
||||
au BufReadPre,WinEnter *.go if !exists('w:go_stack_level') | let w:go_stack_level = 0 | endif
|
||||
augroup END
|
||||
|
||||
|
||||
|
@ -27,6 +27,8 @@
|
||||
" Highlights trailing white space.
|
||||
" - go_highlight_string_spellcheck
|
||||
" Specifies that strings should be spell checked
|
||||
" - go_highlight_format_strings
|
||||
" Highlights printf-style operators inside string literals.
|
||||
|
||||
" Quit when a (custom) syntax file was already loaded
|
||||
if exists("b:current_syntax")
|
||||
@ -81,6 +83,10 @@ if !exists("g:go_highlight_string_spellcheck")
|
||||
let g:go_highlight_string_spellcheck = 1
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_format_strings")
|
||||
let g:go_highlight_format_strings = 1
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_generate_tags")
|
||||
let g:go_highlight_generate_tags = 0
|
||||
endif
|
||||
@ -173,11 +179,14 @@ else
|
||||
syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup
|
||||
syn region goRawString start=+`+ end=+`+
|
||||
endif
|
||||
syn match goFormatSpecifier /%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)*[vTtbcdoqxXUeEfgGsp]/ contained containedin=goString
|
||||
|
||||
if g:go_highlight_format_strings != 0
|
||||
syn match goFormatSpecifier /%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)*[vTtbcdoqxXUeEfgGsp]/ contained containedin=goString
|
||||
hi def link goFormatSpecifier goSpecialString
|
||||
endif
|
||||
|
||||
hi def link goString String
|
||||
hi def link goRawString String
|
||||
hi def link goFormatSpecifier goSpecialString
|
||||
|
||||
" Characters; their contents
|
||||
syn cluster goCharacterGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU
|
||||
|
18
sources_non_forked/vim-go/syntax/godefstack.vim
Normal file
18
sources_non_forked/vim-go/syntax/godefstack.vim
Normal file
@ -0,0 +1,18 @@
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
syn match godefStackComment '^".*'
|
||||
syn match godefLinePrefix '^[>\s]\s' nextgroup=godefStackEntryNumber contains=godefStackCurrentPosition
|
||||
syn match godefStackEntryNumber '\d\+' nextgroup=godefStackFilename skipwhite
|
||||
syn match godefStackCurrentPosition '>' contained
|
||||
syn match godefStackFilename '[^|]\+' contained nextgroup=godefStackEntryLocation
|
||||
syn region godefStackEntryLocation oneline start='|' end='|' contained contains=godefStackEntryLocationNumber
|
||||
syn match godefStackEntryLocationNumber '\d\+' contained display
|
||||
|
||||
let b:current_syntax = "godefstack"
|
||||
|
||||
hi def link godefStackComment Comment
|
||||
hi def link godefStackCurrentPosition Special
|
||||
hi def link godefStackFilename Directory
|
||||
hi def link godefStackEntryLocationNumber LineNr
|
@ -1,47 +0,0 @@
|
||||
" Copyright 2011 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.
|
||||
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
syn case match
|
||||
|
||||
syn match godocTitle "^\([A-Z][A-Z ]*\)$"
|
||||
hi def link godocTitle Title
|
||||
|
||||
" Single Line Definitions
|
||||
syn match godocMethodRec /\i\+\ze)/ contained
|
||||
syn match godocMethodName /) \zs\i\+\ze(/ contained
|
||||
syn match godocMethod /^func \((\i\+ [^)]*)\) \i\+(/ contains=godocMethodRec,godocMethodName
|
||||
syn match godocFunction /^func \zs\i\+\ze(/
|
||||
|
||||
syn match godocType /^type \zs\i\+\ze.*/
|
||||
syn match godocVar /^var \zs\i\+\ze.*/
|
||||
syn match godocConst /^const \zs\i\+\ze.*/
|
||||
|
||||
hi def link godocMethodRec Type
|
||||
hi def link godocType Type
|
||||
hi def link godocMethodName Function
|
||||
hi def link godocFunction Function
|
||||
hi def link godocVar Identifier
|
||||
hi def link godocConst Identifier
|
||||
|
||||
" Definition Blocks
|
||||
syn region godocComment start="/\*" end="\*/" contained
|
||||
syn region godocComment start="//" end="$" contained
|
||||
syn match godocDefinition /^\s\+\i\+/ contained
|
||||
|
||||
syn region godocVarBlock start=/^var (/ end=/^)/ contains=godocComment,godocDefinition
|
||||
syn region godocConstBlock start=/^const (/ end=/^)/ contains=godocComment,godocDefinition
|
||||
syn region godocTypeBlock start=/^type \i\+ \(interface\|struct\) {/ end=/^}/ matchgroup=godocType contains=godocComment,godocType
|
||||
|
||||
hi def link godocComment Comment
|
||||
hi def link godocDefinition Identifier
|
||||
|
||||
syn sync minlines=500
|
||||
|
||||
let b:current_syntax = "godoc"
|
||||
|
||||
" vim:ts=4 sts=2 sw=2:
|
191
sources_non_forked/vim-go/t/coverlay.vim
Normal file
191
sources_non_forked/vim-go/t/coverlay.vim
Normal file
@ -0,0 +1,191 @@
|
||||
" to execute, `rake test` on parent dir
|
||||
|
||||
describe 'go#coverage#Buffer'
|
||||
before
|
||||
new
|
||||
let g:curdir = expand('<sfile>:p:h') . '/'
|
||||
let g:srcpath = 't/fixtures/src/'
|
||||
let g:sample = 'pkg1/sample.go'
|
||||
let g:sampleabs = g:curdir . g:srcpath . 'pkg1/sample.go'
|
||||
let g:samplecover = g:curdir . g:srcpath . 'pkg1/sample.out'
|
||||
let g:go_gopath = g:curdir . 't/fixtures'
|
||||
execute "badd " . g:srcpath . g:sample
|
||||
execute "buffer " . bufnr("$")
|
||||
end
|
||||
after
|
||||
execute "bprev"
|
||||
execute "bdelete " . g:srcpath . g:sample
|
||||
close!
|
||||
end
|
||||
|
||||
it 'puts match to the list'
|
||||
call go#coverage#Buffer(0)
|
||||
Expect len(go#coverlay#matches()) == 5
|
||||
call go#coverlay#Clearlay()
|
||||
Expect len(go#coverlay#matches()) == 0
|
||||
|
||||
call go#coverage#Buffer(0)
|
||||
Expect len(go#coverlay#matches()) == 5
|
||||
call go#coverlay#Clearlay()
|
||||
Expect len(go#coverlay#matches()) == 0
|
||||
|
||||
call go#coverage#Buffer(0)
|
||||
Expect len(go#coverlay#matches()) == 5
|
||||
call go#coverage#Buffer(0)
|
||||
Expect len(go#coverlay#matches()) == 5
|
||||
call go#coverlay#Clearlay()
|
||||
Expect len(go#coverlay#matches()) == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe 'go#coverage#Buffer fail'
|
||||
before
|
||||
new
|
||||
let g:curdir = expand('<sfile>:p:h') . '/'
|
||||
let g:srcpath = 't/fixtures/src/'
|
||||
let g:sample = 'failtest/sample.go'
|
||||
let g:sampletest = 'failtest/sample_test.go'
|
||||
let g:sampleabs = g:curdir . g:srcpath . 'failtest/sample.go'
|
||||
let g:go_gopath = g:curdir . 't/fixtures'
|
||||
execute "badd " . g:srcpath . g:sample
|
||||
execute "buffer " . bufnr("$")
|
||||
end
|
||||
after
|
||||
execute "bprev"
|
||||
execute "bdelete " . g:srcpath . g:sampletest
|
||||
execute "bdelete " . g:srcpath . g:sample
|
||||
end
|
||||
|
||||
it 'does nothing if test fail'
|
||||
call go#coverage#Buffer(0)
|
||||
Expect len(go#coverlay#matches()) == 0
|
||||
Expect len(getqflist()) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe 'go#coverage#Buffer build fail'
|
||||
before
|
||||
new
|
||||
let g:curdir = expand('<sfile>:p:h') . '/'
|
||||
let g:srcpath = 't/fixtures/src/'
|
||||
let g:sample = 'buildfail/sample.go'
|
||||
let g:sampleabs = g:curdir . g:srcpath . 'buildfail/sample.go'
|
||||
let g:go_gopath = g:curdir . 't/fixtures'
|
||||
execute "badd " . g:srcpath . g:sample
|
||||
execute "buffer " . bufnr("$")
|
||||
end
|
||||
after
|
||||
execute "bprev"
|
||||
execute "bdelete " . g:srcpath . g:sample
|
||||
end
|
||||
|
||||
it 'does nothing if test fail'
|
||||
call go#coverage#Buffer(0)
|
||||
Expect len(go#coverlay#matches()) == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe 'go#coverage#Buffer build test fail'
|
||||
before
|
||||
new
|
||||
let g:curdir = expand('<sfile>:p:h') . '/'
|
||||
let g:srcpath = 't/fixtures/src/'
|
||||
let g:sample = 'buildtestfail/sample.go'
|
||||
let g:sampleabs = g:curdir . g:srcpath . 'buildtestfail/sample.go'
|
||||
let g:go_gopath = g:curdir . 't/fixtures'
|
||||
execute "badd " . g:srcpath . g:sample
|
||||
execute "buffer " . bufnr("$")
|
||||
end
|
||||
after
|
||||
execute "bprev"
|
||||
execute "bdelete " . g:srcpath . g:sample
|
||||
end
|
||||
|
||||
it 'does nothing if test fail'
|
||||
call go#coverage#Buffer(0)
|
||||
Expect len(go#coverlay#matches()) == 0
|
||||
end
|
||||
end
|
||||
|
||||
describe 'go#coverlay#findbufnr'
|
||||
before
|
||||
new
|
||||
let g:curdir = expand('<sfile>:p:h') . '/'
|
||||
let g:srcpath = 't/fixtures/src/'
|
||||
let g:sample = 'pkg1/sample.go'
|
||||
let g:sample2 = 'pkg2/sample.go'
|
||||
let g:sampleabs = g:curdir . g:srcpath . 'pkg1/sample.go'
|
||||
let g:sampleabs2 = g:curdir . g:srcpath . 'pkg2/sample.go'
|
||||
let g:go_gopath = g:curdir . 't/fixtures'
|
||||
execute "badd " . g:srcpath . g:sample
|
||||
execute "badd " . g:srcpath . g:sample2
|
||||
end
|
||||
after
|
||||
execute "bdelete " . g:srcpath . g:sample2
|
||||
execute "bdelete " . g:srcpath . g:sample
|
||||
close!
|
||||
end
|
||||
|
||||
it 'returns BUFNR if FILE is opened at BUFNR'
|
||||
Expect go#coverlay#findbufnr('_' . g:sampleabs) == bufnr(g:sampleabs)
|
||||
Expect go#coverlay#findbufnr(g:sample) == bufnr(g:sampleabs)
|
||||
|
||||
Expect go#coverlay#findbufnr('_' . g:sampleabs2) == bufnr(g:sampleabs2)
|
||||
Expect go#coverlay#findbufnr(g:sample2) == bufnr(g:sampleabs2)
|
||||
end
|
||||
|
||||
it 'returns -1 if FILE is not exists'
|
||||
Expect go#coverlay#findbufnr('pkg1/NOTEXISTS.go') == -1
|
||||
Expect go#coverlay#findbufnr('_' . g:curdir . g:srcpath . 'pkg1/NOTEXISTS.go') == -1
|
||||
end
|
||||
end
|
||||
|
||||
describe 'go#coverlay#isopenedon'
|
||||
before
|
||||
new
|
||||
let g:curdir = expand('<sfile>:p:h') . '/'
|
||||
let g:srcpath = 't/fixtures/src/'
|
||||
let g:sample = 'pkg1/sample.go'
|
||||
let g:sampleabs = g:curdir . g:srcpath . 'pkg1/sample.go'
|
||||
let g:go_gopath = g:curdir . 't/fixtures'
|
||||
execute "badd " . g:srcpath . g:sample
|
||||
end
|
||||
after
|
||||
execute "bdelete " . g:srcpath . g:sample
|
||||
close!
|
||||
end
|
||||
|
||||
it 'returns 1 if FILE is opened at BUFNR'
|
||||
Expect go#coverlay#isopenedon('_' . g:sampleabs, bufnr(g:sampleabs)) == 1
|
||||
Expect go#coverlay#isopenedon(g:sample, bufnr(g:sampleabs)) == 1
|
||||
end
|
||||
|
||||
it 'returns 0 if FILE is not opened at BUFNR'
|
||||
Expect go#coverlay#isopenedon('_' . g:sampleabs, 42) == 0
|
||||
Expect go#coverlay#isopenedon(g:sample, 42) == 0
|
||||
end
|
||||
|
||||
it 'returns 0 if FILE is not exists'
|
||||
Expect go#coverlay#isopenedon('_' . g:curdir . g:srcpath . 'pkg1/NOTEXISTS', bufnr(g:sampleabs)) == 0
|
||||
Expect go#coverlay#isopenedon('pkg1/NOTEXISTS.go', bufnr(g:sampleabs)) == 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
describe 'go#coverlay#parsegocoverline'
|
||||
it 'parses a go cover output line and returns as dict'
|
||||
let d = {'file': 'f',"startline": "1", "startcol": "2", "endline": "3", "endcol": "4", "numstmt": "5", "cnt": "6"}
|
||||
" file:startline.col,endline.col numstmt count
|
||||
Expect go#coverlay#parsegocoverline("f:1.2,3.4 5 6") == d
|
||||
end
|
||||
end
|
||||
|
||||
describe 'go#coverlay#genmatch'
|
||||
it 'generate mark pattern from cover data'
|
||||
let d = {'file': 'f',"startline": "1", "startcol": "2", "endline": "3", "endcol": "4", "numstmt": "5", "cnt": "6"}
|
||||
Expect go#coverlay#genmatch(d) == {'group': 'covered', "pattern": '\%>1l\_^\s\+\%<3l\|\%1l\_^\s\+\|\%3l\_^\s\+\(\}$\)\@!', "priority": 6}
|
||||
let d = {'file': 'f',"startline": "1", "startcol": "2", "endline": "3", "endcol": "4", "numstmt": "5", "cnt": "0"}
|
||||
Expect go#coverlay#genmatch(d) == {'group': 'uncover', "pattern": '\%>1l\_^\s\+\%<3l\|\%1l\_^\s\+\|\%3l\_^\s\+\(\}$\)\@!', "priority": 5}
|
||||
end
|
||||
end
|
13
sources_non_forked/vim-go/t/fixtures/src/buildfail/sample.go
Normal file
13
sources_non_forked/vim-go/t/fixtures/src/buildfail/sample.go
Normal file
@ -0,0 +1,13 @@
|
||||
// set gopath before
|
||||
//go:generate go test --coverprofile=sample.out
|
||||
// go1.5.3 example output:
|
||||
// GOPATH=`pwd`/fixtures go test --coverprofile=log.out buildfail
|
||||
// # buildfail
|
||||
// /tmp/go-build264733986/buildfail/_test/_obj_test/sample.go:7: undefined: IT_SHOULD_BE_BUILD_FAILED
|
||||
// /tmp/go-build264733986/buildfail/_test/_obj_test/sample.go:8: missing return at end of function
|
||||
// FAIL buildfail [build failed]
|
||||
package pkg
|
||||
|
||||
func Sample() int {
|
||||
IT_SHOULD_BE_BUILD_FAILED
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package pkg
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSample(t *testing.T) {
|
||||
Sample()
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
// set gopath before
|
||||
//go:generate go test --coverprofile=sample.out
|
||||
package pkg
|
||||
|
||||
func Sample() int {
|
||||
return 1
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
// go1.5.3 example output:
|
||||
// GOPATH=`pwd`/fixtures go test --coverprofile=log.out buildtestfail
|
||||
// # buildtestfail
|
||||
// fixtures/src/buildtestfail/sample_test.go:14: undefined: IT_SHOULD_BE_BUILD_FAILED
|
||||
// FAIL buildtestfail [build failed]
|
||||
// echo $?
|
||||
// 2
|
||||
|
||||
package pkg
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSample(t *testing.T) {
|
||||
IT_SHOULD_BE_BUILD_FAILED
|
||||
}
|
12
sources_non_forked/vim-go/t/fixtures/src/failtest/sample.go
Normal file
12
sources_non_forked/vim-go/t/fixtures/src/failtest/sample.go
Normal file
@ -0,0 +1,12 @@
|
||||
// set gopath before
|
||||
//go:generate go test --coverprofile=sample.out
|
||||
package pkg
|
||||
|
||||
func Sample() int {
|
||||
if false {
|
||||
return 0
|
||||
} else if false {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package pkg
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSample(t *testing.T) {
|
||||
Sample()
|
||||
t.Fatal("itwillfail")
|
||||
}
|
14
sources_non_forked/vim-go/t/fixtures/src/parsefail/sample.go
Normal file
14
sources_non_forked/vim-go/t/fixtures/src/parsefail/sample.go
Normal file
@ -0,0 +1,14 @@
|
||||
// set gopath before
|
||||
//go:generate go test --coverprofile=sample.out
|
||||
// go1.5.3 example output:
|
||||
// GOPATH=`pwd`/fixtures go test --coverprofile=log.out parsefail
|
||||
// # cover parsefail
|
||||
// 2016/01/17 23:59:08 cover: /home/sey/vimfiles/_vim/bundle/vim-go-coverlay/t/fixtures/src/parsefail/sample.go: /home/sey/vimfiles/_vim/bundle/vim-go-coverlay/t/fixtures/src/parsefail/sample.go:10:1: expected declaration, found 'IDENT' PARSEFAIL
|
||||
// FAIL parsefail [build failed]
|
||||
// echo $?
|
||||
// 2
|
||||
package pkg
|
||||
|
||||
PARSEFAIL Sample() int {
|
||||
return 0
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package pkg
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSample(t *testing.T) {
|
||||
Sample()
|
||||
}
|
12
sources_non_forked/vim-go/t/fixtures/src/pkg1/sample.go
Normal file
12
sources_non_forked/vim-go/t/fixtures/src/pkg1/sample.go
Normal file
@ -0,0 +1,12 @@
|
||||
// set gopath before
|
||||
//go:generate go test --coverprofile=sample.out
|
||||
package pkg1
|
||||
|
||||
func Sample() int {
|
||||
if false {
|
||||
return 0
|
||||
} else if false {
|
||||
return 0
|
||||
}
|
||||
return 1
|
||||
}
|
6
sources_non_forked/vim-go/t/fixtures/src/pkg1/sample.out
Normal file
6
sources_non_forked/vim-go/t/fixtures/src/pkg1/sample.out
Normal file
@ -0,0 +1,6 @@
|
||||
mode: set
|
||||
pkg1/sample.go:5.19,6.11 1 1
|
||||
pkg1/sample.go:11.2,11.10 1 1
|
||||
pkg1/sample.go:6.11,8.3 1 0
|
||||
pkg1/sample.go:8.3,8.18 1 1
|
||||
pkg1/sample.go:8.18,10.3 1 0
|
@ -0,0 +1,7 @@
|
||||
package pkg1
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSample(t *testing.T) {
|
||||
Sample()
|
||||
}
|
Reference in New Issue
Block a user