mirror of
				https://github.com/amix/vimrc
				synced 2025-10-31 06:33:35 +08:00 
			
		
		
		
	Updated vim plugins
This commit is contained in:
		| @ -7,7 +7,18 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort | ||||
|     return {'err': "bin path not found"} | ||||
|   endif | ||||
|  | ||||
|   let filename = expand('%:p') | ||||
|   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) | ||||
|  | ||||
| @ -80,12 +91,18 @@ func! s:RunGuru(mode, format, selected, needs_scope) range abort | ||||
|   let old_gopath = $GOPATH | ||||
|   let $GOPATH = go#path#Detect() | ||||
|  | ||||
|   " the query might take time, let us give some feedback | ||||
|   call go#util#EchoProgress("analysing ...") | ||||
|   if 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) | ||||
|   endif | ||||
|  | ||||
|   let $GOPATH = old_gopath | ||||
|   if go#util#ShellError() != 0 | ||||
|     " the output contains the error message | ||||
| @ -268,37 +285,65 @@ function! go#guru#What(selected) | ||||
|  | ||||
|   let out = s:RunGuru('what', 'json', a:selected, 0) | ||||
|   if has_key(out, 'err') | ||||
|     return out.err | ||||
|     return {'err': out.err} | ||||
|   endif | ||||
|  | ||||
|   call s:loclistSecond(out.out) | ||||
|   let result = json_decode(out.out) | ||||
|  | ||||
|   if type(result) != type({}) | ||||
|     return {'err': "malformed output from guru"} | ||||
|   endif | ||||
|  | ||||
|   if !has_key(result, 'what') | ||||
|     return {'err': "no what query found for the given identifier"} | ||||
|   endif | ||||
|  | ||||
|   return {'out': result.what} | ||||
|   return result | ||||
| endfunction | ||||
|  | ||||
| function! go#guru#SameIds(selected) | ||||
|   call go#guru#ClearSameIds() | ||||
|  | ||||
|   let result = go#guru#What(a:selected) | ||||
|   if has_key(out, 'err') | ||||
|     call go#util#EchoError(out.err) | ||||
|   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) | ||||
|     return | ||||
|   endif | ||||
|  | ||||
|   if !has_key(result.out, 'sameids') | ||||
|     call go#util#EchoError("no same_ids founds for the given identifier") | ||||
|     return -1 | ||||
|   if !has_key(result, 'sameids') | ||||
|     if !get(g:, 'go_auto_sameids', 0) | ||||
|       call go#util#EchoError("no same_ids founds for the given identifier") | ||||
|     endif | ||||
|     return | ||||
|   endif | ||||
|  | ||||
|   let same_ids = result.what.sameids | ||||
|   echo same_ids | ||||
|   let poslen = 0 | ||||
|   for enclosing in result['enclosing'] | ||||
|     if enclosing['desc'] == 'identifier' | ||||
|       let poslen = enclosing['end'] - enclosing['start'] | ||||
|       break | ||||
|     endif | ||||
|   endfor | ||||
|  | ||||
|   " return when there's no identifier to highlight. | ||||
|   if poslen == 0 | ||||
|     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 | ||||
|     let pos = split(item, ':') | ||||
|     call matchaddpos('goSameId', [[str2nr(pos[-2]), str2nr(pos[-1]), str2nr(poslen)]]) | ||||
|   endfor | ||||
| endfunction | ||||
|  | ||||
| function! go#guru#ClearSameIds() | ||||
|   let m = getmatches() | ||||
|   for item in m | ||||
|     if item['group'] == 'goSameId' | ||||
|       call matchdelete(item['id']) | ||||
|     endif | ||||
|   endfor | ||||
| endfunction | ||||
|  | ||||
| " vim: sw=2 ts=2 et | ||||
|  | ||||
| @ -131,85 +131,121 @@ function! go#util#Shelljoin(arglist, ...) | ||||
|       return join(map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')'), ' ') | ||||
|     endif | ||||
|  | ||||
|         return join(map(copy(a:arglist), 'shellescape(v:val)'), ' ') | ||||
|     finally | ||||
|         let &shellslash = ssl_save | ||||
|     endtry | ||||
|     return join(map(copy(a:arglist), 'shellescape(v:val)'), ' ') | ||||
|   finally | ||||
|     let &shellslash = ssl_save | ||||
|   endtry | ||||
| endfunction | ||||
|  | ||||
| fu! go#util#Shellescape(arg) | ||||
|     if s:has_vimproc() | ||||
|         return vimproc#shellescape(a:arg) | ||||
|     endif | ||||
|     try | ||||
|         let ssl_save = &shellslash | ||||
|         set noshellslash | ||||
|         return shellescape(a:arg) | ||||
|     finally | ||||
|         let &shellslash = ssl_save | ||||
|     endtry | ||||
|   if s:has_vimproc() | ||||
|     return vimproc#shellescape(a:arg) | ||||
|   endif | ||||
|   try | ||||
|     let ssl_save = &shellslash | ||||
|     set noshellslash | ||||
|     return shellescape(a:arg) | ||||
|   finally | ||||
|     let &shellslash = ssl_save | ||||
|   endtry | ||||
| 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, ...) | ||||
|     try | ||||
|         let ssl_save = &shellslash | ||||
|         set noshellslash | ||||
|         if a:0 | ||||
|             return map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')') | ||||
|         endif | ||||
|         return map(copy(a:arglist), 'shellescape(v:val)') | ||||
|     finally | ||||
|         let &shellslash = ssl_save | ||||
|     endtry | ||||
|   try | ||||
|     let ssl_save = &shellslash | ||||
|     set noshellslash | ||||
|     if a:0 | ||||
|       return map(copy(a:arglist), 'shellescape(v:val, ' . a:1 . ')') | ||||
|     endif | ||||
|     return map(copy(a:arglist), 'shellescape(v:val)') | ||||
|   finally | ||||
|     let &shellslash = ssl_save | ||||
|   endtry | ||||
| endfunction | ||||
|  | ||||
| " Returns the byte offset for line and column | ||||
| function! go#util#Offset(line, col) | ||||
|     if &encoding != 'utf-8' | ||||
|         let sep = go#util#LineEnding() | ||||
|         let buf = a:line == 1 ? '' : (join(getline(1, a:line-1), sep) . sep) | ||||
|         let buf .= a:col == 1 ? '' : getline('.')[:a:col-2] | ||||
|         return len(iconv(buf, &encoding, 'utf-8')) | ||||
|     endif | ||||
|     return line2byte(a:line) + (a:col-2) | ||||
|   if &encoding != 'utf-8' | ||||
|     let sep = go#util#LineEnding() | ||||
|     let buf = a:line == 1 ? '' : (join(getline(1, a:line-1), sep) . sep) | ||||
|     let buf .= a:col == 1 ? '' : getline('.')[:a:col-2] | ||||
|     return len(iconv(buf, &encoding, 'utf-8')) | ||||
|   endif | ||||
|   return line2byte(a:line) + (a:col-2) | ||||
| endfunction | ||||
| " | ||||
| " Returns the byte offset for the cursor | ||||
| function! go#util#OffsetCursor() | ||||
|     return go#util#Offset(line('.'), col('.')) | ||||
|   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) | ||||
|     let s:currentWindow = winnr() | ||||
|     try | ||||
|         execute "windo " . a:command | ||||
|     finally | ||||
|         execute s:currentWindow. "wincmd w" | ||||
|         unlet s:currentWindow | ||||
|     endtry | ||||
|   let s:currentWindow = winnr() | ||||
|   try | ||||
|     execute "windo " . a:command | ||||
|   finally | ||||
|     execute s:currentWindow. "wincmd w" | ||||
|     unlet s:currentWindow | ||||
|   endtry | ||||
| endfunction | ||||
|  | ||||
| " snippetcase converts the given word to given preferred snippet setting type | ||||
| " case. | ||||
| function! go#util#snippetcase(word) | ||||
|   let l:snippet_case = get(g:, 'go_snippet_case_type', "snakecase") | ||||
|   if l:snippet_case == "snakecase" | ||||
|     return go#util#snakecase(a:word) | ||||
|   elseif l:snippet_case == "camelcase" | ||||
|     return go#util#camelcase(a:word) | ||||
|   else | ||||
|     return a:word " do nothing | ||||
|   endif | ||||
| endfunction | ||||
|  | ||||
| " snakecase converts a string to snake case. i.e: FooBar -> foo_bar | ||||
| " Copied from tpope/vim-abolish | ||||
| function! go#util#snakecase(word) | ||||
|   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') | ||||
|   let word = substitute(word,'[.-]','_','g') | ||||
|   let word = tolower(word) | ||||
|   return word | ||||
| endfunction | ||||
|  | ||||
| " camelcase converts a string to camel case. i.e: FooBar -> fooBar | ||||
| " Copied from tpope/vim-abolish | ||||
| function! go#util#camelcase(word) | ||||
|   let word = substitute(a:word, '-', '_', 'g') | ||||
|   if word !~# '_' && word =~# '\l' | ||||
|     return substitute(word,'^.','\l&','') | ||||
|   else | ||||
|     return substitute(word,'\C\(_\)\=\(.\)','\=submatch(1)==""?tolower(submatch(2)) : toupper(submatch(2))','g') | ||||
|   endif | ||||
| 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 | ||||
|   redraws! | 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 | ||||
|   redraws! | 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 | ||||
|   redraws! | 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 | ||||
|   redraws! | echon "vim-go: " | echohl Identifier | echon a:msg | echohl None | ||||
| endfunction | ||||
|  | ||||
| " vim: sw=2 ts=2 et | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 amix
					amix