Skip to content

goimports fails when proj symlinked in GOPATH #1310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ function! s:fmt_cmd(bin_name, source, target)
if exists('b:goimports_vendor_compatible') && b:goimports_vendor_compatible
let ssl_save = &shellslash
set noshellslash
call extend(cmd, ["-srcdir", shellescape(fnamemodify(a:target, ":p"))])
" use the filename without the fully qualified name if the tree is
" symlinked into the GOPATH, goimports won't work properly.
call extend(cmd, ["-srcdir", shellescape(a:target)])
let &shellslash = ssl_save
endif
endif
Expand Down
16 changes: 16 additions & 0 deletions autoload/go/fmt_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,19 @@ func Test_update_file()

call assert_equal(expected, actual)
endfunc

func Test_goimports()
let $GOPATH = 'test-fixtures/fmt/'
let actual_file = tempname()
call writefile(readfile("test-fixtures/fmt/src/imports/goimports.go"), actual_file)

let expected = join(readfile("test-fixtures/fmt/src/imports/goimports_golden.go"), "\n")

" run our code
call go#fmt#run("goimports", actual_file, "test-fixtures/fmt/src/imports/goimports.go")

" this should now contain the formatted code
let actual = join(readfile(actual_file), "\n")

call assert_equal(expected, actual)
endfunc
13 changes: 13 additions & 0 deletions autoload/go/test-fixtures/fmt/imports/goimports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"fmt"
)

func Foo(log *logging.TestLogger) {
log.Debug("vim-go")
}

func main() {
fmt.Println("vim-go")
}
15 changes: 15 additions & 0 deletions autoload/go/test-fixtures/fmt/imports/goimports_golden.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"fmt"

logging "gh.com/gi/foo-logging"
)

func Foo(log *logging.TestLogger) {
log.Debug("vim-go")
}

func main() {
fmt.Println("vim-go")
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions autoload/go/test-fixtures/fmt/src/imports
1 change: 1 addition & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cd $(dirname $0)

# install dependencies
go get github.com/fatih/gomodifytags
go get golang.org/x/tools/cmd/goimports

# cleanup test.log
if [ -f "test.log" ]; then
Expand Down