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

formatting: option to wrap long lines #847

Closed
rendaw opened this issue Oct 16, 2020 · 7 comments
Closed

formatting: option to wrap long lines #847

rendaw opened this issue Oct 16, 2020 · 7 comments

Comments

@rendaw
Copy link

rendaw commented Oct 16, 2020

Recent changes removed the option to prevent gopls from formatting code in the context of VS Code: mvdan/gofumpt#83

gofumpt is specially being integrated into gopls, but this leaves users of other tools like https://github.com/segmentio/golines out in the cold now having to choose between better in-editor diagnostics or code formatting.

I (at least) am not particular about how long lines are automatically wrapped, so if you aren't interested in adding an option to wrap lines perhaps bringing back options that would allow golines to coexist with gopls would be great.

@stamblerre stamblerre transferred this issue from golang/go Oct 28, 2020
@stamblerre stamblerre changed the title x/tools/gopls: Option to wrap long lines x/tools/gopls: option to wrap long lines Oct 28, 2020
@stamblerre stamblerre changed the title x/tools/gopls: option to wrap long lines formatting: option to wrap long lines Oct 28, 2020
@stamblerre
Copy link
Contributor

Thanks for the report. gopls doesn't currently support any custom formatters apart from gofumpt yet, and it's not likely that we will add support for this in the near future. Transferring to the VS Code Go repo in case @hyangah has alternative ideas for supporting custom formatters in VS Code Go.

@hyangah
Copy link
Contributor

hyangah commented Oct 28, 2020

@stamblerre Is there an option to disable gopls's formatting support? As discussed in microsoft/vscode#72315 and microsoft/vscode#41882 at length, multiple formatters from the same extension is not recommended.

I am not sure how many other formatters out there - is there any other formatter to consider?

Re: golines - as discussed in slack, most of formatting decisions golines makes do not follow Go best practice while a couple of them are still something to consider. For example, wrapping long case lists, long comments could be handy and not be too far off of Go best practice if offered as code action or commands.

@stamblerre
Copy link
Contributor

@stamblerre Is there an option to disable gopls's formatting support? As discussed in microsoft/vscode#72315 and microsoft/vscode#41882 at length, multiple formatters from the same extension is not recommended.

Would it be possible to apply additional formatting in the language client's middleware?

@hyangah
Copy link
Contributor

hyangah commented Oct 28, 2020

@stamblerre We can intercept all the formatting requests and not forwarding the requests. Given that most of alternative formatters will run the default gofmt, I don't see a value of forwarding or post processing the requests.

I fear we need to add an additional setting to override gopls's feature. Or is there any existing setting we can reference?

What other formatters do users want to use?

@stamblerre
Copy link
Contributor

stamblerre commented Oct 30, 2020

Or is there any existing setting we can reference?

There is formatTool, but I'm not sure if it's the right choice.

What other formatters do users want to use?

I honestly wasn't aware of golines until this issue, so I'm not sure.

@StevenACoffman
Copy link

BTW, golines lets you use a base formatter (such as gofumports) (so I'm using run on save here):

"emeraldwalk.runonsave": {
        "commands": [
            {
                "match": "\\.go$",
                "cmd": "golines ${file} -w -m 120 --base-formatter=\"gofumports\""
            },
        ]
    },

Note: after 0.1.0 release, gofumpt will include gofumports by default so the above will need to change to gofumpt.

@gopherbot gopherbot added this to the Untriaged milestone Apr 8, 2021
@stamblerre stamblerre modified the milestones: Untriaged, Backlog Apr 9, 2021
@stamblerre
Copy link
Contributor

stamblerre commented Apr 9, 2021

You can now setting "go.formatTool": "golines" and it will work together with gopls. Closing.

@stamblerre stamblerre modified the milestones: Backlog, v0.24.0 Apr 9, 2021
@golang golang locked and limited conversation to collaborators Apr 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants