profile
viewpoint

Ask questionsformatting causes text to shift around and file cannot be saved

For asking questions, see:

Before filing an issue, please review our troubleshooting guides

Please answer these questions before submitting your issue. Thanks!

What version of Go, VS Code & VS Code Go extension are you using?

  • Run go version to get version of Go from the VS Code integrated terminal.

    • go version go1.16.5 windows/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.0 golang.org/x/tools/gopls@v0.7.0 h1:JQBHW81Gsyim6iDjUwGoPeSpXrSqwen3isPJLfDfaYU=
    github.com/BurntSushi/toml@v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/google/go-cmp@v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= 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-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE= golang.org/x/tools@v0.1.3-0.20210608163600-9ed039809d4c h1:Pv9gNyJFYVdpUAVZYJ1BDSU4eGgXQ+0f3DIGAdolO5s= 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.2.0 h1:NSZPykBXJFCetGZykLAxaL6SIpvbVy/UFEniIfHAa8A=

  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.

    • 1.58.2 c3f126316369cd610563c75b1b1725e0679adfb3 x64
  • Check your installed extensions to get the version of the VS Code Go extension

    • v0.26.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command. Checking configured tools.... GOBIN: undefined toolsGopath: gopath: D:\dev\goworkspace GOROOT: C:\Program Files\Go PATH: C:\Program Files\Go\bin;C:\Program Files\PowerShell\7;C:\Python39\Scripts;C:\Python39;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\Python27;C:\Python27\Scripts;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\ProgramData\chocolatey\bin;C:\Program Files\Microsoft VS Code\bin;C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\FSharp;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\dotnet;C:\Program Files\nodejs;D:\dev\goworkspace;D:\dev\goworkspace\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Program Files\PowerShell\7;C:\Program Files (x86)\dotnet;C:\Program Files (x86)\Tailscale IPN;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Users\decod\scoop\apps\nvm\current\nodejs\nodejs;C:\Ruby27-x64\bin;C:\Users\decod\AppData\Local\Microsoft\PowerAppsCLI;C:\Users\decod\scoop\shims;C:\Users\decod\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Oracle\VirtualBox;C:\Users\decod.dotnet\tools;C:\Exercism;C:\Program Files (x86)\GitHub CLI;C:\Users\decod\AppData\Local\Pandoc;C:\Users\decod.dotnet\tools;C:\Users\decod\AppData\Roaming\npm;C:\Users\decod\AppData\Local\Microsoft\WindowsApps;C:\Users\decod\go\bin;C:\Users\decod\AppData\Local\Programs\Rancher Desktop\resources\resources\win32\bin

    gopkgs: gopkgs not installed go-outline: go-outline not installed gotests: gotests not installed gomodifytags: gomodifytags not installed impl: impl not installed goplay: goplay not installed dlv: dlv not installed dlv-dap: dlv-dap not installed staticcheck: staticcheck not installed gopls: D:\dev\goworkspace\bin\gopls.exe installed

go env Workspace Folder (deleteme): d:\dev\deleteme set GO111MODULE= set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\decod\AppData\Local\go-build set GOENV=C:\Users\decod\AppData\Roaming\go\env set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GOMODCACHE=D:\dev\goworkspace\pkg\mod set GONOPROXY= set GONOSUMDB= set GOOS=windows set GOPATH=D:\dev\goworkspace set GOPRIVATE= set GOPROXY=https://proxy.golang.org,direct set GOROOT=C:\Program Files\Go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64 set GOVCS= set GOVERSION=go1.16.5 set GCCGO=gccgo set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD=NUL set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\decod\AppData\Local\Temp\go-build76415324=/tmp/go-build -gno-record-gcc-switches

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

"go.formatTool": "gofmt",
"cloudcode.gke": {
    "projectIds": [
        "atos-dev-254809"
    ]
},
"go.testOnSave": true,
"go.toolsManagement.autoUpdate": true,
"gopls.env": {
    "GOFLAGS": "-tags=integration"
},

Describe the bug

When I save a go file, text around imports starts to "jump" and file cannot be saved. During this time, go test extension spits our errors.

I expect the file to be formatted and saved

Steps to reproduce the behavior:

  1. Create a file
  2. Save a file
  3. Text is jumping around instead of being saved

EDIT: Forgot to mention that adding go.mod does not affect the behavior.

Screenshots or recordings

https://www.screencast.com/t/SqRB4A5h

golang/vscode-go

Answer questions stamblerre

https://go-review.googlesource.com/c/tools/+/319129/ should have fixed this issue, and the fix will be released in gopls/v0.7.1. If you would like to try it now, you can try downloading gopls at master: GO111MODULE=on go get golang.org/x/tools/gopls@master golang.org/x/tools@master.

useful!
source:https://uonfu.com/
Github User Rank List