Closed chrisolsen closed 7 years ago
Thanks for filing. Is that option an effective workaround? What fixes/changes need to be made to goreturns?
@chrisolsen, do you have diff
command installed on your Windows 10 Home?
-d
flag relies on it to perform the diff. See here. If you don't have it, it would fail to work.
If my theory above about diff
being the issue here, then...
What fixes/changes need to be made to goreturns?
Easy: It should check that diff
binary exists, and exit with error if -d
flag is used but diff
isn't available. Especially since it ignores the exit code from running the command. This wouldn't fix the problem, but at least it'd make it visible.
Hard: Rewrite diff
in pure Go and avoid an external dependency. :)
I do have diff.
C:\Users\chris>diff -v
diff - GNU diffutils version 2.7
C:\Users\chris>vim test.go // see test file
C:\Users\chris>goreturns -d test.go
diff test.go gofmt/test.go // only output
test.go
package testme
func main() {
fmt.Println("testing...") // should add `import "fmt"`
}
If it's printing "diff test.go gofmt/test.go", that means it got to this line.
So diff
did run. I'd suggest adding some debug printfs to the code to see what's really going on. It could be that your diff
command produces unexpected output when given -u
flag, or something else.
Does goimports
exhibit the same behavior?
goimports
does return the same output.
For what it's worth, I also came across this issue through my usage of VS Code as referenced in https://github.com/Microsoft/vscode-go/issues/520.
@shurcooL Any new ideas or updates on this one? The Go extension for VS Code depends on the diff output from goreturns
.
@ramya-rao-a I don't see evidence in this issue that there's a problem in code. I suspect it was some specific environment issue on that person's computer. According to https://github.com/sqs/goreturns/issues/28#issuecomment-254862010, they said it happens with goimports
too.
I tested both goimports
and goreturns
, -d
option works as expected for me on macOS.
I would recommend closing this issue and suggesting to anyone who actually runs into this problem to make a new issue with more information and reproduce steps.
I guess I should chime in :) Early this week I had to re-install Windows and noticed that the problem was no longer causing issues. I assumed a fix was made on your guy's side.
Great! I think that confirms it was an environment issue. The only changed merged into goreturns
since this issue was opened on Oct 18, 2016 was a new feature. See https://github.com/sqs/goreturns/commits/master.
It is interesting that 3 to 4 people would have had the same environment issue :)
But yes, it doesnt look like the problem is with goreturns
.
@chrisolsen can you close this issue then?
This issue is in regards to vscode no longer adding/removing imports on save. An additional option was added to override the use of
goreturns -d
and fallback togoreturns -w
, which gets things working for me again.The initial issue: https://github.com/Microsoft/vscode-go/issues/520
I am using: