forked from fatih/vim-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC for fatih#3319 - add fzf wrap for GoImplements
- Loading branch information
Showing
4 changed files
with
112 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
" don't spam the user when Vim is started in Vi compatibility mode | ||
let s:cpo_save = &cpo | ||
set cpo&vim | ||
|
||
function! fzf#fzf#sink(str) abort | ||
if len(a:str) < 2 | ||
return | ||
endif | ||
|
||
let s:current_dir = expand('%:p:h') | ||
|
||
try | ||
" we jump to the file directory so we can get the fullpath via fnamemodify | ||
" below | ||
let l:dir = go#util#Chdir(s:current_dir) | ||
|
||
let vals = matchlist(a:str[1], '|\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)|') | ||
|
||
" i.e: main.go | ||
let filename = vals[1] | ||
let line = vals[2] | ||
let col = vals[3] | ||
|
||
" i.e: /Users/fatih/vim-go/main.go | ||
let filepath = fnamemodify(filename, ":p") | ||
|
||
let cmd = get({'ctrl-x': 'split', | ||
\ 'ctrl-v': 'vertical split', | ||
\ 'ctrl-t': 'tabe'}, a:str[0], 'e') | ||
execute cmd fnameescape(filepath) | ||
call cursor(line, col) | ||
silent! norm! zvzz | ||
finally | ||
"jump back to old dir | ||
call go#util#Chdir(l:dir) | ||
endtry | ||
endfunction | ||
|
||
" restore Vi compatibility settings | ||
let &cpo = s:cpo_save | ||
unlet s:cpo_save | ||
|
||
" vim: sw=2 ts=2 et |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
" don't spam the user when Vim is started in Vi compatibility mode | ||
let s:cpo_save = &cpo | ||
set cpo&vim | ||
|
||
function! s:source(...) abort | ||
let ret_files = [] | ||
|
||
let l:bin = "gopls" | ||
let l:fname = expand('%:p') | ||
let [l:line, l:col] = getpos('.')[1:2] | ||
let pos = printf("%s:%s:%s", | ||
\ l:fname, | ||
\ l:line, | ||
\ l:col | ||
\) | ||
|
||
let bin_path = go#path#CheckBinPath(l:bin) | ||
if empty(bin_path) | ||
return | ||
endif | ||
|
||
call go#cmd#autowrite() | ||
|
||
let [l:out, l:err] = go#util#Exec([l:bin, 'implementation', l:pos]) | ||
if l:err | ||
call go#util#EchoError(l:out) | ||
return | ||
endif | ||
|
||
for line in split(out, '\n') | ||
let vals = matchlist(line, '\(.\{-}\):\(\d\+\):\(\d\+\)-\(\d\+\)') | ||
let filename = fnamemodify(expand(vals[1]), ":~:.") | ||
let pos = printf("|%s:%s:%s|", | ||
\ l:filename, | ||
\ l:vals[2], | ||
\ l:vals[3] | ||
\) | ||
call add(ret_files, printf("%s:%s\t%s", | ||
\ l:filename, | ||
\ l:vals[2], | ||
\ pos | ||
\)) | ||
endfor | ||
return sort(ret_files) | ||
endfunc | ||
|
||
|
||
function! fzf#implements#cmd(...) abort | ||
let l:spec = { | ||
\ 'source': call('<sid>source', [a:000]), | ||
\ 'sink*': function('fzf#fzf#sink'), | ||
\ 'options': printf('-n 1 --with-nth 1 --delimiter=$''\t'' --ansi --prompt "GoImplements> " --expect=ctrl-t,ctrl-v,ctrl-x') | ||
\ } | ||
call fzf#run(fzf#wrap("GoImplements", fzf#vim#with_preview(l:spec, 'right:50%:nohidden'))) | ||
endfunc | ||
|
||
|
||
" restore Vi compatibility settings | ||
let &cpo = s:cpo_save | ||
unlet s:cpo_save | ||
|
||
" vim: sw=2 ts=2 et |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters