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

Updated vim plugins

This commit is contained in:
Amir Salihefendic
2018-12-17 12:28:27 +01:00
parent d2d303593e
commit e99e9e9c3e
137 changed files with 2129 additions and 846 deletions

View File

@ -5,6 +5,10 @@
" This file provides a utility function that performs auto-completion of
" package names, for use by other commands.
" don't spam the user when Vim is started in Vi compatibility mode
let s:cpo_save = &cpo
set cpo&vim
let s:goos = $GOOS
let s:goarch = $GOARCH
@ -55,7 +59,7 @@ function! go#package#Paths() abort
endfunction
let s:import_paths = {}
" ImportPath returns the import path in the current directory it was executed
" ImportPath returns the import path of the package for current buffer.
function! go#package#ImportPath() abort
let dir = expand("%:p:h")
if has_key(s:import_paths, dir)
@ -67,47 +71,50 @@ function! go#package#ImportPath() abort
return -1
endif
let import_path = split(out, '\n')[0]
let l:importpath = split(out, '\n')[0]
" go list returns '_CURRENTDIRECTORY' if the directory is not inside GOPATH.
" Check it and retun an error if that is the case
if import_path[0] ==# '_'
if l:importpath[0] ==# '_'
return -1
endif
let s:import_paths[dir] = import_path
let s:import_paths[dir] = l:importpath
return import_path
return l:importpath
endfunction
" FromPath returns the import path of arg.
function! go#package#FromPath(arg) abort
let path = fnamemodify(resolve(a:arg), ':p')
let dirs = go#package#Paths()
let l:cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
let l:dir = getcwd()
for dir in dirs
if len(dir) && match(path, dir) == 0
let workspace = dir
break
endif
endfor
let l:path = a:arg
if !isdirectory(l:path)
let l:path = fnamemodify(l:path, ':h')
endif
if !exists('workspace')
execute l:cd fnameescape(l:path)
let [l:out, l:err] = go#util#Exec(['go', 'list'])
execute l:cd fnameescape(l:dir)
if l:err != 0
return -1
endif
let path = substitute(path, '/*$', '', '')
let workspace = substitute(workspace . '/src/', '/+', '', '')
if isdirectory(path)
return substitute(path, workspace, '', '')
else
return substitute(substitute(path, workspace, '', ''),
\ '/' . fnamemodify(path, ':t'), '', '')
let l:importpath = split(l:out, '\n')[0]
" go list returns '_CURRENTDIRECTORY' if the directory is not inside GOPATH.
" Check it and retun an error if that is the case
if l:importpath[0] ==# '_'
return -1
endif
return l:importpath
endfunction
function! go#package#CompleteMembers(package, member) abort
let [l:content, l:err] = go#util#Exec(['godoc', a:package])
let [l:content, l:err] = go#util#Exec(['go', 'doc', a:package])
if l:err || !len(content)
return []
endif
@ -137,37 +144,41 @@ function! go#package#Complete(ArgLead, CmdLine, CursorPos) abort
return go#package#CompleteMembers(words[1], words[2])
endif
let dirs = go#package#Paths()
let dirs = go#package#Paths()
if len(dirs) == 0
" should not happen
return []
endif
if len(dirs) == 0
" should not happen
return []
endif
let ret = {}
for dir in dirs
" this may expand to multiple lines
let root = split(expand(dir . '/pkg/' . s:goos . '_' . s:goarch), "\n")
call add(root, expand(dir . '/src'))
for r in root
for i in split(globpath(r, a:ArgLead.'*'), "\n")
if isdirectory(i)
let i .= '/'
elseif i !~ '\.a$'
continue
endif
let i = substitute(substitute(i[len(r)+1:], '[\\]', '/', 'g'),
\ '\.a$', '', 'g')
let ret = {}
for dir in dirs
" this may expand to multiple lines
let root = split(expand(dir . '/pkg/' . s:goos . '_' . s:goarch), "\n")
call add(root, expand(dir . '/src'))
for r in root
for i in split(globpath(r, a:ArgLead.'*'), "\n")
if isdirectory(i)
let i .= '/'
elseif i !~ '\.a$'
continue
endif
let i = substitute(substitute(i[len(r)+1:], '[\\]', '/', 'g'),
\ '\.a$', '', 'g')
" without this the result can have duplicates in form of
" 'encoding/json' and '/encoding/json/'
let i = go#util#StripPathSep(i)
" without this the result can have duplicates in form of
" 'encoding/json' and '/encoding/json/'
let i = go#util#StripPathSep(i)
let ret[i] = i
endfor
endfor
let ret[i] = i
endfor
endfor
return sort(keys(ret))
endfor
return sort(keys(ret))
endfunction
" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
" vim: sw=2 ts=2 et