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