Skip to content

Commit ac26ff6

Browse files
committed
Fix named imports, remove eol pattern, unused
1 parent 95d61c9 commit ac26ff6

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

autoload/sj/go.vim

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
let s:eol_pattern = '\s*\%(\/\/.*\)\=$'
2-
31
function! sj#go#SplitImports()
4-
if getline('.') =~ '^import ".*"$'
5-
call sj#Keeppatterns('s/^import \(".*"\)$/import (\r\1\r)/')
2+
let pattern = '^import\s\+\(\%(\k\+\s\+\)\=\%(".*"\)\)$'
3+
4+
if getline('.') =~ pattern
5+
call sj#Keeppatterns('s/' . pattern . '/import (\r\1\r)/')
66
normal! k==
77
return 1
88
else
@@ -11,10 +11,10 @@ function! sj#go#SplitImports()
1111
endfunction
1212

1313
function! sj#go#JoinImports()
14-
if getline('.') =~ '^import ($' &&
15-
\ getline(line('.') + 1) =~ '^\s*".*"$' &&
14+
if getline('.') =~ '^import\s*($' &&
15+
\ getline(line('.') + 1) =~ '^\s*\%(\k\+\s\+\)\=".*"$' &&
1616
\ getline(line('.') + 2) =~ '^)$'
17-
call sj#Keeppatterns('s/^import (\_s\+\(".*"\)\_s\+)$/import \1/')
17+
call sj#Keeppatterns('s/^import (\_s\+\(\%(\k\+\s\+\)\=\(".*"\)\)\_s\+)$/import \1/')
1818
return 1
1919
else
2020
return 0
@@ -92,7 +92,7 @@ endfunction
9292

9393
function! sj#go#JoinVars() abort
9494
let pattern = '^\s*\(var\|type\|const\)\s\+('
95-
if sj#SearchUnderCursor(pattern.s:eol_pattern) <= 0
95+
if sj#SearchUnderCursor(pattern) <= 0
9696
return 0
9797
endif
9898

@@ -325,7 +325,7 @@ function! sj#go#JoinFuncCallOrDefinition()
325325
return 0
326326
endif
327327

328-
if strpart(getline('.'), 0, col('.')) =~ '\(var\|type\|const\)\s\+($'
328+
if strpart(getline('.'), 0, col('.')) =~ '\(var\|type\|const\|import\)\s\+($'
329329
" This isn't a function call, it's a multilne var/const/type declaration
330330
return 0
331331
endif

spec/plugin/go_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@
3030
EOF
3131
end
3232

33+
specify "imports with names" do
34+
set_file_contents <<~EOF
35+
import _ "fmt"
36+
EOF
37+
38+
vim.search('import')
39+
split
40+
41+
assert_file_contents <<~EOF
42+
import (
43+
_ "fmt"
44+
)
45+
EOF
46+
47+
vim.search('import')
48+
join
49+
50+
assert_file_contents <<~EOF
51+
import _ "fmt"
52+
EOF
53+
end
54+
3355
specify "structs" do
3456
set_file_contents <<~EOF
3557
StructType{one: 1, two: "asdf", three: []int{1, 2, 3}}
@@ -38,7 +60,6 @@
3860
vim.search 'one:'
3961
split
4062

41-
4263
assert_file_contents <<~EOF
4364
StructType{
4465
one: 1,

0 commit comments

Comments
 (0)