Skip to content

Commit

Permalink
import: fix adding import to empty imports
Browse files Browse the repository at this point in the history
fixes #1534
  • Loading branch information
fatih committed Sep 2, 2018
1 parent 0b21790 commit 65f753b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion autoload/go/import.vim
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ function! go#import#SwitchImport(enabled, localname, path, bang) abort
let packageline = line
let appendline = line

elseif linestr =~# '^import\s\+(\+)'
let appendline = line
let appendstr = qlocalpath
elseif linestr =~# '^import\s\+('
let appendstr = qlocalpath
let indentstr = 1
Expand Down Expand Up @@ -118,6 +121,7 @@ function! go#import#SwitchImport(enabled, localname, path, bang) abort
endwhile
break


elseif linestr =~# '^import '
if appendline == packageline
let appendstr = 'import ' . qlocalpath
Expand Down Expand Up @@ -161,8 +165,16 @@ function! go#import#SwitchImport(enabled, localname, path, bang) abort
let linesdelta += 3
let appendstr = qlocalpath
let indentstr = 1
elseif getline(appendline) =~# '^import\s\+(\+)'
call setline(appendline, 'import (')
call append(appendline + 0, appendstr)
call append(appendline + 1, ')')
let linesdelta -= 1
let indentstr = 1
else
call append(appendline, appendstr)
endif
call append(appendline, appendstr)

execute appendline + 1
if indentstr
execute 'normal! >>'
Expand Down

0 comments on commit 65f753b

Please sign in to comment.