Skip to content

Commit

Permalink
Merge pull request #2054 from bhcleek/godef-modified-same-file
Browse files Browse the repository at this point in the history
fix jumping to definition in modified buffer
  • Loading branch information
bhcleek authored Nov 15, 2018
2 parents ece8540 + 68777e1 commit 893065a
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions autoload/go/def.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ function! go#def#Jump(mode) abort
" covers all edge cases, but now anyone can switch to godef if they wish
let bin_name = go#config#DefMode()
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(go#util#GetLines(), l:tmpname)
let fname = l:tmpname
endif

let [l:out, l:err] = go#util#Exec(['godef',
let l:cmd = ['godef',
\ '-f=' . l:fname,
\ '-o=' . go#util#OffsetCursor(),
\ '-t'])
if exists("l:tmpname")
call delete(l:tmpname)
endif
\ '-t']

if &modified
let l:stdin_content = join(go#util#GetLines(), "\n")
call add(l:cmd, "-i")
let [l:out, l:err] = go#util#Exec(l:cmd, l:stdin_content)
else
let [l:out, l:err] = go#util#Exec(l:cmd)
endif
elseif bin_name == 'guru'
let cmd = [go#path#CheckBinPath(bin_name)]
let buildtags = go#config#BuildTags()
Expand All @@ -35,7 +32,7 @@ function! go#def#Jump(mode) abort
let stdin_content = ""

if &modified
let content = join(go#util#GetLines(), "\n")
let content = join(go#util#GetLines(), "\n")
let stdin_content = fname . "\n" . strlen(content) . "\n" . content
call add(cmd, "-modified")
endif
Expand Down

0 comments on commit 893065a

Please sign in to comment.