From a822b97921c8c1929753ea4239661b08805ab673 Mon Sep 17 00:00:00 2001 From: Alok Singh Date: Wed, 16 Nov 2016 04:44:14 -0800 Subject: [PATCH 1/6] Add abort to every autoload function Used `vint` to go over the codebase and applied the (easy to do) suggestion of adding `abort` to every autoload function. --- autoload/ctrlp/decls.vim | 12 ++++---- autoload/go/alternate.vim | 2 +- autoload/go/asmfmt.vim | 4 +-- autoload/go/cmd.vim | 18 ++++++------ autoload/go/complete.vim | 22 +++++++-------- autoload/go/coverage.vim | 18 ++++++------ autoload/go/def.vim | 14 ++++----- autoload/go/doc.vim | 10 +++---- autoload/go/fmt.vim | 4 +-- autoload/go/guru.vim | 34 +++++++++++----------- autoload/go/impl.vim | 10 +++---- autoload/go/import.vim | 4 +-- autoload/go/jobcontrol.vim | 20 ++++++------- autoload/go/lint.vim | 4 +-- autoload/go/list.vim | 18 ++++++------ autoload/go/package.vim | 10 +++---- autoload/go/path.vim | 12 ++++---- autoload/go/play.vim | 8 +++--- autoload/go/rename.vim | 2 +- autoload/go/template.vim | 4 +-- autoload/go/term.vim | 10 +++---- autoload/go/textobj.vim | 4 +-- autoload/go/tool.vim | 18 ++++++------ autoload/go/ui.vim | 8 +++--- autoload/go/util.vim | 58 +++++++++++++++++++------------------- 25 files changed, 164 insertions(+), 164 deletions(-) diff --git a/autoload/ctrlp/decls.vim b/autoload/ctrlp/decls.vim index 7af2cda70b..e1465adb3b 100644 --- a/autoload/ctrlp/decls.vim +++ b/autoload/ctrlp/decls.vim @@ -14,12 +14,12 @@ else let g:ctrlp_ext_vars = [s:go_decls_var] endif -function! ctrlp#decls#init() +function! ctrlp#decls#init() abort cal s:enable_syntax() return s:decls endfunction -function! ctrlp#decls#exit() +function! ctrlp#decls#exit() abort unlet! s:decls s:current_dir s:target endfunction @@ -28,7 +28,7 @@ endfunction " a:mode the mode that has been chosen by pressing or " the values are 'e', 'v', 't' and 'h', respectively " a:str the selected string -function! ctrlp#decls#accept(mode, str) +function! ctrlp#decls#accept(mode, str) abort let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' let dir = getcwd() try @@ -56,7 +56,7 @@ function! ctrlp#decls#accept(mode, str) endtry endfunction -function! ctrlp#decls#enter() +function! ctrlp#decls#enter() abort let s:current_dir = fnameescape(expand('%:p:h')) let s:decls = [] @@ -130,7 +130,7 @@ function! ctrlp#decls#enter() endfor endfunc -function! s:enable_syntax() +function! s:enable_syntax() abort if !(has('syntax') && exists('g:syntax_on')) return endif @@ -148,7 +148,7 @@ endfunction let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) -function! ctrlp#decls#cmd(mode, ...) +function! ctrlp#decls#cmd(mode, ...) abort let s:mode = a:mode if a:0 && !empty(a:1) let s:target = a:1 diff --git a/autoload/go/alternate.vim b/autoload/go/alternate.vim index dc5643dcf3..f2cb210f3f 100644 --- a/autoload/go/alternate.vim +++ b/autoload/go/alternate.vim @@ -4,7 +4,7 @@ if !exists("g:go_alternate_mode") endif " Test alternates between the implementation of code and the test code. -function! go#alternate#Switch(bang, cmd) +function! go#alternate#Switch(bang, cmd) abort let file = expand('%') if empty(file) call go#util#EchoError("no buffer name") diff --git a/autoload/go/asmfmt.vim b/autoload/go/asmfmt.vim index b47651dabd..c0ae70c011 100644 --- a/autoload/go/asmfmt.vim +++ b/autoload/go/asmfmt.vim @@ -19,7 +19,7 @@ let s:got_fmt_error = 0 " This is a trimmed-down version of the logic in fmt.vim. -function! go#asmfmt#Format() +function! go#asmfmt#Format() abort " Save state. let l:curw = winsaveview() @@ -55,7 +55,7 @@ function! go#asmfmt#Format() call winrestview(l:curw) endfunction -function! go#asmfmt#ToggleAsmFmtAutoSave() +function! go#asmfmt#ToggleAsmFmtAutoSave() abort if get(g:, "go_asmfmt_autosave", 1) let g:go_asmfmt_autosave = 0 call go#util#EchoProgress("auto asmfmt disabled") diff --git a/autoload/go/cmd.vim b/autoload/go/cmd.vim index 126ac807d5..a70c1bf72f 100644 --- a/autoload/go/cmd.vim +++ b/autoload/go/cmd.vim @@ -2,7 +2,7 @@ if !exists("g:go_dispatch_enabled") let g:go_dispatch_enabled = 0 endif -function! go#cmd#autowrite() +function! go#cmd#autowrite() abort if &autowrite == 1 silent wall endif @@ -13,7 +13,7 @@ endfunction " an editor so the best is to build it to catch errors and fix them. By " default it tries to call simply 'go build', but it first tries to get all " dependent files for the current folder and passes it to go build. -function! go#cmd#Build(bang, ...) +function! go#cmd#Build(bang, ...) abort " expand all wildcards(i.e: '%' to the current file name) let goargs = map(copy(a:000), "expand(v:val)") @@ -75,7 +75,7 @@ endfunction " Run runs the current file (and their dependencies if any) in a new terminal. -function! go#cmd#RunTerm(bang, mode, files) +function! go#cmd#RunTerm(bang, mode, files) abort if empty(a:files) let cmd = "go run ". go#util#Shelljoin(go#tool#Files()) else @@ -88,7 +88,7 @@ endfunction " This is intented to test small programs and play with them. It's not " suitable for long running apps, because vim is blocking by default and " calling long running apps will block the whole UI. -function! go#cmd#Run(bang, ...) +function! go#cmd#Run(bang, ...) abort if has('nvim') call go#cmd#RunTerm(a:bang, '', a:000) return @@ -143,7 +143,7 @@ endfunction " Install installs the package by simple calling 'go install'. If any argument " is given(which are passed directly to 'go install') it tries to install those " packages. Errors are populated in the location window. -function! go#cmd#Install(bang, ...) +function! go#cmd#Install(bang, ...) abort let old_gopath = $GOPATH let $GOPATH = go#path#Detect() let default_makeprg = &makeprg @@ -189,7 +189,7 @@ endfunction " Test runs `go test` in the current directory. If compile is true, it'll " compile the tests instead of running them (useful to catch errors in the " test files). Any other argument is appendend to the final `go test` command -function! go#cmd#Test(bang, compile, ...) +function! go#cmd#Test(bang, compile, ...) abort let args = ["test"] " don't run the test, only compile it. Useful to capture and fix errors. @@ -276,7 +276,7 @@ endfunction " Testfunc runs a single test that surrounds the current cursor position. " Arguments are passed to the `go test` command. -function! go#cmd#TestFunc(bang, ...) +function! go#cmd#TestFunc(bang, ...) abort " search flags legend (used only) " 'b' search backward instead of forward " 'c' accept a match at the cursor position @@ -304,7 +304,7 @@ function! go#cmd#TestFunc(bang, ...) endfunction " Generate runs 'go generate' in similar fashion to go#cmd#Build() -function! go#cmd#Generate(bang, ...) +function! go#cmd#Generate(bang, ...) abort let default_makeprg = &makeprg let old_gopath = $GOPATH @@ -351,7 +351,7 @@ endfunction " ----------------------- let s:test_compile_handlers = {} -function! s:test_compile_handler(job, exit_status, data) +function! s:test_compile_handler(job, exit_status, data) abort if !has_key(s:test_compile_handlers, a:job.id) return endif diff --git a/autoload/go/complete.vim b/autoload/go/complete.vim index e65b008aa7..9baa30ec9c 100644 --- a/autoload/go/complete.vim +++ b/autoload/go/complete.vim @@ -1,6 +1,6 @@ let s:sock_type = (has('win32') || has('win64')) ? 'tcp' : 'unix' -function! s:gocodeCurrentBuffer() +function! s:gocodeCurrentBuffer() abort let buf = getline(1, '$') if &encoding != 'utf-8' let buf = map(buf, 'iconv(v:val, &encoding, "utf-8")') @@ -16,7 +16,7 @@ function! s:gocodeCurrentBuffer() return file endfunction -function! s:gocodeCommand(cmd, preargs, args) +function! s:gocodeCommand(cmd, preargs, args) abort for i in range(0, len(a:args) - 1) let a:args[i] = go#util#Shellescape(a:args[i]) endfor @@ -59,12 +59,12 @@ function! s:gocodeCommand(cmd, preargs, args) endif endfunction -function! s:gocodeCurrentBufferOpt(filename) +function! s:gocodeCurrentBufferOpt(filename) abort return '-in=' . a:filename endfunction let s:optionsEnabled = 0 -function! s:gocodeEnableOptions() +function! s:gocodeEnableOptions() abort if s:optionsEnabled return endif @@ -81,11 +81,11 @@ function! s:gocodeEnableOptions() call go#util#System(printf('%s set unimported-packages %s', go#util#Shellescape(bin_path), s:toBool(get(g:, 'go_gocode_unimported_packages', 1)))) endfunction -function! s:toBool(val) +function! s:toBool(val) abort if a:val | return 'true ' | else | return 'false' | endif endfunction -function! s:gocodeAutocomplete() +function! s:gocodeAutocomplete() abort call s:gocodeEnableOptions() let filename = s:gocodeCurrentBuffer() @@ -96,7 +96,7 @@ function! s:gocodeAutocomplete() return result endfunction -function! go#complete#GetInfo() +function! go#complete#GetInfo() abort let offset = go#util#OffsetCursor()+1 let filename = s:gocodeCurrentBuffer() let result = s:gocodeCommand('autocomplete', @@ -137,7 +137,7 @@ function! go#complete#GetInfo() return "" endfunction -function! go#complete#Info(auto) +function! go#complete#Info(auto) abort " auto is true if we were called by g:go_auto_type_info's autocmd let result = go#complete#GetInfo() if !empty(result) @@ -147,12 +147,12 @@ function! go#complete#Info(auto) endif endfunction -function! s:trim_bracket(val) +function! s:trim_bracket(val) abort let a:val.word = substitute(a:val.word, '[(){}\[\]]\+$', '', '') return a:val endfunction -function! go#complete#Complete(findstart, base) +function! go#complete#Complete(findstart, base) abort "findstart = 1 when we need to get the text length if a:findstart == 1 execute "silent let g:gocomplete_completions = " . s:gocodeAutocomplete() @@ -167,7 +167,7 @@ function! go#complete#Complete(findstart, base) endif endf -function! go#complete#ToggleAutoTypeInfo() +function! go#complete#ToggleAutoTypeInfo() abort if get(g:, "go_auto_type_info", 0) let g:go_auto_type_info = 0 call go#util#EchoProgress("auto type info disabled") diff --git a/autoload/go/coverage.vim b/autoload/go/coverage.vim index f3d36c4314..ab0e57df17 100644 --- a/autoload/go/coverage.vim +++ b/autoload/go/coverage.vim @@ -3,7 +3,7 @@ let s:toggle = 0 " Buffer creates a new cover profile with 'go test -coverprofile' and changes " the current buffers highlighting to show covered and uncovered sections of " the code. If run again it clears the annotation. -function! go#coverage#BufferToggle(bang, ...) +function! go#coverage#BufferToggle(bang, ...) abort if s:toggle call go#coverage#Clear() return @@ -20,7 +20,7 @@ endfunction " teh current buffers highlighting to show covered and uncovered sections of " the code. Calling it again reruns the tests and shows the last updated " coverage. -function! go#coverage#Buffer(bang, ...) +function! go#coverage#Buffer(bang, ...) abort " we use matchaddpos() which was introduce with 7.4.330, be sure we have " it: http://ftp.vim.org/vim/patches/7.4/7.4.330 if !exists("*matchaddpos") @@ -75,7 +75,7 @@ function! go#coverage#Buffer(bang, ...) endfunction " Clear clears and resets the buffer annotation matches -function! go#coverage#Clear() +function! go#coverage#Clear() abort " only reset the syntax if the user has syntax enabled if !empty(&syntax) if exists("g:syntax_on") | syntax enable | endif @@ -93,7 +93,7 @@ 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, ...) +function! go#coverage#Browser(bang, ...) abort let l:tmpname = tempname() let args = [a:bang, 0, "-coverprofile", l:tmpname] @@ -116,7 +116,7 @@ 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) +function! go#coverage#parsegocoverline(line) abort " file:startline.col,endline.col numstmt count let mx = '\([^:]\+\):\(\d\+\)\.\(\d\+\),\(\d\+\)\.\(\d\+\)\s\(\d\+\)\s\(\d\+\)' let tokens = matchlist(a:line, mx) @@ -133,7 +133,7 @@ endfunction " Generates matches to be added to matchaddpos for the given coverage profile " block -function! go#coverage#genmatch(cov) +function! go#coverage#genmatch(cov) abort let color = 'goCoverageCovered' if a:cov.cnt == 0 let color = 'goCoverageUncover' @@ -183,7 +183,7 @@ function! go#coverage#genmatch(cov) endfunction " Reads the given coverprofile file and annotates the current buffer -function! go#coverage#overlay(file) +function! go#coverage#overlay(file) abort if !filereadable(a:file) return endif @@ -251,7 +251,7 @@ endfunction let s:coverage_handler_jobs = {} let s:coverage_browser_handler_jobs = {} -function! s:coverage_handler(job, exit_status, data) +function! s:coverage_handler(job, exit_status, data) abort if !has_key(s:coverage_handler_jobs, a:job.id) return endif @@ -264,7 +264,7 @@ function! s:coverage_handler(job, exit_status, data) unlet s:coverage_handler_jobs[a:job.id] endfunction -function! s:coverage_browser_handler(job, exit_status, data) +function! s:coverage_browser_handler(job, exit_status, data) abort if !has_key(s:coverage_browser_handler_jobs, a:job.id) return endif diff --git a/autoload/go/def.vim b/autoload/go/def.vim index 41464fe0bb..1e94e38d4e 100644 --- a/autoload/go/def.vim +++ b/autoload/go/def.vim @@ -1,7 +1,7 @@ let s:go_stack = [] let s:go_stack_level = 0 -function! go#def#Jump(mode) +function! go#def#Jump(mode) abort let old_gopath = $GOPATH let $GOPATH = go#path#Detect() @@ -80,7 +80,7 @@ function! go#def#Jump(mode) let $GOPATH = old_gopath endfunction -function! s:jump_to_declaration(out, mode) +function! s:jump_to_declaration(out, mode) abort " strip line ending let out = split(a:out, go#util#LineEnding())[0] if go#util#IsWin() @@ -142,7 +142,7 @@ function! s:jump_to_declaration(out, mode) let &switchbuf = old_switchbuf endfunction -function! go#def#SelectStackEntry() +function! go#def#SelectStackEntry() abort let target_window = go#ui#GetReturnWindow() if empty(target_window) let target_window = winnr() @@ -157,7 +157,7 @@ function! go#def#SelectStackEntry() call go#ui#CloseWindow() endfunction -function! go#def#StackUI() +function! go#def#StackUI() abort if len(s:go_stack) == 0 call go#util#EchoError("godef stack empty") return @@ -192,12 +192,12 @@ function! go#def#StackUI() noremap q :call go#ui#CloseWindow() endfunction -function! go#def#StackClear(...) +function! go#def#StackClear(...) abort let s:go_stack = [] let s:go_stack_level = 0 endfunction -function! go#def#StackPop(...) +function! go#def#StackPop(...) abort if len(s:go_stack) == 0 call go#util#EchoError("godef stack empty") return @@ -218,7 +218,7 @@ function! go#def#StackPop(...) call go#def#Stack(newLevel + 1) endfunction -function! go#def#Stack(...) +function! go#def#Stack(...) abort if len(s:go_stack) == 0 call go#util#EchoError("godef stack empty") return diff --git a/autoload/go/doc.vim b/autoload/go/doc.vim index a65351f326..e1398fd1c2 100644 --- a/autoload/go/doc.vim +++ b/autoload/go/doc.vim @@ -15,7 +15,7 @@ endif " returns the package and exported name. exported name might be empty. " ie: fmt and Println " ie: github.com/fatih/set and New -function! s:godocWord(args) +function! s:godocWord(args) abort if !executable('godoc') let msg = "godoc command not found." let msg .= " install with: go get golang.org/x/tools/cmd/godoc" @@ -54,7 +54,7 @@ function! s:godocWord(args) return [pkg, exported_name] endfunction -function! s:godocNotFound(content) +function! s:godocNotFound(content) abort if len(a:content) == 0 return 1 endif @@ -62,7 +62,7 @@ function! s:godocNotFound(content) return a:content =~# '^.*: no such file or directory\n$' endfunction -function! go#doc#OpenBrowser(...) +function! go#doc#OpenBrowser(...) abort let pkgs = s:godocWord(a:000) if empty(pkgs) return @@ -76,7 +76,7 @@ function! go#doc#OpenBrowser(...) call go#tool#OpenBrowser(godoc_url) endfunction -function! go#doc#Open(newmode, mode, ...) +function! go#doc#Open(newmode, mode, ...) abort if len(a:000) " check if we have 'godoc' and use it automatically let bin_path = go#path#CheckBinPath('godoc') @@ -125,7 +125,7 @@ function! go#doc#Open(newmode, mode, ...) call s:GodocView(a:newmode, a:mode, out) endfunction -function! s:GodocView(newposition, position, content) +function! s:GodocView(newposition, position, content) abort " reuse existing buffer window if it exists otherwise create a new one if !bufexists(s:buf_nr) execute a:newposition diff --git a/autoload/go/fmt.vim b/autoload/go/fmt.vim index b55ba83d7c..6ddb2a0d01 100644 --- a/autoload/go/fmt.vim +++ b/autoload/go/fmt.vim @@ -51,7 +51,7 @@ endif " it doesn't undo changes and break undo history. If you are here reading " this and have VimL experience, please look at the function for " improvements, patches are welcome :) -function! go#fmt#Format(withGoimport) +function! go#fmt#Format(withGoimport) abort if g:go_fmt_experimental == 1 " Using winsaveview to save/restore cursor state has the problem of " closing folds on save: @@ -215,7 +215,7 @@ function! go#fmt#Format(withGoimport) endif endfunction -function! go#fmt#ToggleFmtAutoSave() +function! go#fmt#ToggleFmtAutoSave() abort if get(g:, "go_fmt_autosave", 1) let g:go_fmt_autosave = 0 call go#util#EchoProgress("auto fmt disabled") diff --git a/autoload/go/guru.vim b/autoload/go/guru.vim index c1f7f193c5..34388913e4 100644 --- a/autoload/go/guru.vim +++ b/autoload/go/guru.vim @@ -115,7 +115,7 @@ endfunc " and put it into location list. I believe using errorformat is much more " easier to use. If we need more power we can always switch back to parse it " via regex. -func! s:loclistSecond(output) +func! s:loclistSecond(output) abort " backup users errorformat, will be restored once we are finished let old_errorformat = &errorformat @@ -135,7 +135,7 @@ func! s:loclistSecond(output) endfun -function! go#guru#Scope(...) +function! go#guru#Scope(...) abort if a:0 if a:0 == 1 && a:1 == '""' unlet g:go_guru_scope @@ -155,7 +155,7 @@ function! go#guru#Scope(...) endif endfunction -function! go#guru#Tags(...) +function! go#guru#Tags(...) abort if a:0 if a:0 == 1 && a:1 == '""' unlet g:go_guru_tags @@ -177,7 +177,7 @@ endfunction " Report the possible constants, global variables, and concrete types that may " appear in a value of type error -function! go#guru#Whicherrs(selected) +function! go#guru#Whicherrs(selected) abort let out = s:RunGuru('whicherrs', 'plain', a:selected, 1) if has_key(out, 'err') call go#util#EchoError(out.err) @@ -193,7 +193,7 @@ function! go#guru#Whicherrs(selected) endfunction " Show 'implements' relation for selected package -function! go#guru#Implements(selected) +function! go#guru#Implements(selected) abort let out = s:RunGuru('implements', 'plain', a:selected, 1) if has_key(out, 'err') call go#util#EchoError(out.err) @@ -204,7 +204,7 @@ function! go#guru#Implements(selected) endfunction " Describe selected syntax: definition, methods, etc -function! go#guru#Describe(selected) +function! go#guru#Describe(selected) abort let out = s:RunGuru('describe', 'plain', a:selected, 0) if has_key(out, 'err') call go#util#EchoError(out.err) @@ -215,7 +215,7 @@ function! go#guru#Describe(selected) endfunction " Show possible targets of selected function call -function! go#guru#Callees(selected) +function! go#guru#Callees(selected) abort let out = s:RunGuru('callees', 'plain', a:selected, 1) if has_key(out, 'err') call go#util#EchoError(out.err) @@ -226,7 +226,7 @@ function! go#guru#Callees(selected) endfunction " Show possible callers of selected function -function! go#guru#Callers(selected) +function! go#guru#Callers(selected) abort let out = s:RunGuru('callers', 'plain', a:selected, 1) if has_key(out, 'err') call go#util#EchoError(out.err) @@ -237,7 +237,7 @@ function! go#guru#Callers(selected) endfunction " Show path from callgraph root to selected function -function! go#guru#Callstack(selected) +function! go#guru#Callstack(selected) abort let out = s:RunGuru('callstack', 'plain', a:selected, 1) if has_key(out, 'err') call go#util#EchoError(out.err) @@ -248,7 +248,7 @@ function! go#guru#Callstack(selected) endfunction " Show free variables of selection -function! go#guru#Freevars(selected) +function! go#guru#Freevars(selected) abort " Freevars requires a selection if a:selected == -1 call go#util#EchoError("GoFreevars requires a selection (range) of code") @@ -265,7 +265,7 @@ function! go#guru#Freevars(selected) endfunction " Show send/receive corresponding to selected channel op -function! go#guru#ChannelPeers(selected) +function! go#guru#ChannelPeers(selected) abort let out = s:RunGuru('peers', 'plain', a:selected, 1) if has_key(out, 'err') call go#util#EchoError(out.err) @@ -276,7 +276,7 @@ function! go#guru#ChannelPeers(selected) endfunction " Show all refs to entity denoted by selected identifier -function! go#guru#Referrers(selected) +function! go#guru#Referrers(selected) abort let out = s:RunGuru('referrers', 'plain', a:selected, 0) if has_key(out, 'err') call go#util#EchoError(out.err) @@ -286,7 +286,7 @@ function! go#guru#Referrers(selected) call s:loclistSecond(out.out) endfunction -function! go#guru#What(selected) +function! go#guru#What(selected) abort " json_encode() and friends are introduced with this patch (7.4.1304) " vim: https://groups.google.com/d/msg/vim_dev/vLupTNhQhZ8/cDGIk0JEDgAJ " nvim: https://github.com/neovim/neovim/pull/4131 @@ -308,7 +308,7 @@ function! go#guru#What(selected) return result endfunction -function! go#guru#AutoToogleSameIds() +function! go#guru#AutoToogleSameIds() abort if get(g:, "go_auto_sameids", 0) call go#util#EchoProgress("sameids auto highlighting disabled") call go#guru#ClearSameIds() @@ -320,7 +320,7 @@ function! go#guru#AutoToogleSameIds() let g:go_auto_sameids = 1 endfunction -function! go#guru#SameIds(selected) +function! go#guru#SameIds(selected) abort " we use matchaddpos() which was introduce with 7.4.330, be sure we have " it: http://ftp.vim.org/vim/patches/7.4/7.4.330 if !exists("*matchaddpos") @@ -371,7 +371,7 @@ function! go#guru#SameIds(selected) endif endfunction -function! go#guru#ClearSameIds() +function! go#guru#ClearSameIds() abort let m = getmatches() for item in m if item['group'] == 'goSameId' @@ -385,7 +385,7 @@ function! go#guru#ClearSameIds() endif endfunction -function! go#guru#ToggleSameIds(selected) +function! go#guru#ToggleSameIds(selected) abort if len(getmatches()) != 0 call go#guru#ClearSameIds() else diff --git a/autoload/go/impl.vim b/autoload/go/impl.vim index fce4a29b96..139dba75b5 100644 --- a/autoload/go/impl.vim +++ b/autoload/go/impl.vim @@ -1,4 +1,4 @@ -function! go#impl#Impl(...) +function! go#impl#Impl(...) abort let binpath = go#path#CheckBinPath('impl') if empty(binpath) return @@ -69,7 +69,7 @@ else endfunction endif -function! s:root_dirs() +function! s:root_dirs() abort let dirs = [] let root = go#util#goroot() if root !=# '' && isdirectory(root) @@ -88,7 +88,7 @@ function! s:root_dirs() return dirs endfunction -function! s:go_packages(dirs) +function! s:go_packages(dirs) abort let pkgs = [] for d in a:dirs let pkg_root = expand(d . '/pkg/' . go#util#osarch()) @@ -97,7 +97,7 @@ function! s:go_packages(dirs) return map(pkgs, "fnamemodify(v:val, ':t:r')") endfunction -function! s:interface_list(pkg) +function! s:interface_list(pkg) abort let contents = split(go#util#System('go doc ' . a:pkg), "\n") if go#util#ShellError() return [] @@ -108,7 +108,7 @@ function! s:interface_list(pkg) endfunction " Complete package and interface for {interface} -function! go#impl#Complete(arglead, cmdline, cursorpos) +function! go#impl#Complete(arglead, cmdline, cursorpos) abort let words = split(a:cmdline, '\s\+', 1) if words[-1] ==# '' return s:uniq(sort(s:go_packages(s:root_dirs()))) diff --git a/autoload/go/import.vim b/autoload/go/import.vim index 6965891613..8d9e8d4c81 100644 --- a/autoload/go/import.vim +++ b/autoload/go/import.vim @@ -4,7 +4,7 @@ " " Check out the docs for more information at /doc/vim-go.txt " -function! go#import#SwitchImport(enabled, localname, path, bang) +function! go#import#SwitchImport(enabled, localname, path, bang) abort let view = winsaveview() let path = substitute(a:path, '^\s*\(.\{-}\)\s*$', '\1', '') @@ -205,7 +205,7 @@ function! go#import#SwitchImport(enabled, localname, path, bang) endfunction -function! s:Error(s) +function! s:Error(s) abort echohl Error | echo a:s | echohl None endfunction diff --git a/autoload/go/jobcontrol.vim b/autoload/go/jobcontrol.vim index e03c75d66b..dfbad6ef8b 100644 --- a/autoload/go/jobcontrol.vim +++ b/autoload/go/jobcontrol.vim @@ -9,7 +9,7 @@ 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). -function! go#jobcontrol#Spawn(bang, desc, args) +function! go#jobcontrol#Spawn(bang, desc, args) abort " autowrite is not enabled for jobs call go#cmd#autowrite() @@ -41,7 +41,7 @@ function! go#jobcontrol#Statusline() abort endfunction " AddHandler adds a on_exit callback handler and returns the id. -function! go#jobcontrol#AddHandler(handler) +function! go#jobcontrol#AddHandler(handler) abort let i = len(s:handlers) while has_key(s:handlers, string(i)) let i += 1 @@ -52,7 +52,7 @@ function! go#jobcontrol#AddHandler(handler) endfunction " RemoveHandler removes a callback handler by id. -function! go#jobcontrol#RemoveHandler(id) +function! go#jobcontrol#RemoveHandler(id) abort unlet s:handlers[a:id] endfunction @@ -60,7 +60,7 @@ endfunction " a job is started a reference will be stored inside s:jobs. spawn changes the " GOPATH when g:go_autodetect_gopath is enabled. The job is started inside the " current files folder. -function! s:spawn(bang, desc, args) +function! s:spawn(bang, desc, args) abort let job = { \ 'desc': a:desc, \ 'bang': a:bang, @@ -113,7 +113,7 @@ endfunction " references and also displaying errors in the quickfix window collected by " on_stderr handler. If there are no errors and a quickfix window is open, " it'll be closed. -function! s:on_exit(job_id, exit_status) +function! s:on_exit(job_id, exit_status) abort let std_combined = self.stderr + self.stdout let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' @@ -159,7 +159,7 @@ function! s:on_exit(job_id, exit_status) endfunction " callback_handlers_on_exit runs all handlers for job on exit event. -function! s:callback_handlers_on_exit(job, exit_status, data) +function! s:callback_handlers_on_exit(job, exit_status, data) abort if empty(s:handlers) return endif @@ -171,18 +171,18 @@ 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) +function! s:on_stdout(job_id, data) 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) +function! s:on_stderr(job_id, data) abort call extend(self.stderr, a:data) endfunction " abort_all aborts all current jobs created with s:spawn() -function! s:abort_all() +function! s:abort_all() abort if empty(s:jobs) return endif @@ -198,7 +198,7 @@ endfunction " abort aborts the job with the given name, where name is the first argument " passed to s:spawn() -function! s:abort(path) +function! s:abort(path) abort if empty(s:jobs) return endif diff --git a/autoload/go/lint.vim b/autoload/go/lint.vim index 9b2a543a29..582ef1d58d 100644 --- a/autoload/go/lint.vim +++ b/autoload/go/lint.vim @@ -117,7 +117,7 @@ endfunction " Vet calls 'go vet' on the current directory. Any warnings are populated in " the location list -function! go#lint#Vet(bang, ...) +function! go#lint#Vet(bang, ...) abort call go#cmd#autowrite() echon "vim-go: " | echohl Identifier | echon "calling vet..." | echohl None if a:0 == 0 @@ -196,7 +196,7 @@ function! go#lint#Errcheck(...) abort endfunction -function! go#lint#ToggleMetaLinterAutoSave() +function! go#lint#ToggleMetaLinterAutoSave() abort if get(g:, "go_metalinter_autosave", 0) let g:go_metalinter_autosave = 0 call go#util#EchoProgress("auto metalinter disabled") diff --git a/autoload/go/list.vim b/autoload/go/list.vim index 6859a9f3e9..1112a8269b 100644 --- a/autoload/go/list.vim +++ b/autoload/go/list.vim @@ -5,7 +5,7 @@ endif " Window opens the list with the given height up to 10 lines maximum. " Otherwise g:go_loclist_height is used. If no or zero height is given it " closes the window -function! go#list#Window(listtype, ...) +function! go#list#Window(listtype, ...) abort let l:listtype = go#list#Type(a:listtype) " we don't use lwindow to close the location list as we need also the " ability to resize the window. So, we are going to use lopen and lclose @@ -40,7 +40,7 @@ endfunction " Get returns the current list of items from the location list -function! go#list#Get(listtype) +function! go#list#Get(listtype) abort let l:listtype = go#list#Type(a:listtype) if l:listtype == "locationlist" return getloclist(0) @@ -50,7 +50,7 @@ function! go#list#Get(listtype) endfunction " Populate populate the location list with the given items -function! go#list#Populate(listtype, items) +function! go#list#Populate(listtype, items) abort let l:listtype = go#list#Type(a:listtype) if l:listtype == "locationlist" call setloclist(0, a:items, 'r') @@ -59,13 +59,13 @@ function! go#list#Populate(listtype, items) endif endfunction -function! go#list#PopulateWin(winnr, items) +function! go#list#PopulateWin(winnr, items) abort call setloclist(a:winnr, a:items, 'r') endfunction " Parse parses the given items based on the specified errorformat nad " populates the location list. -function! go#list#ParseFormat(listtype, errformat, items) +function! go#list#ParseFormat(listtype, errformat, items) abort let l:listtype = go#list#Type(a:listtype) " backup users errorformat, will be restored once we are finished let old_errorformat = &errorformat @@ -84,7 +84,7 @@ endfunction " Parse parses the given items based on the global errorformat and " populates the location list. -function! go#list#Parse(listtype, items) +function! go#list#Parse(listtype, items) abort let l:listtype = go#list#Type(a:listtype) if l:listtype == "locationlist" lgetexpr a:items @@ -94,7 +94,7 @@ function! go#list#Parse(listtype, items) endfunction " JumpToFirst jumps to the first item in the location list -function! go#list#JumpToFirst(listtype) +function! go#list#JumpToFirst(listtype) abort let l:listtype = go#list#Type(a:listtype) if l:listtype == "locationlist" ll 1 @@ -104,7 +104,7 @@ function! go#list#JumpToFirst(listtype) endfunction " Clean cleans the location list -function! go#list#Clean(listtype) +function! go#list#Clean(listtype) abort let l:listtype = go#list#Type(a:listtype) if l:listtype == "locationlist" lex [] @@ -113,7 +113,7 @@ function! go#list#Clean(listtype) endif endfunction -function! go#list#Type(listtype) +function! go#list#Type(listtype) abort if g:go_list_type == "locationlist" return "locationlist" elseif g:go_list_type == "quickfix" diff --git a/autoload/go/package.vim b/autoload/go/package.vim index e6f194ae8f..b12c7b7171 100644 --- a/autoload/go/package.vim +++ b/autoload/go/package.vim @@ -28,7 +28,7 @@ if len(s:goarch) == 0 endif endif -function! go#package#Paths() +function! go#package#Paths() abort let dirs = [] if !exists("s:goroot") @@ -54,7 +54,7 @@ function! go#package#Paths() return dirs endfunction -function! go#package#ImportPath(arg) +function! go#package#ImportPath(arg) abort let path = fnamemodify(resolve(a:arg), ':p') let dirs = go#package#Paths() @@ -77,7 +77,7 @@ function! go#package#ImportPath(arg) endif endfunction -function! go#package#FromPath(arg) +function! go#package#FromPath(arg) abort let path = fnamemodify(resolve(a:arg), ':p') let dirs = go#package#Paths() @@ -99,7 +99,7 @@ function! go#package#FromPath(arg) endif endfunction -function! go#package#CompleteMembers(package, member) +function! go#package#CompleteMembers(package, member) abort silent! let content = go#util#System('godoc ' . a:package) if go#util#ShellError() || !len(content) return [] @@ -118,7 +118,7 @@ function! go#package#CompleteMembers(package, member) endtry endfunction -function! go#package#Complete(ArgLead, CmdLine, CursorPos) +function! go#package#Complete(ArgLead, CmdLine, CursorPos) abort let words = split(a:CmdLine, '\s\+', 1) " do not complete package members for these commands diff --git a/autoload/go/path.vim b/autoload/go/path.vim index 75c466162b..3b09160df7 100644 --- a/autoload/go/path.vim +++ b/autoload/go/path.vim @@ -8,7 +8,7 @@ let s:initial_go_path = "" " echoes the current GOPATH, if an argument is passed it replaces the current " GOPATH with it. If two double quotes are passed (the empty string in go), " it'll clear the GOPATH and will restore to the initial GOPATH. -function! go#path#GoPath(...) +function! go#path#GoPath(...) abort " we have an argument, replace GOPATH if len(a:000) " clears the current manually set GOPATH and restores it to the @@ -35,7 +35,7 @@ endfunction " Default returns the default GOPATH. If there is a single GOPATH it returns " it. For multiple GOPATHS separated with a the OS specific separator, only " the first one is returned -function! go#path#Default() +function! go#path#Default() abort let go_paths = split($GOPATH, go#util#PathListSep()) if len(go_paths) == 1 @@ -47,7 +47,7 @@ endfunction " HasPath checks whether the given path exists in GOPATH environment variable " or not -function! go#path#HasPath(path) +function! go#path#HasPath(path) abort let go_paths = split($GOPATH, go#util#PathListSep()) let last_char = strlen(a:path) - 1 @@ -69,7 +69,7 @@ endfunction " Godeps, GB, it will modify the GOPATH so those directories take precedence " over the current GOPATH. It also detects diretories whose are outside " GOPATH. -function! go#path#Detect() +function! go#path#Detect() abort let gopath = $GOPATH " don't lookup for godeps if autodetect is disabled. @@ -115,7 +115,7 @@ endfunction " BinPath returns the binary path of installed go tools. -function! go#path#BinPath() +function! go#path#BinPath() abort let bin_path = "" " check if our global custom path is set, if not check if $GOBIN is set so @@ -135,7 +135,7 @@ endfunction " CheckBinPath checks whether the given binary exists or not and returns the " path of the binary. It returns an empty string doesn't exists. -function! go#path#CheckBinPath(binpath) +function! go#path#CheckBinPath(binpath) abort " remove whitespaces if user applied something like 'goimports ' let binpath = substitute(a:binpath, '^\s*\(.\{-}\)\s*$', '\1', '') " save off original path diff --git a/autoload/go/play.vim b/autoload/go/play.vim index 44cf3eca4e..ac5bba4201 100644 --- a/autoload/go/play.vim +++ b/autoload/go/play.vim @@ -3,7 +3,7 @@ if !exists("g:go_play_open_browser") endif -function! go#play#Share(count, line1, line2) +function! go#play#Share(count, line1, line2) abort if !executable('curl') echohl ErrorMsg | echomsg "vim-go: require 'curl' command" | echohl None return @@ -42,7 +42,7 @@ function! go#play#Share(count, line1, line2) endfunction -function! s:get_visual_content() +function! s:get_visual_content() abort let save_regcont = @" let save_regtype = getregtype('"') silent! normal! gvy @@ -55,7 +55,7 @@ endfunction " http://stackoverflow.com/questions/1533565/how-to-get-visually-selected-text-in-vimscript " another function that returns the content of visual selection, it's not used " but might be useful in the future -function! s:get_visual_selection() +function! s:get_visual_selection() abort let [lnum1, col1] = getpos("'<")[1:2] let [lnum2, col2] = getpos("'>")[1:2] @@ -72,7 +72,7 @@ endfunction " following two functions are from: https://github.com/mattn/gist-vim " thanks @mattn -function! s:get_browser_command() +function! s:get_browser_command() abort let go_play_browser_command = get(g:, 'go_play_browser_command', '') if go_play_browser_command == '' if has('win32') || has('win64') diff --git a/autoload/go/rename.vim b/autoload/go/rename.vim index d65256c517..92abfeadc7 100644 --- a/autoload/go/rename.vim +++ b/autoload/go/rename.vim @@ -6,7 +6,7 @@ if !exists("g:go_gorename_prefill") let g:go_gorename_prefill = 1 endif -function! go#rename#Rename(bang, ...) +function! go#rename#Rename(bang, ...) abort let to = "" if a:0 == 0 let from = expand("") diff --git a/autoload/go/template.vim b/autoload/go/template.vim index 4b9e27138d..9cbfc0312e 100644 --- a/autoload/go/template.vim +++ b/autoload/go/template.vim @@ -1,6 +1,6 @@ let s:current_file = expand("") -function! go#template#create() +function! go#template#create() abort let l:root_dir = fnamemodify(s:current_file, ':h:h:h') let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' @@ -28,7 +28,7 @@ function! go#template#create() execute cd . fnameescape(dir) endfunction -function! go#template#ToggleAutoCreate() +function! go#template#ToggleAutoCreate() abort if get(g:, "go_template_autocreate", 1) let g:go_template_autocreate = 0 call go#util#EchoProgress("auto template create disabled") diff --git a/autoload/go/term.vim b/autoload/go/term.vim index 08947fa947..604316ee17 100644 --- a/autoload/go/term.vim +++ b/autoload/go/term.vim @@ -7,12 +7,12 @@ let s:jobs = {} " new creates a new terminal with the given command. Mode is set based on the " global variable g:go_term_mode, which is by default set to :vsplit -function! go#term#new(bang, cmd) +function! go#term#new(bang, cmd) abort return go#term#newmode(a:bang, a:cmd, g:go_term_mode) endfunction " new creates a new terminal with the given command and window mode. -function! go#term#newmode(bang, cmd, mode) +function! go#term#newmode(bang, cmd, mode) abort let mode = a:mode if empty(mode) let mode = g:go_term_mode @@ -74,7 +74,7 @@ function! go#term#newmode(bang, cmd, mode) return id endfunction -function! s:on_stdout(job_id, data) +function! s:on_stdout(job_id, data) abort if !has_key(s:jobs, a:job_id) return endif @@ -83,7 +83,7 @@ function! s:on_stdout(job_id, data) call extend(job.stdout, a:data) endfunction -function! s:on_stderr(job_id, data) +function! s:on_stderr(job_id, data) abort if !has_key(s:jobs, a:job_id) return endif @@ -92,7 +92,7 @@ function! s:on_stderr(job_id, data) call extend(job.stderr, a:data) endfunction -function! s:on_exit(job_id, exit_status) +function! s:on_exit(job_id, exit_status) abort if !has_key(s:jobs, a:job_id) return endif diff --git a/autoload/go/textobj.vim b/autoload/go/textobj.vim index 53dfacd46d..be0c771850 100644 --- a/autoload/go/textobj.vim +++ b/autoload/go/textobj.vim @@ -13,7 +13,7 @@ endif " < > " t for tag -function! go#textobj#Function(mode) +function! go#textobj#Function(mode) abort let offset = go#util#OffsetCursor() let fname = shellescape(expand("%:p")) @@ -84,7 +84,7 @@ function! go#textobj#Function(mode) call cursor(info.rbrace.line-1, 1) endfunction -function! go#textobj#FunctionJump(mode, direction) +function! go#textobj#FunctionJump(mode, direction) abort " get count of the motion. This should be done before all the normal " expressions below as those reset this value(because they have zero " count!). We abstract -1 because the index starts from 0 in motion. diff --git a/autoload/go/tool.vim b/autoload/go/tool.vim index fe7f257571..e7365439bf 100644 --- a/autoload/go/tool.vim +++ b/autoload/go/tool.vim @@ -1,4 +1,4 @@ -function! go#tool#Files() +function! go#tool#Files() abort if go#util#IsWin() let format = '{{range $f := .GoFiles}}{{$.Dir}}\{{$f}}{{printf \"\n\"}}{{end}}{{range $f := .CgoFiles}}{{$.Dir}}\{{$f}}{{printf \"\n\"}}{{end}}' else @@ -9,7 +9,7 @@ function! go#tool#Files() return split(out, '\n') endfunction -function! go#tool#Deps() +function! go#tool#Deps() abort if go#util#IsWin() let format = '{{range $f := .Deps}}{{$f}}{{printf \"\n\"}}{{end}}' else @@ -20,7 +20,7 @@ function! go#tool#Deps() return split(out, '\n') endfunction -function! go#tool#Imports() +function! go#tool#Imports() abort let imports = {} if go#util#IsWin() let format = '{{range $f := .Imports}}{{$f}}{{printf \"\n\"}}{{end}}' @@ -43,7 +43,7 @@ function! go#tool#Imports() return imports endfunction -function! go#tool#PackageName() +function! go#tool#PackageName() abort let command = "go list -f \"{{.Name}}\"" let out = go#tool#ExecuteInDir(command) if go#util#ShellError() != 0 @@ -53,7 +53,7 @@ function! go#tool#PackageName() return split(out, '\n')[0] endfunction -function! go#tool#ParseErrors(lines) +function! go#tool#ParseErrors(lines) abort let errors = [] for line in a:lines @@ -85,7 +85,7 @@ endfunction "FilterValids filters the given items with only items that have a valid "filename. Any non valid filename is filtered out. -function! go#tool#FilterValids(items) +function! go#tool#FilterValids(items) abort " Remove any nonvalid filename from the location list to avoid opening an " empty buffer. See https://github.com/fatih/vim-go/issues/287 for " details. @@ -141,7 +141,7 @@ endfunction " Exists checks whether the given importpath exists or not. It returns 0 if " the importpath exists under GOPATH. -function! go#tool#Exists(importpath) +function! go#tool#Exists(importpath) abort let command = "go list ". a:importpath let out = go#tool#ExecuteInDir(command) @@ -155,7 +155,7 @@ endfunction " following two functions are from: https://github.com/mattn/gist-vim " thanks @mattn -function! s:get_browser_command() +function! s:get_browser_command() abort let go_play_browser_command = get(g:, 'go_play_browser_command', '') if go_play_browser_command == '' if go#util#IsWin() @@ -173,7 +173,7 @@ function! s:get_browser_command() return go_play_browser_command endfunction -function! go#tool#OpenBrowser(url) +function! go#tool#OpenBrowser(url) abort let cmd = s:get_browser_command() if len(cmd) == 0 redraw diff --git a/autoload/go/ui.vim b/autoload/go/ui.vim index ad8b517bfe..3f612576de 100644 --- a/autoload/go/ui.vim +++ b/autoload/go/ui.vim @@ -1,7 +1,7 @@ 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, filetype) +function! go#ui#OpenWindow(title, content, filetype) abort " 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 @@ -54,7 +54,7 @@ function! go#ui#OpenWindow(title, content, filetype) echon endfunction -function! go#ui#GetReturnWindow() +function! go#ui#GetReturnWindow() abort for l:wn in range(1, winnr("$")) if !empty(getwinvar(l:wn, "vim_go_return_window")) return l:wn @@ -63,7 +63,7 @@ function! go#ui#GetReturnWindow() endfunction " CloseWindow closes the current window -function! go#ui#CloseWindow() +function! go#ui#CloseWindow() abort " 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) @@ -82,7 +82,7 @@ endfunction " OpenDefinition parses the current line and jumps to it by openening a new " tab -function! go#ui#OpenDefinition(filter) +function! go#ui#OpenDefinition(filter) abort let curline = getline('.') " don't touch our first line or any blank line diff --git a/autoload/go/util.vim b/autoload/go/util.vim index 8792e2304c..70895b484c 100644 --- a/autoload/go/util.vim +++ b/autoload/go/util.vim @@ -1,5 +1,5 @@ " PathSep returns the appropriate OS specific path separator. -function! go#util#PathSep() +function! go#util#PathSep() abort if go#util#IsWin() return '\' endif @@ -7,7 +7,7 @@ function! go#util#PathSep() endfunction " PathListSep returns the appropriate OS specific path list separator. -function! go#util#PathListSep() +function! go#util#PathListSep() abort if go#util#IsWin() return ";" endif @@ -15,7 +15,7 @@ function! go#util#PathListSep() endfunction " LineEnding returns the correct line ending, based on the current fileformat -function! go#util#LineEnding() +function! go#util#LineEnding() abort if &fileformat == 'dos' return "\r\n" elseif &fileformat == 'mac' @@ -27,12 +27,12 @@ endfunction " Join joins any number of path elements into a single path, adding a " Separator if necessary and returns the result -function! go#util#Join(...) +function! go#util#Join(...) abort return join(a:000, go#util#PathSep()) endfunction " IsWin returns 1 if current OS is Windows or 0 otherwise -function! go#util#IsWin() +function! go#util#IsWin() abort let win = ['win16', 'win32', 'win64', 'win95'] for w in win if (has(w)) @@ -48,7 +48,7 @@ let s:env_cache = {} " env returns the go environment variable for the given key. Where key can be " GOARCH, GOOS, GOROOT, etc... It caches the result and returns the cached " version. -function! go#util#env(key) +function! go#util#env(key) abort let l:key = tolower(a:key) if has_key(s:env_cache, l:key) return s:env_cache[l:key] @@ -68,28 +68,28 @@ function! go#util#env(key) return l:var endfunction -function! go#util#goarch() +function! go#util#goarch() abort return substitute(go#util#System('go env GOARCH'), '\n', '', 'g') endfunction -function! go#util#goos() +function! go#util#goos() abort return substitute(go#util#System('go env GOOS'), '\n', '', 'g') endfunction -function! go#util#goroot() +function! go#util#goroot() abort return substitute(go#util#System('go env GOROOT'), '\n', '', 'g') endfunction -function! go#util#gopath() +function! go#util#gopath() abort return substitute(go#util#System('go env GOPATH'), '\n', '', 'g') endfunction -function! go#util#osarch() +function! go#util#osarch() abort return go#util#goos() . '_' . go#util#goarch() endfunction "Check if has vimproc -function! s:has_vimproc() +function! s:has_vimproc() abort if !exists('g:go#use_vimproc') if go#util#IsWin() try @@ -118,7 +118,7 @@ endif " System runs a shell command. It will reset the shell to /bin/sh for Unix-like " systems if it is executable. -function! go#util#System(str, ...) +function! go#util#System(str, ...) abort let l:shell = &shell if !go#util#IsWin() && executable('/bin/sh') let &shell = '/bin/sh' @@ -132,7 +132,7 @@ function! go#util#System(str, ...) endtry endfunction -function! go#util#ShellError() +function! go#util#ShellError() abort if empty(s:vim_shell_error) return v:shell_error endif @@ -142,7 +142,7 @@ endfunction " StripPath strips the path's last character if it's a path separator. " example: '/foo/bar/' -> '/foo/bar' -function! go#util#StripPathSep(path) +function! go#util#StripPathSep(path) abort let last_char = strlen(a:path) - 1 if a:path[last_char] == go#util#PathSep() return strpart(a:path, 0, last_char) @@ -153,13 +153,13 @@ endfunction " StripTrailingSlash strips the trailing slash from the given path list. " example: ['/foo/bar/'] -> ['/foo/bar'] -function! go#util#StripTrailingSlash(paths) +function! go#util#StripTrailingSlash(paths) abort return map(copy(a:paths), 'go#util#StripPathSep(v:val)') endfunction " Shelljoin returns a shell-safe string representation of arglist. The " {special} argument of shellescape() may optionally be passed. -function! go#util#Shelljoin(arglist, ...) +function! go#util#Shelljoin(arglist, ...) abort try let ssl_save = &shellslash set noshellslash @@ -188,7 +188,7 @@ endf " Shelllist returns a shell-safe representation of the items in the given " arglist. The {special} argument of shellescape() may optionally be passed. -function! go#util#Shelllist(arglist, ...) +function! go#util#Shelllist(arglist, ...) abort try let ssl_save = &shellslash set noshellslash @@ -202,7 +202,7 @@ function! go#util#Shelllist(arglist, ...) endfunction " Returns the byte offset for line and column -function! go#util#Offset(line, col) +function! go#util#Offset(line, col) abort if &encoding != 'utf-8' let sep = go#util#LineEnding() let buf = a:line == 1 ? '' : (join(getline(1, a:line-1), sep) . sep) @@ -213,13 +213,13 @@ function! go#util#Offset(line, col) endfunction " " Returns the byte offset for the cursor -function! go#util#OffsetCursor() +function! go#util#OffsetCursor() abort 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) +function! go#util#Windo(command) abort let s:currentWindow = winnr() try execute "windo " . a:command @@ -231,7 +231,7 @@ endfunction " snippetcase converts the given word to given preferred snippet setting type " case. -function! go#util#snippetcase(word) +function! go#util#snippetcase(word) abort let l:snippet_case = get(g:, 'go_snippet_case_type', "snakecase") if l:snippet_case == "snakecase" return go#util#snakecase(a:word) @@ -244,7 +244,7 @@ endfunction " snakecase converts a string to snake case. i.e: FooBar -> foo_bar " Copied from tpope/vim-abolish -function! go#util#snakecase(word) +function! go#util#snakecase(word) abort let word = substitute(a:word,'::','/','g') let word = substitute(word,'\(\u\+\)\(\u\l\)','\1_\2','g') let word = substitute(word,'\(\l\|\d\)\(\u\)','\1_\2','g') @@ -255,7 +255,7 @@ endfunction " camelcase converts a string to camel case. i.e: FooBar -> fooBar " Copied from tpope/vim-abolish -function! go#util#camelcase(word) +function! go#util#camelcase(word) abort let word = substitute(a:word, '-', '_', 'g') if word !~# '_' && word =~# '\l' return substitute(word,'^.','\l&','') @@ -264,7 +264,7 @@ function! go#util#camelcase(word) endif endfunction -function! go#util#AddTags(line1, line2, ...) +function! go#util#AddTags(line1, line2, ...) abort " default is json let l:keys = ["json"] if a:0 @@ -312,19 +312,19 @@ endfunction " TODO(arslan): I couldn't parameterize the highlight types. Check if we can " simplify the following functions -function! go#util#EchoSuccess(msg) +function! go#util#EchoSuccess(msg) abort redraw | echon "vim-go: " | echohl Function | echon a:msg | echohl None endfunction -function! go#util#EchoError(msg) +function! go#util#EchoError(msg) abort redraw | echon "vim-go: " | echohl ErrorMsg | echon a:msg | echohl None endfunction -function! go#util#EchoWarning(msg) +function! go#util#EchoWarning(msg) abort redraw | echon "vim-go: " | echohl WarningMsg | echon a:msg | echohl None endfunction -function! go#util#EchoProgress(msg) +function! go#util#EchoProgress(msg) abort redraw | echon "vim-go: " | echohl Identifier | echon a:msg | echohl None endfunction From 298520ce1971e223f2e80a04a2bc52418b9436eb Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 19 Nov 2016 20:04:00 +0900 Subject: [PATCH 2/6] add an option to show type info when completion is done --- doc/vim-go.txt | 7 +++++++ plugin/go.vim | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/doc/vim-go.txt b/doc/vim-go.txt index 7518949648..f0ba4ce346 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -1440,6 +1440,13 @@ the `hello_world.go` file is used. The default is: > let g:go_decls_includes = 'func,type' +< + *'g:go_echo_go_info'* + +Use this option to show the identifier information when completion is done. By +default it's enabled > + + let g:go_echo_go_info = 1 < ============================================================================== TROUBLESHOOTING *go-troubleshooting* diff --git a/plugin/go.vim b/plugin/go.vim index 8a9eaf2ae2..eb573614f2 100644 --- a/plugin/go.vim +++ b/plugin/go.vim @@ -126,6 +126,10 @@ endfunction " ============================================================================ " function! s:echo_go_info() + if !get(g:, "go_echo_go_info", 1) + return + endif + if !exists('v:completed_item') || empty(v:completed_item) return endif From 26d766a27d70d2688c6df00900da86051b5e749b Mon Sep 17 00:00:00 2001 From: Rustam Zagirov Date: Sat, 19 Nov 2016 20:34:12 +0300 Subject: [PATCH 3/6] typos in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3285648eee..42c9de82dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ IMPROVEMENTS: * Function calls are now highligted as wel when `g:go_highlight_functions` is enabled [gh-1048] -* Add completion support for uninported packages. This allows to complete even if the package is not improted [gh-1084] +* Add completion support for unimported packages. This allows to complete even if the package is not imported [gh-1084] * Tools that embeds GOROOT into their binaries do not work when people update their Go version and the GOROOT contains the vesion as part of their path (i.e: `/usr/local/Cellar/go/1.7.2/libexec`, [more info](https://blog.filippo.io/stale-goroot-and-gorebuild/)) . This is now fixed by introducing automatic GOROOT set/unset before each tool invoke. [gh-954] BUG FIXES: From 37f828315bf8f47be8cd48f213f489558379092a Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Sat, 19 Nov 2016 19:41:14 -0500 Subject: [PATCH 4/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42c9de82dd..8197f8e91b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ IMPROVEMENTS: * Function calls are now highligted as wel when `g:go_highlight_functions` is enabled [gh-1048] * Add completion support for unimported packages. This allows to complete even if the package is not imported [gh-1084] * Tools that embeds GOROOT into their binaries do not work when people update their Go version and the GOROOT contains the vesion as part of their path (i.e: `/usr/local/Cellar/go/1.7.2/libexec`, [more info](https://blog.filippo.io/stale-goroot-and-gorebuild/)) . This is now fixed by introducing automatic GOROOT set/unset before each tool invoke. [gh-954] +* Added new setting `g:go_echo_go_info` to enable/disable printing identifier information when completion is done [gh-1101] BUG FIXES: From 303667f4f3b8e76045fdbf6ca1e5bc783ac26ad8 Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Sat, 19 Nov 2016 19:43:16 -0500 Subject: [PATCH 5/6] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8197f8e91b..322612f71d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ IMPROVEMENTS: -* Function calls are now highligted as wel when `g:go_highlight_functions` is enabled [gh-1048] +* Function calls are now highligted as well when `g:go_highlight_functions` is enabled [gh-1048] * Add completion support for unimported packages. This allows to complete even if the package is not imported [gh-1084] * Tools that embeds GOROOT into their binaries do not work when people update their Go version and the GOROOT contains the vesion as part of their path (i.e: `/usr/local/Cellar/go/1.7.2/libexec`, [more info](https://blog.filippo.io/stale-goroot-and-gorebuild/)) . This is now fixed by introducing automatic GOROOT set/unset before each tool invoke. [gh-954] * Added new setting `g:go_echo_go_info` to enable/disable printing identifier information when completion is done [gh-1101] @@ -17,6 +17,7 @@ BUG FIXES: * Highlight nested structs correctly [gh-1075] * Highlight builtin functions correctly if `g:go_highlight_functions` is enabled [gh-1070] * Fix `:GoSameIds` highlighting if a new buffer is opened in the same window [gh-1067] +* Internal: add `abort` to all vim function to return in case of errors [gh-1100] ## 1.9 (September 13, 2016) From 362decf1ad1d3156a9dcfb7b6596b99aa91883b6 Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Sat, 19 Nov 2016 19:47:15 -0500 Subject: [PATCH 6/6] complete: disable unimported support Slows down Vim signficantly on some machines. Should be optional. --- CHANGELOG.md | 2 +- autoload/go/complete.vim | 2 +- doc/vim-go.txt | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 322612f71d..4ce1016e53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ IMPROVEMENTS: * Function calls are now highligted as well when `g:go_highlight_functions` is enabled [gh-1048] -* Add completion support for unimported packages. This allows to complete even if the package is not imported [gh-1084] +* Add completion support for unimported packages. This allows to complete even if the package is not imported. By default it's disabled, enable by adding `let g:go_gocode_unimported_packages = 1` [gh-1084] * Tools that embeds GOROOT into their binaries do not work when people update their Go version and the GOROOT contains the vesion as part of their path (i.e: `/usr/local/Cellar/go/1.7.2/libexec`, [more info](https://blog.filippo.io/stale-goroot-and-gorebuild/)) . This is now fixed by introducing automatic GOROOT set/unset before each tool invoke. [gh-954] * Added new setting `g:go_echo_go_info` to enable/disable printing identifier information when completion is done [gh-1101] diff --git a/autoload/go/complete.vim b/autoload/go/complete.vim index 9baa30ec9c..2663afbdd3 100644 --- a/autoload/go/complete.vim +++ b/autoload/go/complete.vim @@ -78,7 +78,7 @@ function! s:gocodeEnableOptions() abort call go#util#System(printf('%s set propose-builtins %s', go#util#Shellescape(bin_path), s:toBool(get(g:, 'go_gocode_propose_builtins', 1)))) call go#util#System(printf('%s set autobuild %s', go#util#Shellescape(bin_path), s:toBool(get(g:, 'go_gocode_autobuild', 1)))) - call go#util#System(printf('%s set unimported-packages %s', go#util#Shellescape(bin_path), s:toBool(get(g:, 'go_gocode_unimported_packages', 1)))) + call go#util#System(printf('%s set unimported-packages %s', go#util#Shellescape(bin_path), s:toBool(get(g:, 'go_gocode_unimported_packages', 0)))) endfunction function! s:toBool(val) abort diff --git a/doc/vim-go.txt b/doc/vim-go.txt index f0ba4ce346..48ee054433 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -1399,9 +1399,11 @@ to an autocompletion proposals. By default it is enabled. *'g:go_gocode_unimported_packages'* Specifies whether `gocode` should include suggestions from unimported packages. -By default it is enabled +By default it is disabled. > - let g:go_gocode_unimported_packages = 1 + let g:go_gocode_unimported_packages = 0 +< + *'g:go_gocode_socket_type'* Specifies whether `gocode` should use a different socket type. By default