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.21.1 windows/amd64 * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. - gopls v0.13.2 * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - 1.82.1 x64 * Check your installed extensions to get the version of the VS Code Go extension - v0.39.1 * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command.
GOBIN: undefined
toolsGopath:
gopath: C:\Users\redacted\go
GOROOT: C:\Users\redacted\scoop\apps\go\current
PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\WireGuard\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\PowerShell\7\;C:\Program Files\dotnet\;C:\Users\redacted\go\bin;C:\Users\redacted\scoop\apps\python\current\Scripts;C:\Users\redacted\scoop\apps\python\current;C:\Users\redacted\scoop\apps\vscode\current\bin;C:\Users\redacted\scoop\apps\gcc\current\bin;C:\Users\redacted\scoop\apps\rustup\current\.cargo\bin;C:\Users\redacted\scoop\shims;C:\Users\redacted\AppData\Local\Microsoft\WindowsApps;C:\Users\redacted\Apps\poetry\bin;C:\Users\redacted\dev\Inno Setup 6;c:\users\redacted\.local\bin
go: C:\Users\redacted\scoop\shims\go.exe: go version go1.21.1 windows/amd64
gotests: not installed
gomodifytags: not installed
impl: not installed
goplay: not installed
dlv: C:\Users\redacted\go\bin\dlv.exe (version: v1.21.0 built with go: go1.21.1)
staticcheck: C:\Users\redacted\go\bin\staticcheck.exe (version: v0.4.6 built with go: go1.21.1)
gopls: C:\Users\redacted\go\bin\gopls.exe (version: v0.13.2 built with go: go1.21.1)
go env
Workspace Folder (playground): c:\Users\redacted\dev\go_projects\playground
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\redacted\AppData\Local\go-build
set GOENV=C:\Users\redacted\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\redacted\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\redacted\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\redacted\scoop\apps\go\current
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\redacted\scoop\apps\go\current\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.21.1
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\redacted\AppData\Local\Temp\go-build1818320928=/tmp/go-build -gno-record-gcc-switches
```
</details>
### Share the Go related settings you have added/edited
```json
"[go]": {
"editor.formatOnSave": false,
"editor.defaultFormatter": "golang.go"
},
### Describe the bug
Disabling format on save is not possible without disabling gopls altogether.
### Steps to reproduce the behavior:
1. Install Go extension
2. Create new Go file
3. Type anything with the wrong formatting e. g. `package main`
4. Save the file
**Comment From: 70sh1**
Upon further investigation, it turns out that the bulk of the formatting is indeed turned off, but it is the extra spaces between words that are still removed for some reason (as in the `package main` example).
**Comment From: findleyr**
This looks like a dupe of golang/vscode-go#2268, which is still not resolved. Interestingly, I apparently couldn't reproduce that issue, but do reproduce it now.
@hyangah this looks like a VS Code issue: the extension is setting a formatting request to gopls.
**Comment From: suzmue**
I think this is actually the result of a formatting from `Organize Imports` (https://github.com/golang/vscode-go/blob/d9015c19ed5be58bb51f3c53b651fe2468540086/docs/faq.md#how-can-i-stop-the-extension-from-formatting-files-on-save).
Can you try turning off organize imports on save to confirm this is where the bug is?
"[go]": {
"editor.formatOnSave": false,
"editor.defaultFormatter": "golang.go",
"editor.codeActionsOnSave": {"source.organizeImports": false}
},
**Comment From: 70sh1**
Confirmed. `editor.codeActionsOnSave": {"source.organizeImports": false}` indeed solves the issue.
**Comment From: suzmue**
Transferred to the gopls issue tracker for the organize imports bug.
**Comment From: abel1502**
Any progress? The proposed fixes don't work for me. The only thing that does is disabling the language server altogether
**Comment From: findleyr**
@abel1502 you mean the the fixes in https://github.com/golang/go/issues/63153#issuecomment-1730492015 does not turn off auto-formatting for you? Can you share the full contents of your `settings.json`?
**Comment From: abel1502**
@findleyr Sorry, after fruitlessly fiddling with it for a while I eventually gave up and removed all of my attempted modifications. By now I think I'm used to this behaviour... Neat brainwashing setup you've got, it turns out)
**Comment From: pjweinb**
Can this be closed?