mirror of
https://github.com/amix/vimrc
synced 2025-06-16 09:35:01 +08:00
Updated plugins
This commit is contained in:
4
sources_non_forked/vim-go/.gitignore
vendored
4
sources_non_forked/vim-go/.gitignore
vendored
@ -1,2 +1,6 @@
|
||||
doc/tags
|
||||
.DS_Store
|
||||
|
||||
# Test specific files
|
||||
FAILED
|
||||
test.log
|
||||
|
22
sources_non_forked/vim-go/.travis.yml
Normal file
22
sources_non_forked/vim-go/.travis.yml
Normal file
@ -0,0 +1,22 @@
|
||||
language: go
|
||||
|
||||
env:
|
||||
global:
|
||||
- DEPS=$HOME/deps
|
||||
- PATH=$DEPS/bin:$PATH
|
||||
- PATCH="v8.0.0134"
|
||||
|
||||
install: |
|
||||
git config --global user.email "you@example.com"
|
||||
git config --global user.name "Your Name"
|
||||
|
||||
# check out if we can pre-compiled Vim releases somehow,
|
||||
git clone --branch $PATCH --depth 1 https://github.com/vim/vim
|
||||
cd vim
|
||||
./configure --prefix=$DEPS --with-features=huge --disable-gui
|
||||
make
|
||||
make install
|
||||
cd -
|
||||
|
||||
script: ./scripts/test.sh
|
||||
|
@ -1,7 +1,33 @@
|
||||
## 1.11 - Unplanned
|
||||
## unplanned
|
||||
|
||||
FEATURES:
|
||||
|
||||
* Add new `errl` snippet that expands to [gh-1185]:
|
||||
|
||||
```
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
```
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
||||
* Lowercase `<Leader>` in mappings examples for consisten documentation across the README [gh-1192]
|
||||
* All of files should be written in utf-8 if the file will be passed to external command. [gh-1184]
|
||||
|
||||
BUG FIXES:
|
||||
|
||||
* Honor `g:go_echo_command_info` when dispatching builds in neovim [gh-1176]
|
||||
* Fix `:GoBuild` error in neovim due to invalid jobcontrol handler function signatures (`s:on_stdout`, `s:on_stderr`)[gh-1176]
|
||||
* Update statusline before and after `go#jobcontrol#Spawn` command is executed [gh-1176]
|
||||
* Correctly report the value of the 'g:go_guru_tags' variable [gh-1177]
|
||||
* Ensure no trailing `:` exist in GOPATH detection if initial GOPATH is not set [gh-1194]
|
||||
|
||||
## 1.11 - (January 9, 2017)
|
||||
|
||||
FEATURES:
|
||||
|
||||
* Travis test integration has been added. Now any file that is added as `<name>_test.vim` will be automatically tested in for every Pull Request (just like how we add tests to Go with `_test.go`). Going forward this will tremendously increase the stability and decrease the maintaince burden of vim-go. [gh-1157]
|
||||
* Add new `g:go_updatetime` setting to change the default updatetime (which was hardcoded previously) [gh-1055]
|
||||
* Add new `g:go_template_use_pkg` setting to enable to use cwd as package name instead of basic template file [gh-1124]
|
||||
|
||||
@ -9,6 +35,8 @@ IMPROVEMENTS:
|
||||
|
||||
* Add `statusline` support for `:GoMetaLinter` [gh-1120]
|
||||
* Quickfix and Location lists contain now a descriptive title (requires at least Vim `7.4.2200`)[gh-1004]
|
||||
* Check `go env GOPATH` as well for `:GoInstallBinaries` as Go has now a default path for GOPATH ("~/go")starting with 1.8 [gh-1152]
|
||||
* `:GoDocBrowser` now also works on import paths [gh-1174]
|
||||
|
||||
BUG FIXES:
|
||||
|
||||
@ -24,6 +52,22 @@ BUG FIXES:
|
||||
* Fix referencing a non defined variable for async commands when bang (!) was used
|
||||
* Fix `:GoDef` failing for a modified buffer if `hidden` was not set [gh-1132]
|
||||
* Fix `:GoDefStack` to allow popping from jump list when buffer is modified [gh-1133]
|
||||
* Improve internal defining of functions and referencing them for async operations [gh-1155]
|
||||
* Fix `:GoMetaLinter` failing if `go_metalinter_command` is set. [gh-1160]
|
||||
* Fix `:GoMetaLinter`'s `go_metalinter_deadline` setting for async mode [gh-1146]
|
||||
|
||||
BACKWARDS INCOMPATIBILITIES:
|
||||
|
||||
* The following syntax options are now disabled by default. If you're using them be sure to set them in your .vimrc [gh-1167]
|
||||
|
||||
```viml
|
||||
g:go_highlight_array_whitespace_error
|
||||
g:go_highlight_chan_whitespace_error
|
||||
g:go_highlight_extra_types
|
||||
g:go_highlight_space_tab_error
|
||||
g:go_highlight_trailing_whitespace_error
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 1.10 (November 24, 2016)
|
||||
|
7
sources_non_forked/vim-go/Makefile
Normal file
7
sources_non_forked/vim-go/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
all: test
|
||||
|
||||
test:
|
||||
@echo "==> Running tests"
|
||||
@./scripts/test.sh
|
||||
|
||||
.PHONY: all test
|
@ -1,4 +1,4 @@
|
||||
# vim-go
|
||||
# vim-go [](https://travis-ci.org/fatih/vim-go)
|
||||
|
||||
<p align="center">
|
||||
<img style="float: right;" src="assets/vim-go.png" alt="Vim-go logo"/>
|
||||
@ -137,43 +137,43 @@ current buffer. You can also open the definition/declaration, in a new vertical,
|
||||
horizontal, or tab, for the word under your cursor:
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>ds <Plug>(go-def-split)
|
||||
au FileType go nmap <Leader>dv <Plug>(go-def-vertical)
|
||||
au FileType go nmap <Leader>dt <Plug>(go-def-tab)
|
||||
au FileType go nmap <leader>ds <Plug>(go-def-split)
|
||||
au FileType go nmap <leader>dv <Plug>(go-def-vertical)
|
||||
au FileType go nmap <leader>dt <Plug>(go-def-tab)
|
||||
```
|
||||
|
||||
Open the relevant Godoc for the word under the cursor with `<leader>gd` or open
|
||||
it vertically with `<leader>gv`
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>gd <Plug>(go-doc)
|
||||
au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
|
||||
au FileType go nmap <leader>gd <Plug>(go-doc)
|
||||
au FileType go nmap <leader>gv <Plug>(go-doc-vertical)
|
||||
```
|
||||
|
||||
Or open the Godoc in browser
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>gb <Plug>(go-doc-browser)
|
||||
au FileType go nmap <leader>gb <Plug>(go-doc-browser)
|
||||
```
|
||||
|
||||
Show a list of interfaces which is implemented by the type under your cursor
|
||||
with `<leader>s`
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>s <Plug>(go-implements)
|
||||
au FileType go nmap <leader>s <Plug>(go-implements)
|
||||
```
|
||||
|
||||
Show type info for the word under your cursor with `<leader>i` (useful if you
|
||||
have disabled auto showing type info via `g:go_auto_type_info`)
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>i <Plug>(go-info)
|
||||
au FileType go nmap <leader>i <Plug>(go-info)
|
||||
```
|
||||
|
||||
Rename the identifier under the cursor to a new name
|
||||
|
||||
```vim
|
||||
au FileType go nmap <Leader>e <Plug>(go-rename)
|
||||
au FileType go nmap <leader>e <Plug>(go-rename)
|
||||
```
|
||||
|
||||
More `<Plug>` mappings can be seen with `:he go-mappings`. Also these are just
|
||||
@ -245,8 +245,8 @@ Run `:GoRun` in a new tab, horizontal split or vertical split terminal
|
||||
|
||||
```vim
|
||||
au FileType go nmap <leader>rt <Plug>(go-run-tab)
|
||||
au FileType go nmap <Leader>rs <Plug>(go-run-split)
|
||||
au FileType go nmap <Leader>rv <Plug>(go-run-vertical)
|
||||
au FileType go nmap <leader>rs <Plug>(go-run-split)
|
||||
au FileType go nmap <leader>rv <Plug>(go-run-vertical)
|
||||
```
|
||||
|
||||
By default new terminals are opened in a vertical split. To change it
|
||||
@ -288,6 +288,31 @@ information. It includes
|
||||
section](https://github.com/fatih/vim-go/wiki/FAQ-Troubleshooting), and many
|
||||
other [various pieces](https://github.com/fatih/vim-go/wiki) of information.
|
||||
|
||||
## Development & Testing
|
||||
|
||||
vim-go supports now test files. Please check `autoload` folder for examples. If
|
||||
you add a new feature be sure you also include the `_test.vim` file next to the
|
||||
script. Test functions should be starting with `Test_`, example:
|
||||
|
||||
|
||||
```viml
|
||||
function Test_run_fmt()
|
||||
call assert_equal(expected, actual)
|
||||
...
|
||||
endfunction
|
||||
```
|
||||
|
||||
You can locally test it by running:
|
||||
|
||||
```
|
||||
make
|
||||
```
|
||||
|
||||
This will run all tests and print either `PASS` or `FAIL` to indicate the final
|
||||
status of all tests.
|
||||
|
||||
Additionally, each new pull request will trigger a new Travis-ci job.
|
||||
|
||||
## Donation
|
||||
|
||||
People have asked for this for a long time, now you can be a fully supporter by
|
||||
|
@ -1,13 +0,0 @@
|
||||
#!/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
|
@ -25,7 +25,7 @@ function! go#asmfmt#Format() abort
|
||||
|
||||
" Write the current buffer to a tempfile.
|
||||
let l:tmpname = tempname()
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
call writefile(go#util#GetLines(), l:tmpname)
|
||||
|
||||
" Run asmfmt.
|
||||
let path = go#path#CheckBinPath("asmfmt")
|
||||
|
@ -32,8 +32,11 @@ function! go#cmd#Build(bang, ...) abort
|
||||
\})
|
||||
return
|
||||
elseif has('nvim')
|
||||
if get(g:, 'go_echo_command_info', 1)
|
||||
call go#util#EchoProgress("building dispatched ...")
|
||||
endif
|
||||
|
||||
" if we have nvim, call it asynchronously and return early ;)
|
||||
call go#util#EchoProgress("building dispatched ...")
|
||||
call go#jobcontrol#Spawn(a:bang, "build", args)
|
||||
return
|
||||
endif
|
||||
@ -419,7 +422,7 @@ function s:cmd_job(args) abort
|
||||
call go#statusline#Update(status_dir, status)
|
||||
endfunction
|
||||
|
||||
let a:args.error_info_cb = function('s:error_info_cb')
|
||||
let a:args.error_info_cb = funcref('s:error_info_cb')
|
||||
let callbacks = go#job#Spawn(a:args)
|
||||
|
||||
let start_options = {
|
||||
|
@ -1,18 +1,8 @@
|
||||
let s:sock_type = (has('win32') || has('win64')) ? 'tcp' : 'unix'
|
||||
|
||||
function! s:gocodeCurrentBuffer() abort
|
||||
let buf = getline(1, '$')
|
||||
if &encoding != 'utf-8'
|
||||
let buf = map(buf, 'iconv(v:val, &encoding, "utf-8")')
|
||||
endif
|
||||
if &l:fileformat == 'dos'
|
||||
" XXX: line2byte() depend on 'fileformat' option.
|
||||
" so if fileformat is 'dos', 'buf' must include '\r'.
|
||||
let buf = map(buf, 'v:val."\r"')
|
||||
endif
|
||||
let file = tempname()
|
||||
call writefile(buf, file)
|
||||
|
||||
call writefile(go#util#GetLines(), file)
|
||||
return file
|
||||
endfunction
|
||||
|
||||
|
@ -283,7 +283,7 @@ function s:coverage_job(args)
|
||||
call go#statusline#Update(status_dir, status)
|
||||
endfunction
|
||||
|
||||
let a:args.error_info_cb = function('s:error_info_cb')
|
||||
let a:args.error_info_cb = funcref('s:error_info_cb')
|
||||
let callbacks = go#job#Spawn(a:args)
|
||||
|
||||
let start_options = {
|
||||
|
@ -16,7 +16,7 @@ function! go#def#Jump(mode) abort
|
||||
if &modified
|
||||
" Write current unsaved buffer to a temp file and use the modified content
|
||||
let l:tmpname = tempname()
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
call writefile(go#util#GetLines(), l:tmpname)
|
||||
let fname = l:tmpname
|
||||
endif
|
||||
|
||||
@ -41,8 +41,7 @@ function! go#def#Jump(mode) abort
|
||||
let stdin_content = ""
|
||||
|
||||
if &modified
|
||||
let sep = go#util#LineEnding()
|
||||
let content = join(getline(1, '$'), sep)
|
||||
let content = join(go#util#GetLines(), "\n")
|
||||
let stdin_content = fname . "\n" . strlen(content) . "\n" . content
|
||||
call add(cmd, "-modified")
|
||||
endif
|
||||
@ -87,7 +86,7 @@ function! go#def#Jump(mode) abort
|
||||
return
|
||||
endif
|
||||
|
||||
call s:jump_to_declaration(out, a:mode, bin_name)
|
||||
call go#def#jump_to_declaration(out, a:mode, bin_name)
|
||||
let $GOPATH = old_gopath
|
||||
endfunction
|
||||
|
||||
@ -96,10 +95,10 @@ function! s:jump_to_declaration_cb(mode, bin_name, job, exit_status, data) abort
|
||||
return
|
||||
endif
|
||||
|
||||
call s:jump_to_declaration(a:data[0], a:mode, a:bin_name)
|
||||
call go#def#jump_to_declaration(a:data[0], a:mode, a:bin_name)
|
||||
endfunction
|
||||
|
||||
function! s:jump_to_declaration(out, mode, bin_name) abort
|
||||
function! go#def#jump_to_declaration(out, mode, bin_name) abort
|
||||
let final_out = a:out
|
||||
if a:bin_name == "godef"
|
||||
" append the type information to the same line so our we can parse it.
|
||||
@ -299,7 +298,7 @@ function s:def_job(args) abort
|
||||
" do not print anything during async definition search&jump
|
||||
endfunction
|
||||
|
||||
let a:args.error_info_cb = function('s:error_info_cb')
|
||||
let a:args.error_info_cb = funcref('s:error_info_cb')
|
||||
let callbacks = go#job#Spawn(a:args)
|
||||
|
||||
let start_options = {
|
||||
|
32
sources_non_forked/vim-go/autoload/go/def_test.vim
Normal file
32
sources_non_forked/vim-go/autoload/go/def_test.vim
Normal file
@ -0,0 +1,32 @@
|
||||
func Test_jump_to_declaration_guru()
|
||||
let file_name = "test-fixtures/def/jump.go"
|
||||
let lnum = 5
|
||||
let col = 6
|
||||
|
||||
let out = printf("%s:%d:%d: defined here as func main", file_name, lnum, col)
|
||||
let bin_name = "guru"
|
||||
|
||||
call go#def#jump_to_declaration(out, "", bin_name)
|
||||
|
||||
call assert_equal(file_name, bufname("%"))
|
||||
call assert_equal(lnum, getcurpos()[1])
|
||||
call assert_equal(col, getcurpos()[2])
|
||||
endfunc
|
||||
|
||||
func Test_jump_to_declaration_godef()
|
||||
let file_name = "test-fixtures/def/jump.go"
|
||||
let lnum = 5
|
||||
let col = 6
|
||||
|
||||
" note that the output of godef has two lines
|
||||
let out = printf("%s:%d:%d\ndefined here as func main", file_name, lnum, col)
|
||||
let bin_name = "godef"
|
||||
|
||||
call go#def#jump_to_declaration(out, "", bin_name)
|
||||
|
||||
call assert_equal(file_name, bufname("%"))
|
||||
call assert_equal(lnum, getcurpos()[1])
|
||||
call assert_equal(col, getcurpos()[2])
|
||||
endfunc
|
||||
|
||||
" vim: sw=2 ts=2 et
|
@ -31,12 +31,11 @@ function! go#doc#OpenBrowser(...) abort
|
||||
|
||||
let import = out["import"]
|
||||
let name = out["name"]
|
||||
|
||||
" if import is empty, it means we selected a package name
|
||||
if import ==# ""
|
||||
let godoc_url = "https://godoc.org/" . name
|
||||
else
|
||||
let godoc_url = "https://godoc.org/" . import . "#" . name
|
||||
let decl = out["decl"]
|
||||
|
||||
let godoc_url = "https://godoc.org/" . import
|
||||
if decl !~ "^package"
|
||||
let godoc_url .= "#" . name
|
||||
endif
|
||||
|
||||
echo godoc_url
|
||||
@ -153,8 +152,7 @@ function! s:gogetdoc(json) abort
|
||||
" file size followed by newline
|
||||
" file contents
|
||||
let in = ""
|
||||
let sep = go#util#LineEnding()
|
||||
let content = join(getline(1, '$'), sep)
|
||||
let content = join(go#util#GetLines(), "\n")
|
||||
let in = fname . "\n" . strlen(content) . "\n" . content
|
||||
let command .= " -modified"
|
||||
let out = go#util#System(command, in)
|
||||
|
@ -2,26 +2,8 @@
|
||||
" Use of this source code is governed by a BSD-style
|
||||
" license that can be found in the LICENSE file.
|
||||
"
|
||||
" fmt.vim: Vim command to format Go files with gofmt.
|
||||
"
|
||||
" This filetype plugin add a new commands for go buffers:
|
||||
"
|
||||
" :Fmt
|
||||
"
|
||||
" Filter the current Go buffer through gofmt.
|
||||
" It tries to preserve cursor position and avoids
|
||||
" replacing the buffer with stderr output.
|
||||
"
|
||||
" Options:
|
||||
"
|
||||
" g:go_fmt_command [default="gofmt"]
|
||||
"
|
||||
" Flag naming the gofmt executable to use.
|
||||
"
|
||||
" g:go_fmt_autosave [default=1]
|
||||
"
|
||||
" Flag to auto call :Fmt when saved file
|
||||
"
|
||||
" fmt.vim: Vim command to format Go files with gofmt (and gofmt compatible
|
||||
" toorls, such as goimports).
|
||||
|
||||
if !exists("g:go_fmt_command")
|
||||
let g:go_fmt_command = "gofmt"
|
||||
@ -67,6 +49,13 @@ function! go#fmt#Format(withGoimport) abort
|
||||
catch
|
||||
let l:curw = winsaveview()
|
||||
endtry
|
||||
|
||||
" save our undo file to be restored after we are done. This is needed to
|
||||
" prevent an additional undo jump due to BufWritePre auto command and also
|
||||
" restore 'redo' history because it's getting being destroyed every
|
||||
" BufWritePre
|
||||
let tmpundofile = tempname()
|
||||
exe 'wundo! ' . tmpundofile
|
||||
else
|
||||
" Save cursor position and many other things.
|
||||
let l:curw = winsaveview()
|
||||
@ -74,135 +63,32 @@ function! go#fmt#Format(withGoimport) abort
|
||||
|
||||
" 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
|
||||
" prevent an additional undo jump due to BufWritePre auto command and also
|
||||
" restore 'redo' history because it's getting being destroyed every
|
||||
" BufWritePre
|
||||
let tmpundofile = tempname()
|
||||
exe 'wundo! ' . tmpundofile
|
||||
endif
|
||||
|
||||
" get the command first so we can test it
|
||||
let bin_name = g:go_fmt_command
|
||||
if a:withGoimport == 1
|
||||
let bin_name = g:go_goimports_bin
|
||||
endif
|
||||
|
||||
" 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()
|
||||
let bin_path = go#path#CheckBinPath(bin_name)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
if bin_name != "gofmt"
|
||||
" change GOPATH too, so goimports can pick up the correct library
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
endif
|
||||
|
||||
" populate the final command with user based fmt options
|
||||
let command = bin_path . ' -w '
|
||||
if a:withGoimport != 1
|
||||
let command = command . g:go_fmt_options
|
||||
endif
|
||||
|
||||
if bin_name == "goimports"
|
||||
if !exists('b:goimports_vendor_compatible')
|
||||
let out = go#util#System(bin_path . " --help")
|
||||
if out !~ "-srcdir"
|
||||
call go#util#EchoWarning(printf("vim-go: goimports (%s) does not support srcdir. Update with: :GoUpdateBinaries", bin_path))
|
||||
else
|
||||
let b:goimports_vendor_compatible = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
if exists('b:goimports_vendor_compatible') && b:goimports_vendor_compatible
|
||||
let ssl_save = &shellslash
|
||||
set noshellslash
|
||||
let command = command . '-srcdir ' . shellescape(expand("%:p"))
|
||||
let &shellslash = ssl_save
|
||||
endif
|
||||
endif
|
||||
|
||||
" execute our command...
|
||||
call writefile(go#util#GetLines(), l:tmpname)
|
||||
if go#util#IsWin()
|
||||
let l:tmpname = tr(l:tmpname, '\', '/')
|
||||
endif
|
||||
let out = go#util#System(command . " " . l:tmpname)
|
||||
|
||||
if bin_name != "gofmt"
|
||||
let $GOPATH = old_gopath
|
||||
let bin_name = g:go_fmt_command
|
||||
if a:withGoimport == 1
|
||||
let bin_name = g:go_goimports_bin
|
||||
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\+')
|
||||
let out = go#fmt#run(bin_name, l:tmpname, expand('%'))
|
||||
if go#util#ShellError() == 0
|
||||
" remove undo point caused via BufWritePre
|
||||
try | silent undojoin | catch | endtry
|
||||
|
||||
" Replace current file with temp file, then reload buffer
|
||||
let old_fileformat = &fileformat
|
||||
if exists("*getfperm")
|
||||
" save old file permissions
|
||||
let original_fperm = getfperm(expand('%'))
|
||||
endif
|
||||
call rename(l:tmpname, expand('%'))
|
||||
" restore old file permissions
|
||||
if exists("*setfperm") && original_fperm != ''
|
||||
call setfperm(expand('%'), original_fperm)
|
||||
endif
|
||||
silent edit!
|
||||
let &fileformat = old_fileformat
|
||||
let &syntax = &syntax
|
||||
|
||||
" 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
|
||||
call go#fmt#update_file(l:tmpname, expand('%'))
|
||||
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*\(.*\)')
|
||||
if !empty(tokens)
|
||||
call add(errors, {"filename": @%,
|
||||
\"lnum": tokens[2],
|
||||
\"col": tokens[3],
|
||||
\"text": tokens[4]})
|
||||
endif
|
||||
endfor
|
||||
if empty(errors)
|
||||
% | " Couldn't detect gofmt error format, output errors
|
||||
endif
|
||||
if !empty(errors)
|
||||
call go#list#Populate(l:listtype, errors, 'Format')
|
||||
echohl Error | echomsg "Gofmt returned error" | echohl None
|
||||
endif
|
||||
|
||||
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)
|
||||
let errors = s:parse_errors(out)
|
||||
call s:show_errors(errors)
|
||||
endif
|
||||
|
||||
" We didn't use the temp file, so clean up
|
||||
call delete(l:tmpname)
|
||||
|
||||
if g:go_fmt_experimental == 1
|
||||
" restore our undo history
|
||||
silent! exe 'rundo ' . tmpundofile
|
||||
call delete(tmpundofile)
|
||||
endif
|
||||
|
||||
if g:go_fmt_experimental == 1
|
||||
" Restore our cursor/windows positions, folds, etc.
|
||||
if empty(l:curw)
|
||||
silent! loadview
|
||||
@ -215,6 +101,134 @@ function! go#fmt#Format(withGoimport) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" update_file updates the target file with the given formatted source
|
||||
function! go#fmt#update_file(source, target)
|
||||
" remove undo point caused via BufWritePre
|
||||
try | silent undojoin | catch | endtry
|
||||
|
||||
let old_fileformat = &fileformat
|
||||
if exists("*getfperm")
|
||||
" save file permissions
|
||||
let original_fperm = getfperm(a:target)
|
||||
endif
|
||||
|
||||
call rename(a:source, a:target)
|
||||
|
||||
" restore file permissions
|
||||
if exists("*setfperm") && original_fperm != ''
|
||||
call setfperm(a:target , original_fperm)
|
||||
endif
|
||||
|
||||
" reload buffer to reflect latest changes
|
||||
silent! edit!
|
||||
|
||||
let &fileformat = old_fileformat
|
||||
let &syntax = &syntax
|
||||
|
||||
" clean up previous location list
|
||||
let l:listtype = "locationlist"
|
||||
call go#list#Clean(l:listtype)
|
||||
call go#list#Window(l:listtype)
|
||||
endfunction
|
||||
|
||||
" run runs the gofmt/goimport command for the given source file and returns
|
||||
" the the output of the executed command. Target is the real file to be
|
||||
" formated.
|
||||
function! go#fmt#run(bin_name, source, target)
|
||||
let cmd = s:fmt_cmd(a:bin_name, a:source, a:target)
|
||||
if cmd[0] == "goimports"
|
||||
" change GOPATH too, so goimports can pick up the correct library
|
||||
let old_gopath = $GOPATH
|
||||
let $GOPATH = go#path#Detect()
|
||||
endif
|
||||
|
||||
let command = join(cmd, " ")
|
||||
|
||||
" execute our command...
|
||||
let out = go#util#System(command)
|
||||
|
||||
if cmd[0] == "goimports"
|
||||
let $GOPATH = old_gopath
|
||||
endif
|
||||
|
||||
return out
|
||||
endfunction
|
||||
|
||||
" fmt_cmd returns a dict that contains the command to execute gofmt (or
|
||||
" goimports). args is dict with
|
||||
function! s:fmt_cmd(bin_name, source, target)
|
||||
" 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()
|
||||
let bin_path = go#path#CheckBinPath(a:bin_name)
|
||||
if empty(bin_path)
|
||||
return
|
||||
endif
|
||||
|
||||
" start constructing the command
|
||||
let cmd = [bin_path]
|
||||
call add(cmd, "-w")
|
||||
|
||||
if a:bin_name != "goimports"
|
||||
call extend(cmd, split(g:go_fmt_options, " "))
|
||||
else
|
||||
" lazy check if goimports support `-srcdir`. We should eventually remove
|
||||
" this in the future
|
||||
if !exists('b:goimports_vendor_compatible')
|
||||
let out = go#util#System(bin_path . " --help")
|
||||
if out !~ "-srcdir"
|
||||
call go#util#EchoWarning(printf("vim-go: goimports (%s) does not support srcdir. Update with: :GoUpdateBinaries", bin_path))
|
||||
else
|
||||
let b:goimports_vendor_compatible = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
if exists('b:goimports_vendor_compatible') && b:goimports_vendor_compatible
|
||||
let ssl_save = &shellslash
|
||||
set noshellslash
|
||||
call extend(cmd, ["-srcdir", shellescape(fnamemodify(a:target, ":p"))])
|
||||
let &shellslash = ssl_save
|
||||
endif
|
||||
endif
|
||||
|
||||
call add(cmd, a:source)
|
||||
return cmd
|
||||
endfunction
|
||||
|
||||
" parse_errors parses the given errors and returns a list of parsed errors
|
||||
function! s:parse_errors(content) abort
|
||||
let splitted = split(a:content, '\n')
|
||||
|
||||
" list of errors to be put into location list
|
||||
let errors = []
|
||||
for line in splitted
|
||||
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
|
||||
if !empty(tokens)
|
||||
call add(errors,{
|
||||
\"lnum": tokens[2],
|
||||
\"col": tokens[3],
|
||||
\"text": tokens[4],
|
||||
\ })
|
||||
endif
|
||||
endfor
|
||||
|
||||
return errors
|
||||
endfunction
|
||||
|
||||
" show_errors opens a location list and shows the given errors. If the given
|
||||
" errors is empty, it closes the the location list
|
||||
function! s:show_errors(errors) abort
|
||||
let l:listtype = "locationlist"
|
||||
if !empty(a:errors)
|
||||
call go#list#Populate(l:listtype, a:errors, 'Format')
|
||||
echohl Error | echomsg "Gofmt returned error" | echohl None
|
||||
endif
|
||||
|
||||
" this closes the window if there are no errors or it opens
|
||||
" it if there is any
|
||||
call go#list#Window(l:listtype, len(a:errors))
|
||||
endfunction
|
||||
|
||||
function! go#fmt#ToggleFmtAutoSave() abort
|
||||
if get(g:, "go_fmt_autosave", 1)
|
||||
let g:go_fmt_autosave = 0
|
||||
@ -225,4 +239,5 @@ function! go#fmt#ToggleFmtAutoSave() abort
|
||||
let g:go_fmt_autosave = 1
|
||||
call go#util#EchoProgress("auto fmt enabled")
|
||||
endfunction
|
||||
|
||||
" vim: sw=2 ts=2 et
|
||||
|
31
sources_non_forked/vim-go/autoload/go/fmt_test.vim
Normal file
31
sources_non_forked/vim-go/autoload/go/fmt_test.vim
Normal file
@ -0,0 +1,31 @@
|
||||
func Test_run_fmt()
|
||||
let actual_file = tempname()
|
||||
call writefile(readfile("test-fixtures/fmt/hello.go"), actual_file)
|
||||
|
||||
let expected = join(readfile("test-fixtures/fmt/hello_golden.go"), "\n")
|
||||
|
||||
" run our code
|
||||
call go#fmt#run("gofmt", actual_file, "test-fixtures/fmt/hello.go")
|
||||
|
||||
" this should now contain the formatted code
|
||||
let actual = join(readfile(actual_file), "\n")
|
||||
|
||||
call assert_equal(expected, actual)
|
||||
endfunc
|
||||
|
||||
func Test_update_file()
|
||||
let expected = join(readfile("test-fixtures/fmt/hello_golden.go"), "\n")
|
||||
let source_file = tempname()
|
||||
call writefile(readfile("test-fixtures/fmt/hello_golden.go"), source_file)
|
||||
|
||||
let target_file = tempname()
|
||||
call writefile([""], target_file)
|
||||
|
||||
" update_file now
|
||||
call go#fmt#update_file(source_file, target_file)
|
||||
|
||||
" this should now contain the formatted code
|
||||
let actual = join(readfile(target_file), "\n")
|
||||
|
||||
call assert_equal(expected, actual)
|
||||
endfunc
|
@ -1,6 +1,6 @@
|
||||
" guru.vim -- Vim integration for the Go guru.
|
||||
|
||||
" guru_cmd returns a dict that contains the command to execute guru. option
|
||||
" guru_cmd returns a dict that contains the command to execute guru. args
|
||||
" is dict with following options:
|
||||
" mode : guru mode, such as 'implements'
|
||||
" format : output format, either 'plain' or 'json'
|
||||
@ -34,10 +34,8 @@ function! s:guru_cmd(args) range abort
|
||||
let cmd = [bin_path]
|
||||
|
||||
let filename = fnamemodify(expand("%"), ':p:gs?\\?/?')
|
||||
let stdin_content = ""
|
||||
if &modified
|
||||
let sep = go#util#LineEnding()
|
||||
let content = join(getline(1, '$'), sep )
|
||||
let content = join(go#util#GetLines(), "\n")
|
||||
let result.stdin_content = filename . "\n" . strlen(content) . "\n" . content
|
||||
call add(cmd, "-modified")
|
||||
endif
|
||||
@ -127,7 +125,7 @@ function! s:sync_guru(args) abort
|
||||
|
||||
" run, forrest run!!!
|
||||
let command = join(result.cmd, " ")
|
||||
if &modified
|
||||
if has_key(result, 'stdin_content')
|
||||
let out = go#util#System(command, result.stdin_content)
|
||||
else
|
||||
let out = go#util#System(command)
|
||||
@ -198,10 +196,10 @@ function! s:async_guru(args) abort
|
||||
endfunction
|
||||
|
||||
let start_options = {
|
||||
\ 'close_cb': function("s:close_cb"),
|
||||
\ 'close_cb': funcref("s:close_cb"),
|
||||
\ }
|
||||
|
||||
if &modified
|
||||
if has_key(result, 'stdin_content')
|
||||
let l:tmpname = tempname()
|
||||
call writefile(split(result.stdin_content, "\n"), l:tmpname, "b")
|
||||
let l:start_options.in_io = "file"
|
||||
@ -543,7 +541,7 @@ function! go#guru#ClearSameIds() abort
|
||||
endfor
|
||||
|
||||
" remove the autocmds we defined
|
||||
if exists("#BufWinEnter<buffer>")
|
||||
if exists("#BufWinEnter#<buffer>")
|
||||
autocmd! BufWinEnter <buffer>
|
||||
endif
|
||||
endfunction
|
||||
@ -635,7 +633,7 @@ function! go#guru#Tags(...) abort
|
||||
if !exists('g:go_guru_tags')
|
||||
call go#util#EchoSuccess("guru tags is not set")
|
||||
else
|
||||
call go#util#EchoSuccess("current guru tags: ". a:1)
|
||||
call go#util#EchoSuccess("current guru tags: ". g:go_guru_tags)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -38,6 +38,16 @@ endfunction
|
||||
" GOPATH when g:go_autodetect_gopath is enabled. The job is started inside the
|
||||
" current files folder.
|
||||
function! s:spawn(bang, desc, args) abort
|
||||
let status_type = a:args[0]
|
||||
let status_dir = expand('%:p:h')
|
||||
let started_at = reltime()
|
||||
|
||||
call go#statusline#Update(status_dir, {
|
||||
\ 'desc': "current status",
|
||||
\ 'type': status_type,
|
||||
\ 'state': "started",
|
||||
\})
|
||||
|
||||
let job = {
|
||||
\ 'desc': a:desc,
|
||||
\ 'bang': a:bang,
|
||||
@ -49,6 +59,9 @@ function! s:spawn(bang, desc, args) abort
|
||||
\ 'on_stdout': function('s:on_stdout'),
|
||||
\ 'on_stderr': function('s:on_stderr'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ 'status_type' : status_type,
|
||||
\ 'status_dir' : status_dir,
|
||||
\ 'started_at' : started_at,
|
||||
\ }
|
||||
|
||||
" modify GOPATH if needed
|
||||
@ -91,6 +104,23 @@ endfunction
|
||||
" 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, event) dict abort
|
||||
let status = {
|
||||
\ 'desc': 'last status',
|
||||
\ 'type': self.status_type,
|
||||
\ 'state': "success",
|
||||
\ }
|
||||
|
||||
if a:exit_status
|
||||
let status.state = "failed"
|
||||
endif
|
||||
|
||||
let elapsed_time = reltimestr(reltime(self.started_at))
|
||||
" strip whitespace
|
||||
let elapsed_time = substitute(elapsed_time, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
let status.state .= printf(" (%ss)", elapsed_time)
|
||||
|
||||
call go#statusline#Update(self.status_dir, status)
|
||||
|
||||
let std_combined = self.stderr + self.stdout
|
||||
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
@ -105,14 +135,20 @@ function! s:on_exit(job_id, exit_status, event) dict abort
|
||||
call go#list#Window(l:listtype)
|
||||
|
||||
let self.state = "SUCCESS"
|
||||
call go#util#EchoSuccess("SUCCESS")
|
||||
|
||||
if get(g:, 'go_echo_command_info', 1)
|
||||
call go#util#EchoSuccess("[" . self.status_type . "] SUCCESS")
|
||||
endif
|
||||
|
||||
execute cd . fnameescape(dir)
|
||||
return
|
||||
endif
|
||||
|
||||
let self.state = "FAILED"
|
||||
call go#util#EchoError("FAILED")
|
||||
|
||||
if get(g:, 'go_echo_command_info', 1)
|
||||
call go#util#EchoError("[" . self.status_type . "] FAILED")
|
||||
endif
|
||||
|
||||
let errors = go#tool#ParseErrors(std_combined)
|
||||
let errors = go#tool#FilterValids(errors)
|
||||
@ -148,13 +184,13 @@ 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) dict abort
|
||||
function! s:on_stdout(job_id, data, event) dict abort
|
||||
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) dict abort
|
||||
function! s:on_stderr(job_id, data, event) dict abort
|
||||
call extend(self.stderr, a:data)
|
||||
endfunction
|
||||
|
||||
|
@ -10,10 +10,6 @@ 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
|
||||
@ -48,16 +44,33 @@ function! go#lint#Gometa(autosave, ...) abort
|
||||
let cmd += [expand('%:p:h')]
|
||||
else
|
||||
" the user wants something else, let us use it.
|
||||
let cmd += [split(g:go_metalinter_command, " ")]
|
||||
let cmd += split(g:go_metalinter_command, " ")
|
||||
endif
|
||||
|
||||
" gometalinter has a default deadline of 5 seconds.
|
||||
"
|
||||
" For async mode (s:lint_job), we want to override the default deadline only
|
||||
" if we have a deadline configured.
|
||||
"
|
||||
" For sync mode (go#tool#ExecuteInDir), always explicitly pass the 5 seconds
|
||||
" deadline if there is no other deadline configured. If a deadline is
|
||||
" configured, then use it.
|
||||
|
||||
" Call gometalinter asynchronously.
|
||||
if go#util#has_job() && has('lambda')
|
||||
let deadline = get(g:, 'go_metalinter_deadline', 0)
|
||||
if deadline != 0
|
||||
let cmd += ["--deadline=" . deadline]
|
||||
endif
|
||||
|
||||
call s:lint_job({'cmd': cmd})
|
||||
return
|
||||
endif
|
||||
|
||||
" we add deadline only for sync mode
|
||||
let cmd += ["--deadline=" . g:go_metalinter_deadline]
|
||||
" We're calling gometalinter synchronously.
|
||||
|
||||
let cmd += ["--deadline=" . get(g:, 'go_metalinter_deadline', "5s")]
|
||||
|
||||
if a:autosave
|
||||
" include only messages for the active buffer
|
||||
let cmd += ["--include='^" . expand('%:p') . ".*$'"]
|
||||
@ -283,8 +296,8 @@ function s:lint_job(args)
|
||||
endfunction
|
||||
|
||||
let start_options = {
|
||||
\ 'callback': function("s:callback"),
|
||||
\ 'close_cb': function("s:close_cb"),
|
||||
\ 'callback': funcref("s:callback"),
|
||||
\ 'close_cb': funcref("s:close_cb"),
|
||||
\ }
|
||||
|
||||
call job_start(a:args.cmd, start_options)
|
||||
|
@ -110,6 +110,9 @@ function! go#path#Detect() abort
|
||||
endif
|
||||
endif
|
||||
|
||||
" Fix up the case where initial $GOPATH is empty,
|
||||
" and we end up with a trailing :
|
||||
let gopath = substitute(gopath, ":$", "", "")
|
||||
return gopath
|
||||
endfunction
|
||||
|
||||
|
@ -85,8 +85,8 @@ function s:rename_job(args)
|
||||
endfunction
|
||||
|
||||
let start_options = {
|
||||
\ 'callback': function("s:callback"),
|
||||
\ 'close_cb': function("s:close_cb"),
|
||||
\ 'callback': funcref("s:callback"),
|
||||
\ 'close_cb': funcref("s:close_cb"),
|
||||
\ }
|
||||
|
||||
" modify GOPATH if needed
|
||||
|
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("vim-go")
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("vim-go")
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("vim-go")
|
||||
}
|
@ -20,7 +20,7 @@ function! go#textobj#Function(mode) abort
|
||||
if &modified
|
||||
" Write current unsaved buffer to a temp file and use the modified content
|
||||
let l:tmpname = tempname()
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
call writefile(go#util#GetLines(), l:tmpname)
|
||||
let fname = l:tmpname
|
||||
endif
|
||||
|
||||
@ -107,7 +107,7 @@ function! go#textobj#FunctionJump(mode, direction) abort
|
||||
if &modified
|
||||
" Write current unsaved buffer to a temp file and use the modified content
|
||||
let l:tmpname = tempname()
|
||||
call writefile(getline(1, '$'), l:tmpname)
|
||||
call writefile(go#util#GetLines(), l:tmpname)
|
||||
let fname = l:tmpname
|
||||
endif
|
||||
|
||||
|
@ -305,4 +305,17 @@ function! go#util#EchoInfo(msg)
|
||||
redraw | echohl Debug | echom "vim-go: " . a:msg | echohl None
|
||||
endfunction
|
||||
|
||||
function! go#util#GetLines()
|
||||
let buf = getline(1, '$')
|
||||
if &encoding != 'utf-8'
|
||||
let buf = map(buf, 'iconv(v:val, &encoding, "utf-8")')
|
||||
endif
|
||||
if &l:fileformat == 'dos'
|
||||
" XXX: line2byte() depend on 'fileformat' option.
|
||||
" so if fileformat is 'dos', 'buf' must include '\r'.
|
||||
let buf = map(buf, 'v:val."\r"')
|
||||
endif
|
||||
return buf
|
||||
endfunction
|
||||
|
||||
" vim: sw=2 ts=2 et
|
||||
|
@ -1382,8 +1382,7 @@ For example here is how to set each to 30.
|
||||
This option is Neovim only. Use it to change the behavior of the test
|
||||
commands. If set to 1 it opens the test commands inside a new terminal
|
||||
according to |'g:go_term_mode'|, otherwise it will run them in the background
|
||||
just like `:GoBuild` and then display the status with
|
||||
|go#jobcontrol#Statusline()|. By default it is disabled.
|
||||
just like `:GoBuild`. By default it is disabled.
|
||||
>
|
||||
let g:go_term_enabled = 0
|
||||
<
|
||||
|
@ -151,6 +151,14 @@ if err != nil {
|
||||
${0}
|
||||
endsnippet
|
||||
|
||||
# error log snippet
|
||||
snippet errl "Error with log.Fatal(err)" !b
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
${0}
|
||||
endsnippet
|
||||
|
||||
# error multiple return
|
||||
snippet errn, "Error return with two return values" !b
|
||||
if err != nil {
|
||||
|
@ -132,6 +132,13 @@ abbr if err != nil { ... }
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
# error snippet in log.Fatal
|
||||
snippet errl
|
||||
abbr if err != nil { ... }
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
# error snippet with two return values
|
||||
snippet errn,
|
||||
abbr if err != nil { return [...], err }
|
||||
|
@ -32,7 +32,7 @@ command! -nargs=? -complete=dir GoPath call go#path#GoPath(<f-args>)
|
||||
" target install directory. GoInstallBinaries doesn't install binaries if they
|
||||
" exist, to update current binaries pass 1 to the argument.
|
||||
function! s:GoInstallBinaries(updateBinaries)
|
||||
if $GOPATH == ""
|
||||
if $GOPATH == "" && go#util#gopath() == ""
|
||||
echohl Error
|
||||
echomsg "vim.go: $GOPATH is not set"
|
||||
echohl None
|
||||
|
81
sources_non_forked/vim-go/scripts/runtest.vim
Normal file
81
sources_non_forked/vim-go/scripts/runtest.vim
Normal file
@ -0,0 +1,81 @@
|
||||
let total_started = reltime()
|
||||
|
||||
" add vim-go the only plugin inside the runtimepath
|
||||
let git_root_path = system("git rev-parse --show-toplevel | tr -d '\\n'")
|
||||
exe 'set rtp=' . git_root_path
|
||||
|
||||
" source the passed test file
|
||||
source %
|
||||
|
||||
" cd into the folder of the test file
|
||||
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
|
||||
let dir = getcwd()
|
||||
execute cd . expand('%:p:h')
|
||||
|
||||
" initialize variables
|
||||
let g:testname = expand('%')
|
||||
let s:fail = 0
|
||||
let s:done = 0
|
||||
let s:logs = []
|
||||
|
||||
" get a list of all Test_ functions for the given file
|
||||
set nomore
|
||||
redir @q
|
||||
silent function /^Test_
|
||||
redir END
|
||||
let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g'))
|
||||
|
||||
" Iterate over all tests and execute them
|
||||
for s:test in sort(s:tests)
|
||||
let started = reltime()
|
||||
|
||||
call add(s:logs, printf("=== RUN %s", s:test[:-3]))
|
||||
exe 'call ' . s:test
|
||||
|
||||
let elapsed_time = reltimestr(reltime(started))
|
||||
let elapsed_time = substitute(elapsed_time, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
|
||||
let s:done += 1
|
||||
|
||||
if len(v:errors) > 0
|
||||
let s:fail += 1
|
||||
call add(s:logs, printf("--- FAIL: %s (%ss)", s:test[:-3], elapsed_time))
|
||||
call extend(s:logs, map(v:errors, '" ". v:val'))
|
||||
|
||||
" reset so we can capture failures of next test
|
||||
let v:errors = []
|
||||
else
|
||||
call add(s:logs, printf("--- PASS: %s (%ss)", s:test[:-3], elapsed_time))
|
||||
endif
|
||||
endfor
|
||||
|
||||
" pop out into the scripts folder
|
||||
execute cd . fnameescape(dir)
|
||||
|
||||
" create an empty fail to indicate that the test failed
|
||||
if s:fail > 0
|
||||
split FAILED
|
||||
write
|
||||
endif
|
||||
|
||||
let total_elapsed_time = reltimestr(reltime(total_started))
|
||||
let total_elapsed_time = substitute(total_elapsed_time, '^\s*\(.\{-}\)\s*$', '\1', '')
|
||||
|
||||
let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test') . '. Total test time: '. total_elapsed_time .'s'
|
||||
call add(s:logs, "")
|
||||
call add(s:logs, message)
|
||||
|
||||
" store all error messages from within vim into test.log
|
||||
redir > test.log
|
||||
silent messages
|
||||
redir END
|
||||
|
||||
" also store all internal messages from s:logs: as well
|
||||
split test.log
|
||||
call append(line('$'), '')
|
||||
call append(line('$'), 'From ' . g:testname . ':')
|
||||
call append(line('$'), s:logs)
|
||||
write
|
||||
|
||||
" bye, bye!
|
||||
qall!
|
@ -1,77 +1,29 @@
|
||||
#!/bin/bash -e
|
||||
#
|
||||
# Copyright 2012 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.
|
||||
#
|
||||
# Tests for import.vim.
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
cd $(dirname $0)
|
||||
|
||||
cat > base.go <<EOF
|
||||
package test
|
||||
# cleanup test.log
|
||||
if [ -f "test.log" ]; then
|
||||
rm test.log
|
||||
fi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"net"
|
||||
if [ -f "FAILED" ]; then
|
||||
rm FAILED
|
||||
fi
|
||||
|
||||
"mycorp/foo"
|
||||
)
|
||||
EOF
|
||||
for test_file in ../autoload/go/*_test.vim
|
||||
do
|
||||
vim -u NONE -S runtest.vim $test_file
|
||||
done
|
||||
|
||||
fail=0
|
||||
if [ -f "test.log" ]; then
|
||||
cat test.log
|
||||
fi
|
||||
|
||||
# usage: test_one command pattern
|
||||
# Pattern is a PCRE expression that will match across lines.
|
||||
test_one() {
|
||||
echo 2>&1 -n "$1: "
|
||||
vim -e -s -u /dev/null -U /dev/null --noplugin -c "source import.vim" \
|
||||
-c "$1" -c 'wq! test.go' base.go
|
||||
# ensure blank lines are treated correctly
|
||||
if ! gofmt test.go | cmp test.go -; then
|
||||
echo 2>&1 "gofmt conflict"
|
||||
gofmt test.go | diff -u test.go - | sed "s/^/ /" 2>&1
|
||||
fail=1
|
||||
return
|
||||
fi
|
||||
if ! [[ $(cat test.go) =~ $2 ]]; then
|
||||
echo 2>&1 "$2 did not match"
|
||||
cat test.go | sed "s/^/ /" 2>&1
|
||||
fail=1
|
||||
return
|
||||
fi
|
||||
echo 2>&1 "ok"
|
||||
}
|
||||
|
||||
# Tests for Import
|
||||
|
||||
test_one "Import baz" '"baz".*"bytes"'
|
||||
test_one "Import io/ioutil" '"io".*"io/ioutil".*"net"'
|
||||
test_one "Import myc" '"io".*"myc".*"net"' # prefix of a site prefix
|
||||
test_one "Import nat" '"io".*"nat".*"net"'
|
||||
test_one "Import net/http" '"net".*"net/http".*"mycorp/foo"'
|
||||
test_one "Import zoo" '"net".*"zoo".*"mycorp/foo"'
|
||||
test_one "Import mycorp/bar" '"net".*"mycorp/bar".*"mycorp/foo"'
|
||||
test_one "Import mycorp/goo" '"net".*"mycorp/foo".*"mycorp/goo"'
|
||||
|
||||
# Tests for Drop
|
||||
|
||||
cat > base.go <<EOF
|
||||
package test
|
||||
|
||||
import (
|
||||
"foo"
|
||||
|
||||
"something"
|
||||
"zoo"
|
||||
)
|
||||
EOF
|
||||
|
||||
test_one "Drop something" '\([^"]*"foo"[^"]*"zoo"[^"]*\)'
|
||||
|
||||
rm -f base.go test.go
|
||||
if [ $fail -gt 0 ]; then
|
||||
# if Failed exists, test failed
|
||||
if [ -f "FAILED" ]; then
|
||||
echo 2>&1 "FAIL"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -10,9 +10,7 @@
|
||||
" let OPTION_NAME = 0
|
||||
" in your ~/.vimrc file to disable particular options. You can also write:
|
||||
" let OPTION_NAME = 1
|
||||
" to enable particular options.
|
||||
" At present, all options default to on, except highlight of:
|
||||
" functions, methods, structs, operators, build constraints and interfaces.
|
||||
" to enable particular options. At present, all options default to off:
|
||||
"
|
||||
" - go_highlight_array_whitespace_error
|
||||
" Highlights white space after "[]".
|
||||
@ -36,23 +34,23 @@ if exists("b:current_syntax")
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_array_whitespace_error")
|
||||
let g:go_highlight_array_whitespace_error = 1
|
||||
let g:go_highlight_array_whitespace_error = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_chan_whitespace_error")
|
||||
let g:go_highlight_chan_whitespace_error = 1
|
||||
let g:go_highlight_chan_whitespace_error = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_extra_types")
|
||||
let g:go_highlight_extra_types = 1
|
||||
let g:go_highlight_extra_types = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_space_tab_error")
|
||||
let g:go_highlight_space_tab_error = 1
|
||||
let g:go_highlight_space_tab_error = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_trailing_whitespace_error")
|
||||
let g:go_highlight_trailing_whitespace_error = 1
|
||||
let g:go_highlight_trailing_whitespace_error = 0
|
||||
endif
|
||||
|
||||
if !exists("g:go_highlight_operators")
|
||||
|
@ -1,191 +0,0 @@
|
||||
" 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
|
@ -1,13 +0,0 @@
|
||||
// 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
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package pkg
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSample(t *testing.T) {
|
||||
Sample()
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
// set gopath before
|
||||
//go:generate go test --coverprofile=sample.out
|
||||
package pkg
|
||||
|
||||
func Sample() int {
|
||||
return 1
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
// 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
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// 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
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package pkg
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSample(t *testing.T) {
|
||||
Sample()
|
||||
t.Fatal("itwillfail")
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// 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
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package pkg
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSample(t *testing.T) {
|
||||
Sample()
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// 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
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
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
|
@ -1,7 +0,0 @@
|
||||
package pkg1
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSample(t *testing.T) {
|
||||
Sample()
|
||||
}
|
Reference in New Issue
Block a user