mirror of
				https://github.com/amix/vimrc
				synced 2025-10-31 06:33:35 +08:00 
			
		
		
		
	Updated plugins
This commit is contained in:
		| @ -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 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 amix
					amix