Skip to content
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

goreturns configuration #208

Closed
tobstarr opened this issue Oct 16, 2014 · 4 comments
Closed

goreturns configuration #208

tobstarr opened this issue Oct 16, 2014 · 4 comments

Comments

@tobstarr
Copy link

I am struggling setting up vim-go with goreturns https://github.com/sqs/goreturns. What I tried is this:

    let g:go_fmt_command = 'goreturns'
    let g:go_fmt_options = '-w'

but it seems it always ignores the -w flag (and just prints the output to stdout). Any tips on that?

Thanx!

@sqs
Copy link

sqs commented Oct 16, 2014

@tobstarr and I talked a bit about this on Twitter: https://twitter.com/tobstarr/status/522655779518939136. It seems like goreturns is working by itself but not in vim-go. I don't use vim, but if anyone can determine if there's something I need to fix in goreturns, please let me know and I will make a fix asap.

@fatih
Copy link
Owner

fatih commented Oct 16, 2014

Due to nature of Vim, before I do a formatting I'm creating a temporary file and doing the formatting on it. Now this temporary file is created in a the systems temp dir. Both gofmt and goimports are successful executing them, however goreturns fails. Here is a basic example:

~ ❯ gofmt /var/folders/mc/hxkh39y93dn__458mq8xrbcm0000gn/T/vKrskW5/4
package main

import "errors"

func main() {
    F()
}

func F() (string, int, error) {
    return errors.New("foo")
}
~ ❯ goimports /var/folders/mc/hxkh39y93dn__458mq8xrbcm0000gn/T/vKrskW5/4
package main

import "errors"

func main() {
    F()
}

func F() (string, int, error) {
    return errors.New("foo")
}
~ ❯ goreturns /var/folders/mc/hxkh39y93dn__458mq8xrbcm0000gn/T/vKrskW5/4
no buildable Go source files in /var/folders/mc/hxkh39y93dn__458mq8xrbcm0000gn/T/vKrskW5

Another thing is (which I think should be changed). goreturns outputs an error message together with the corrected message. Again nor gofmt nor goimports is doing it. This is important because the output should be machine readable. If there is an error (in the case below) it should exit with non zero code instead of zero, and it only should output the error.:

demo ❯ gofmt demo.go
package main

import "errors"

func main() {
    F()
}

func F() (string, int, error) {
    return errors.New("foo")
}
demo ❯ goimports demo.go
package main

import "errors"

func main() {
    F()
}

func F() (string, int, error) {
    return errors.New("foo")
}
demo ❯ goreturns demo.go
demo.go:10:2: wrong number of return values (want 3, got 1)
package main

import "errors"

func main() {
    F()
}

func F() (string, int, error) {
    return "", 0, errors.New("foo")
}

@sqs
Copy link

sqs commented Oct 16, 2014

Ah, got it. I will eliminate the error output.

As for the temp file, goreturns needs the file to be in the existing dir because it builds and type checks the files, unlike gofmt/goimports which just parse it. Is it possible to eliminate the usage of a temp file?

Thanks for looking into this.

@fatih
Copy link
Owner

fatih commented Oct 18, 2014

@sqs that's unfortunately not possible. Because the undo history in Vim break when I don't use the temp file. So maybe you can do something that goreturns can be executed in that folder. On my side when I change the behavior it will just break the plugin.

@fatih fatih closed this as completed Oct 18, 2014
mattbostock added a commit to mattbostock/dotfiles that referenced this issue Jan 31, 2015
This reverts commit 4cbe6c0.

`goreturns` was returning output to stdout, rather than writing to a
file. I was hoping for a drop-in replacement for `gofmt`/`goimports`.

See also:
fatih/vim-go#208
mocheryl added a commit to mocheryl/vim-go that referenced this issue Dec 6, 2017
A lot of scripts filter files based on their name to make sure they
operate only on the appropriate content. By appending a Go file type to
a temporary file when running a formatter, we add support for a broader
range of Go formating tools.

Fixes fatih#208
arp242 pushed a commit to mocheryl/vim-go that referenced this issue Dec 10, 2017
A lot of scripts filter files based on their name to make sure they
operate only on the appropriate content. By appending a Go file type to
a temporary file when running a formatter, we add support for a broader
range of Go formating tools.

Fixes fatih#208
arp242 pushed a commit that referenced this issue Dec 10, 2017
Append Go file type when creating temporary file

A lot of scripts filter files based on their name to make sure they
operate only on the appropriate content. By appending a Go file type to
a temporary file when running a formatter, we add support for a broader
range of Go formating tools.

Fixes #208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants