Skip to content

Commit 60565da

Browse files
authored
goimports fails when proj symlinked in GOPATH (#1310)
* goimports fails when proj symlinked in GOPATH * scripts/test: add goimports dependency
1 parent aec3292 commit 60565da

File tree

7 files changed

+61
-1
lines changed

7 files changed

+61
-1
lines changed

autoload/go/fmt.vim

+3-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,9 @@ function! s:fmt_cmd(bin_name, source, target)
193193
if exists('b:goimports_vendor_compatible') && b:goimports_vendor_compatible
194194
let ssl_save = &shellslash
195195
set noshellslash
196-
call extend(cmd, ["-srcdir", shellescape(fnamemodify(a:target, ":p"))])
196+
" use the filename without the fully qualified name if the tree is
197+
" symlinked into the GOPATH, goimports won't work properly.
198+
call extend(cmd, ["-srcdir", shellescape(a:target)])
197199
let &shellslash = ssl_save
198200
endif
199201
endif

autoload/go/fmt_test.vim

+16
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,19 @@ func Test_update_file()
2929

3030
call assert_equal(expected, actual)
3131
endfunc
32+
33+
func Test_goimports()
34+
let $GOPATH = 'test-fixtures/fmt/'
35+
let actual_file = tempname()
36+
call writefile(readfile("test-fixtures/fmt/src/imports/goimports.go"), actual_file)
37+
38+
let expected = join(readfile("test-fixtures/fmt/src/imports/goimports_golden.go"), "\n")
39+
40+
" run our code
41+
call go#fmt#run("goimports", actual_file, "test-fixtures/fmt/src/imports/goimports.go")
42+
43+
" this should now contain the formatted code
44+
let actual = join(readfile(actual_file), "\n")
45+
46+
call assert_equal(expected, actual)
47+
endfunc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func Foo(log *logging.TestLogger) {
8+
log.Debug("vim-go")
9+
}
10+
11+
func main() {
12+
fmt.Println("vim-go")
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
logging "gh.com/gi/foo-logging"
7+
)
8+
9+
func Foo(log *logging.TestLogger) {
10+
log.Debug("vim-go")
11+
}
12+
13+
func main() {
14+
fmt.Println("vim-go")
15+
}

autoload/go/test-fixtures/fmt/imports/vendor/gh.com/gi/foo-logging/logger.go

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../imports/

scripts/test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cd $(dirname $0)
66

77
# install dependencies
88
go get github.com/fatih/gomodifytags
9+
go get golang.org/x/tools/cmd/goimports
910

1011
# cleanup test.log
1112
if [ -f "test.log" ]; then

0 commit comments

Comments
 (0)