Open jpap opened 3 years ago
Can you please share your gopls
logs? Information on how to capture them can be found here.
The setting works by not sending formatting requests to the extension when formatOnSave is disabled, so if there is a bug here, it would be a VS Code bug, not a Go extension bug.
Thanks for your speedy response!
The setting works by not sending formatting requests to the extension when formatOnSave is disabled, so if there is a bug here, it would be a VS Code bug, not a Go extension bug.
The bug exists whether with gopls enabled or disabled.
Can you please share your
gopls
logs? Information on how to capture them can be found here.
The following was observed with the following VSCode setting:
"editor.formatOnSave": false,
Thanks for sharing this log. Looks like the textDocument/formatting
request is still present in the log, so I would guess that this could be an issue with your VS Code settings or with VS Code itself. Can you file an issue with the https://github.com/microsoft/vscode repository instead?
I'm happy to file an issue against vscode, though it would be good to rule out vscode-go first. Are you able to reproduce, with and without gopls enabled? (The bug is present with both here.)
Yeah, I actually did repro. I think it's because the VS Code Go extension defaults to formatOnSave being enabled: https://github.com/golang/vscode-go/blob/9b3e92e8c625df63fcd907e9195b765ea68c49d2/package.json#L184, so probably VS Code doesn't correctly override the setting. Please file an issue with VS Code.
Thanks for that line reference; with it I was able to find #65844 and #58995 which refer to the same problem for a variety of VSC-supported languages and associated settings.
The "official" method to control the format-on-save, or any of the other settings under configurationDefaults
is to override them manually in the user's json config. 😲
Given that #58995 is almost three years old and it may not get addressed any time soon, is there any way to flip this issue into a documentation change, or a hack in the vscode-go settings panel to educate the user so they don't end up following the same path of confusion as I did?
My understanding is that the language-specific configuration overrides non-language-specific configuration setting (https://code.visualstudio.com/api/references/vscode-api#WorkspaceConfiguration) so this is working as expected from VSCode's point of view even though surfacing these to users (microsoft/vscode#58995) definitely needs improvement.
This is not the first time this language-specific default override caused confusion. (https://github.com/golang/vscode-go/issues/1231 https://github.com/golang/vscode-go/issues/1805 and many in the old repo)
Some users request basically not to set language-specific defaults but stay away from configurationDefaults
. However, given that most users go with the default setting, recommending the best configuration and encouraging the best practice for 'go' development is also a role of the extension.
If we want to turn this into a documentation change, where is the best place to surface this info? The editor.formatOnSave
setting is owned by vscode so I don't think documentation surfaced through setting UI is an option. We had related doc in https://github.com/golang/vscode-go/blob/master/docs/advanced.md#formatting-code-and-organizing-imports but it doesn't seem easy to discover.
Popup to suggest the best practice setting instead of configurationDefaults
is an option too but I think for Cloud-based IDEs (e.g.codespaces), popups are not considered a great way to set up environments for the best practice.
Any idea to improve documentation is welcome.
"source.organizeImports" has some weird behavior if there are no imports (formatting the whole file). Would this be the root cause or similar? Here's a short video.
@mukunda- Thanks for the report. It sounds like that is a different issue because you have all the per-language settings override. Can you please file a separate issue with a smaller repro case and the gopls trace (instruction)? Thanks!
Change https://go.dev/cl/412054 mentions this issue: docs/faq.md: entries on formatting issues
Change https://go.dev/cl/412383 mentions this issue: docs/faq.md: entries on formatting issues
What version of Go, VS Code & VS Code Go extension are you using?
Version Information
* Run `go version` to get version of Go from _the VS Code integrated terminal_. - go version go1.17 darwin/amd64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. ``` Build info ---------- golang.org/x/tools/gopls v0.7.2 golang.org/x/tools/gopls@v0.7.2 h1:kRKKdvA8GOzra8rhSFDClOR7hV/x8v0J0Vm4C/gWq8s= github.com/BurntSushi/toml@v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= github.com/google/go-cmp@v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= golang.org/x/mod@v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sys@v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= golang.org/x/tools@v0.1.6-0.20210908190839-cf92b39a962c h1:C0nyHiBU2m0cR6hDiUORWqQIt3h37wsp1255QBSSXqY= golang.org/x/xerrors@v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= honnef.co/go/tools@v0.2.0 h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE= mvdan.cc/gofumpt@v0.1.1 h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA= mvdan.cc/xurls/v2@v2.3.0 h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I= ``` * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - 1.60.2 7f6ab5485bbc008386c4386d08766667e155244e x64 * Check your installed extensions to get the version of the VS Code Go extension - v0.28.1
Describe the bug
editor.formatOnSave
setting, vscode-go still formats Go files on save.editor.formatOnSave
setting, as the workaround above must be set up by editing the VSC settings json file; it is not selectable via the GUI settings panel.