1
0
mirror of https://github.com/amix/vimrc synced 2025-06-16 01:25:00 +08:00

Updated plugins

This commit is contained in:
amix
2016-08-02 14:48:32 +02:00
parent 64a81818ee
commit 61a22e9f3e
39 changed files with 1372 additions and 782 deletions

View File

@ -41,7 +41,11 @@ function! go#asmfmt#Format()
" Replace the current file with the temp file; then reload the buffer.
let old_fileformat = &fileformat
" save old file permissions
let original_fperm = getfperm(expand('%'))
call rename(l:tmpname, expand('%'))
" restore old file permissions
call setfperm(expand('%'), original_fperm)
silent edit!
let &fileformat = old_fileformat
let &syntax = &syntax
@ -51,4 +55,15 @@ function! go#asmfmt#Format()
call winrestview(l:curw)
endfunction
function! go#asmfmt#ToggleAsmFmtAutoSave()
if get(g:, "go_asmfmt_autosave", 1)
let g:go_asmfmt_autosave = 0
call go#util#EchoProgress("auto asmfmt disabled")
return
end
let g:go_asmfmt_autosave = 1
call go#util#EchoProgress("auto asmfmt enabled")
endfunction
" vim: sw=2 ts=2 et

View File

@ -143,6 +143,8 @@ endfunction
" is given(which are passed directly to 'go install') it tries to install those
" packages. Errors are populated in the location window.
function! go#cmd#Install(bang, ...)
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
let default_makeprg = &makeprg
" :make expands '%' and '#' wildcards, so they must also be escaped
@ -179,6 +181,7 @@ function! go#cmd#Install(bang, ...)
redraws! | echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None
endif
let $GOPATH = old_gopath
let &makeprg = default_makeprg
endfunction

View File

@ -153,4 +153,16 @@ function! go#complete#Complete(findstart, base)
endif
endf
function! go#complete#ToggleAutoTypeInfo()
if get(g:, "go_auto_type_info", 0)
let g:go_auto_type_info = 0
call go#util#EchoProgress("auto type info disabled")
return
end
let g:go_auto_type_info = 1
call go#util#EchoProgress("auto type info enabled")
endfunction
" vim: sw=2 ts=2 et

View File

@ -134,9 +134,9 @@ endfunction
" Generates matches to be added to matchaddpos for the given coverage profile
" block
function! go#coverage#genmatch(cov)
let color = 'covered'
let color = 'goCoverageCovered'
if a:cov.cnt == 0
let color = 'uncover'
let color = 'goCoverageUncover'
endif
let matches = []
@ -195,12 +195,12 @@ function! go#coverage#overlay(file)
" contains matches for matchaddpos()
let matches = []
" first mark all lines as normaltext. We use a custom group to not
" first mark all lines as goCoverageNormalText. We use a custom group to not
" interfere with other buffers highlightings. Because the priority is
" lower than the cover and uncover matches, it'll be overriden.
let cnt = 1
while cnt <= line('$')
call add(matches, {'group': 'normaltext', 'pos': [cnt], 'priority': 1})
call add(matches, {'group': 'goCoverageNormalText', 'pos': [cnt], 'priority': 1})
let cnt += 1
endwhile
@ -234,9 +234,6 @@ function! go#coverage#overlay(file)
endfor
syntax manual
highlight normaltext term=bold ctermfg=darkgrey guifg=#75715E
highlight covered term=bold ctermfg=green guifg=#A6E22E
highlight uncover term=bold ctermfg=red guifg=#F92672
" clear the matches if we leave the buffer
autocmd BufWinLeave <buffer> call go#coverage#Clear()

View File

@ -6,12 +6,6 @@ function! go#def#Jump(mode)
let $GOPATH = go#path#Detect()
let fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
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)
let fname = l:tmpname
endif
" so guru right now is slow for some people. previously we were using
" godef which also has it's own quirks. But this issue come up so many
@ -19,6 +13,13 @@ function! go#def#Jump(mode)
" covers all edge cases, but now anyone can switch to godef if they wish
let bin_name = get(g:, 'go_def_mode', 'guru')
if bin_name == 'godef'
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)
let fname = l:tmpname
endif
let bin_path = go#path#CheckBinPath("godef")
if empty(bin_path)
let $GOPATH = old_gopath
@ -31,31 +32,45 @@ function! go#def#Jump(mode)
" jump_to_declaration() function can parse it. This makes it
" compatible with guru definition as well too
let out = join(split(out, '\n'), ':')
if exists("l:tmpname")
call delete(l:tmpname)
endif
elseif bin_name == 'guru'
let flags = ""
let in = ""
if &modified
let sep = go#util#LineEnding()
let content = join(getline(1, '$'), sep)
let in = fname . "\n" . strlen(content) . "\n" . content
let flags .= " -modified"
endif
let bin_path = go#path#CheckBinPath("guru")
if empty(bin_path)
let $GOPATH = old_gopath
return
endif
let flags = ""
if exists('g:go_guru_tags')
let tags = get(g:, 'go_guru_tags')
let flags = printf(" -tags %s", tags)
let flags .= printf(" -tags %s", tags)
endif
let fname = shellescape(fname.':#'.go#util#OffsetCursor())
let command = printf("%s %s definition %s", bin_path, flags, fname)
let out = go#util#System(command)
if &modified
let out = go#util#System(command, in)
else
let out = go#util#System(command)
endif
else
call go#util#EchoError('go_def_mode value: '. bin_name .' is not valid. Valid values are: [godef, guru]')
return
endif
if exists("l:tmpname")
call delete(l:tmpname)
endif
if go#util#ShellError() != 0
call go#util#EchoError(out)
return
@ -98,24 +113,29 @@ function! s:jump_to_declaration(out, mode)
" modes of switchbuf which we need based on the split mode
let old_switchbuf = &switchbuf
" jump to existing buffer if, 1. we have enabled it, 2. the buffer is loaded
" and 3. there is buffer window number we switch to
if get(g:, 'go_def_reuse_buffer', 0) && bufloaded(filename) != 0 && bufwinnr(filename) != -1
" jumpt to existing buffer if it exists
execute bufwinnr(filename) . 'wincmd w'
elseif a:mode == "tab"
let &switchbuf = "usetab"
if bufloaded(filename) == 0
tab split
let l:fname = fnamemodify(expand("%"), ':p:gs?\\?/?')
if filename != l:fname
" jump to existing buffer if, 1. we have enabled it, 2. the buffer is loaded
" and 3. there is buffer window number we switch to
if get(g:, 'go_def_reuse_buffer', 0) && bufloaded(filename) != 0 && bufwinnr(filename) != -1
" jumpt to existing buffer if it exists
execute bufwinnr(filename) . 'wincmd w'
elseif a:mode == "tab"
let &switchbuf = "usetab"
if bufloaded(filename) == 0
tab split
endif
elseif a:mode == "split"
split
elseif a:mode == "vsplit"
vsplit
elseif &modified
split
endif
elseif a:mode == "split"
split
elseif a:mode == "vsplit"
vsplit
endif
" open the file and jump to line and column
exec 'edit '.filename
" open the file and jump to line and column
exec 'edit '.filename
endif
call cursor(line, col)
" also align the line to middle of the view

View File

@ -43,7 +43,7 @@ if !exists("g:go_fmt_experimental")
let g:go_fmt_experimental = 0
endif
" we have those problems :
" we have those problems :
" http://stackoverflow.com/questions/12741977/prevent-vim-from-updating-its-undo-tree
" http://stackoverflow.com/questions/18532692/golang-formatter-and-vim-how-to-destroy-history-record?rq=1
"
@ -124,7 +124,7 @@ function! go#fmt#Format(withGoimport)
if exists('b:goimports_vendor_compatible') && b:goimports_vendor_compatible
let ssl_save = &shellslash
set noshellslash
let command = command . '-srcdir ' . shellescape(expand("%:p:h"))
let command = command . '-srcdir ' . shellescape(expand("%:p"))
let &shellslash = ssl_save
endif
endif
@ -149,7 +149,15 @@ function! go#fmt#Format(withGoimport)
" 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
@ -207,4 +215,14 @@ function! go#fmt#Format(withGoimport)
endif
endfunction
function! go#fmt#ToggleFmtAutoSave()
if get(g:, "go_fmt_autosave", 1)
let g:go_fmt_autosave = 0
call go#util#EchoProgress("auto fmt disabled")
return
end
let g:go_fmt_autosave = 1
call go#util#EchoProgress("auto fmt enabled")
endfunction
" vim: sw=2 ts=2 et

View File

@ -1,5 +1,6 @@
" guru.vim -- Vim integration for the Go guru.
func! s:RunGuru(mode, format, selected, needs_scope) range abort
"return with a warning if the binary doesn't exist
let bin_path = go#path#CheckBinPath("guru")
@ -7,18 +8,6 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
return {'err': "bin path not found"}
endif
let filename = fnamemodify(expand("%"), ':p:gs?\\?/?')
if !filereadable(filename)
" this might happen for new buffers which are not written yet
return {'err': "file does not exist"}
endif
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)
let filename = l:tmpname
endif
let dirname = expand('%:p:h')
let pkg = go#package#ImportPath(dirname)
@ -30,6 +19,15 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
" start constructing the 'command' variable
let command = bin_path
let filename = fnamemodify(expand("%"), ':p:gs?\\?/?')
let in = ""
if &modified
let sep = go#util#LineEnding()
let content = join(getline(1, '$'), sep )
let in = filename . "\n" . strlen(content) . "\n" . content
let command .= " -modified"
endif
" enable outputting in json format
if a:format == "json"
let command .= " -json"
@ -72,8 +70,8 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
let scopes = go#util#Shelllist(scopes)
" guru expect a comma-separated list of patterns, construct it
let scope = join(scopes, ",")
let command .= printf(" -scope %s", scope)
let l:scope = join(scopes, ",")
let command .= printf(" -scope %s", l:scope)
endif
let pos = printf("#%s", go#util#OffsetCursor())
@ -91,16 +89,18 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
if a:mode !=# 'what'
if a:needs_scope
call go#util#EchoProgress("analysing with scope ". l:scope . " ...")
elseif a:mode !=# 'what'
" the query might take time, let us give some feedback
call go#util#EchoProgress("analysing ...")
endif
" run, forrest run!!!
let out = go#util#System(command)
if exists("l:tmpname")
call delete(l:tmpname)
if &modified
let out = go#util#System(command, in)
else
let out = go#util#System(command)
endif
let $GOPATH = old_gopath
@ -176,6 +176,23 @@ function! go#guru#Tags(...)
endif
endfunction
" Report the possible constants, global variables, and concrete types that may
" appear in a value of type error
function! go#guru#Whicherrs(selected)
let out = s:RunGuru('whicherrs', 'plain', a:selected, 1)
if has_key(out, 'err')
call go#util#EchoError(out.err)
return
endif
if empty(out.out)
call go#util#EchoSuccess("no error variables found. Try to change the scope with :GoGuruScope")
return
endif
call s:loclistSecond(out.out)
endfunction
" Show 'implements' relation for selected package
function! go#guru#Implements(selected)
let out = s:RunGuru('implements', 'plain', a:selected, 1)
@ -271,16 +288,11 @@ function! go#guru#Referrers(selected)
endfunction
function! go#guru#What(selected)
" nvim doesn't have JSON support, though they work on it:
" https://github.com/neovim/neovim/pull/4131
if has('nvim')
return {'err': "GoWhat is not supported in Neovim"}
endif
" json_encode() and friends are introduced with this patch
" https://groups.google.com/d/msg/vim_dev/vLupTNhQhZ8/cDGIk0JEDgAJ
if !has('patch-7.4.1304')
return {'err': "GoWhat is supported with Vim version 7.4-1304 or later"}
" 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
if !exists("*json_decode")
return {'err': "GoWhat is not supported due old version of Vim/Neovim"}
endif
let out = s:RunGuru('what', 'json', a:selected, 0)
@ -297,10 +309,29 @@ function! go#guru#What(selected)
return result
endfunction
function! go#guru#AutoToogleSameIds()
if get(g:, "go_auto_sameids", 0)
call go#util#EchoProgress("sameids auto highlighting disabled")
call go#guru#ClearSameIds()
let g:go_auto_sameids = 0
return
endif
call go#util#EchoSuccess("sameids auto highlighting enabled")
let g:go_auto_sameids = 1
endfunction
function! go#guru#SameIds(selected)
call go#guru#ClearSameIds()
" 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")
call go#util#EchoError("GoSameIds is supported with Vim version 7.4-330 or later")
return
endif
let result = go#guru#What(a:selected)
call go#guru#ClearSameIds() " run after calling guru to reduce flicker.
if has_key(result, 'err') && !get(g:, 'go_auto_sameids', 0)
" only echo if it's called via `:GoSameIds, but not if it's in automode
call go#util#EchoError(result.err)
@ -327,8 +358,6 @@ function! go#guru#SameIds(selected)
return
endif
hi goSameId term=bold cterm=bold ctermbg=white ctermfg=black
let same_ids = result['sameids']
" highlight the lines
for item in same_ids
@ -346,4 +375,12 @@ function! go#guru#ClearSameIds()
endfor
endfunction
function! go#guru#ToggleSameIds(selected)
if len(getmatches()) != 0
call go#guru#ClearSameIds()
else
call go#guru#SameIds(a:selected)
endif
endfunction
" vim: sw=2 ts=2 et

View File

@ -71,12 +71,12 @@ endif
function! s:root_dirs()
let dirs = []
let root = go#util#GOROOT()
let root = go#util#goroot()
if root !=# '' && isdirectory(root)
call add(dirs, root)
endif
let paths = map(split(go#util#GOPATH(), go#util#PathListSep()), "substitute(v:val, '\\\\', '/', 'g')")
let paths = map(split(go#util#gopath(), go#util#PathListSep()), "substitute(v:val, '\\\\', '/', 'g')")
if go#util#ShellError()
return []
endif
@ -91,7 +91,7 @@ endfunction
function! s:go_packages(dirs)
let pkgs = []
for d in a:dirs
let pkg_root = expand(d . '/pkg/' . go#util#OSARCH())
let pkg_root = expand(d . '/pkg/' . go#util#osarch())
call extend(pkgs, split(globpath(pkg_root, '**/*.a', 1), "\n"))
endfor
return map(pkgs, "fnamemodify(v:val, ':t:r')")

View File

@ -196,4 +196,15 @@ function! go#lint#Errcheck(...) abort
endfunction
function! go#lint#ToggleMetaLinterAutoSave()
if get(g:, "go_metalinter_autosave", 0)
let g:go_metalinter_autosave = 0
call go#util#EchoProgress("auto metalinter disabled")
return
end
let g:go_metalinter_autosave = 1
call go#util#EchoProgress("auto metalinter enabled")
endfunction
" vim: sw=2 ts=2 et

View File

@ -33,7 +33,7 @@ function! go#package#Paths()
if !exists("s:goroot")
if executable('go')
let s:goroot = substitute(go#util#System('go env GOROOT'), '\n', '', 'g')
let s:goroot = go#util#goroot()
if go#util#ShellError() != 0
echomsg '''go env GOROOT'' failed'
endif

View File

@ -10,13 +10,13 @@ function! go#template#create()
let l:package_name = go#tool#PackageName()
" if we can't figure out any package name(no Go files or non Go package
" files) from the directory create the template
" files) from the directory create the template
if l:package_name == -1
let l:template_file = get(g:, 'go_template_file', "hello_world.go")
let l:template_path = go#util#Join(l:root_dir, "templates", l:template_file)
exe '0r ' . l:template_path
exe '0r ' . fnameescape(l:template_path)
$delete _
else
else
let l:content = printf("package %s", l:package_name)
call append(0, l:content)
$delete _
@ -28,4 +28,15 @@ function! go#template#create()
execute cd . fnameescape(dir)
endfunction
function! go#template#ToggleAutoCreate()
if get(g:, "go_template_autocreate", 1)
let g:go_template_autocreate = 0
call go#util#EchoProgress("auto template create disabled")
return
end
let g:go_template_autocreate = 1
call go#util#EchoProgress("auto template create enabled")
endfunction
" vim: sw=2 ts=2 et

View File

@ -44,7 +44,7 @@ function! go#tool#Imports()
endfunction
function! go#tool#PackageName()
let command = "go list -f '{{.Name}}'"
let command = "go list -f \"{{.Name}}\""
let out = go#tool#ExecuteInDir(command)
if go#util#ShellError() != 0
return -1

View File

@ -43,27 +43,26 @@ function! go#util#IsWin()
return 0
endfunction
function! go#util#GOARCH()
function! go#util#goarch()
return substitute(go#util#System('go env GOARCH'), '\n', '', 'g')
endfunction
function! go#util#GOOS()
function! go#util#goos()
return substitute(go#util#System('go env GOOS'), '\n', '', 'g')
endfunction
function! go#util#GOROOT()
function! go#util#goroot()
return substitute(go#util#System('go env GOROOT'), '\n', '', 'g')
endfunction
function! go#util#GOPATH()
function! go#util#gopath()
return substitute(go#util#System('go env GOPATH'), '\n', '', 'g')
endfunction
function! go#util#OSARCH()
return go#util#GOOS() . '_' . go#util#GOARCH()
function! go#util#osarch()
return go#util#goos() . '_' . go#util#goarch()
endfunction
"Check if has vimproc
function! s:has_vimproc()
if !exists('g:go#use_vimproc')
@ -92,8 +91,20 @@ else
let s:vim_shell_error = ''
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, ...)
return call(s:vim_system, [a:str] + a:000)
let l:shell = &shell
if !go#util#IsWin() && executable('/bin/sh')
let &shell = '/bin/sh'
endif
try
let l:output = call(s:vim_system, [a:str] + a:000)
return l:output
finally
let &shell = l:shell
endtry
endfunction
function! go#util#ShellError()
@ -228,24 +239,68 @@ function! go#util#camelcase(word)
endif
endfunction
function! go#util#AddTags(line1, line2, ...)
" default is json
let l:keys = ["json"]
if a:0
let l:keys = a:000
endif
let l:line1 = a:line1
let l:line2 = a:line2
" If we're inside a struct and just call this function let us add the tags
" to all fields
" TODO(arslan): I don't like using patterns. Check if we can move it to
" `motion` and do it via AST based position
let ln1 = searchpair('struct {', '', '}', 'bcnW')
if ln1 == 0
echon "vim-go: " | echohl ErrorMsg | echon "cursor is outside the struct" | echohl None
return
endif
" searchpair only returns a single position
let ln2 = search('}', "cnW")
" if no range is given we apply for the whole struct
if l:line1 == l:line2
let l:line1 = ln1 + 1
let l:line2 = ln2 - 1
endif
for line in range(l:line1, l:line2)
" get the field name (word) that are not part of a commented line
let l:matched = matchstr(getline(line), '\(\/\/.*\)\@<!\w\+')
if empty(l:matched)
continue
endif
let word = go#util#snippetcase(l:matched)
let tags = map(copy(l:keys), 'printf("%s:%s", v:val,"\"'. word .'\"")')
let updated_line = printf("%s `%s`", getline(line), join(tags, " "))
" finally, update the line inplace
call setline(line, updated_line)
endfor
endfunction
" TODO(arslan): I couldn't parameterize the highlight types. Check if we can
" simplify the following functions
function! go#util#EchoSuccess(msg)
redraws! | echon "vim-go: " | echohl Function | echon a:msg | echohl None
redraw | echon "vim-go: " | echohl Function | echon a:msg | echohl None
endfunction
function! go#util#EchoError(msg)
redraws! | echon "vim-go: " | echohl ErrorMsg | echon a:msg | echohl None
redraw | echon "vim-go: " | echohl ErrorMsg | echon a:msg | echohl None
endfunction
function! go#util#EchoWarning(msg)
redraws! | echon "vim-go: " | echohl WarningMsg | echon a:msg | echohl None
redraw | echon "vim-go: " | echohl WarningMsg | echon a:msg | echohl None
endfunction
function! go#util#EchoProgress(msg)
redraws! | echon "vim-go: " | echohl Identifier | echon a:msg | echohl None
redraw | echon "vim-go: " | echohl Identifier | echon a:msg | echohl None
endfunction
" vim: sw=2 ts=2 et