Skip to content

formatting causes text to shift around and file cannot be saved #1646

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

Closed
Piotr1215 opened this issue Jul 23, 2021 · 6 comments
Closed

formatting causes text to shift around and file cannot be saved #1646

Piotr1215 opened this issue Jul 23, 2021 · 6 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@Piotr1215
Copy link

Piotr1215 commented Jul 23, 2021

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/[email protected] h1:JQBHW81Gsyim6iDjUwGoPeSpXrSqwen3isPJLfDfaYU=
    github.com/BurntSushi/[email protected] h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
    github.com/google/[email protected] h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
    github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/[email protected] h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
    golang.org/x/[email protected] h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/[email protected] h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
    golang.org/x/[email protected] h1:Pv9gNyJFYVdpUAVZYJ1BDSU4eGgXQ+0f3DIGAdolO5s=
    golang.org/x/[email protected] h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
    honnef.co/go/[email protected] h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE=
    mvdan.cc/[email protected] h1:bi/1aS/5W00E2ny5q65w9SnKpWEF/UIOqDYBILpo9rA=
    mvdan.cc/xurls/[email protected] 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

@gopherbot gopherbot added this to the Untriaged milestone Jul 23, 2021
@hyangah
Copy link
Contributor

hyangah commented Jul 23, 2021

Thanks for sharing the details and the recording @Piotr1215
My guess is it is a duplicate of golang/go#46791
Can you please try to switch CRLF -> LF and see if it helps?

If it is still an issue, please share the gopls trace - here is the instruction on how to collect gopls traces.
https://github.com/golang/vscode-go/blob/master/docs/troubleshooting.md#collect-gopls-information

@hyangah hyangah added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jul 23, 2021
@Piotr1215
Copy link
Author

Hi @hyangah , thank you for very fast response. Indeed switching to LF resolved the issue, I can use it as a workaround.

Could you please let me know what issue tracks the bug now? The one you linked is closed, I would like to subscribe to notifications to see when the problem will be fixed.

@stamblerre
Copy link
Contributor

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.

@Piotr1215
Copy link
Author

Great, it works! One small thing to note is that now swapping to CRLF adds an extra line below the last package, like so

CRLF:

import (
	"fmt"
	"os"

)

whereas LF removes this extra line

LF:

import (
	"fmt"
	"os"
)

maybe this might cause some unnecessary commits/merge conflicts.

@hyangah
Copy link
Contributor

hyangah commented Jul 26, 2021

Thanks for verifying the fix @Piotr1215 - I will close this issue in favor of golang/go#46791 and we will follow up with the extra-new-line issue there as well.

@hyangah hyangah closed this as completed Jul 26, 2021
@Piotr1215
Copy link
Author

Thank you @hyangah , looking forward to the fix.

@golang golang locked and limited conversation to collaborators Jul 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants