vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

The extension erases parts of my code when I save changes (CTRL + S)

Open JeySamir opened this issue 3 years ago • 6 comments

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.18.2 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.9.1
    golang.org/x/tools/[email protected] h1:SigsTL4Hpv3a6b/a7oPCLRv5QUeSM6PZNdta1oKY4B0=
    github.com/BurntSushi/[email protected] h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
    github.com/google/[email protected] h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp/[email protected] h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=
    golang.org/x/[email protected] h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
    golang.org/x/[email protected] h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=    
    golang.org/x/[email protected] h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=     
    golang.org/x/[email protected] h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/[email protected] h1:Ljlba2fVWOA1049JjsKii44g8nZN2GjpxMlzVc8AnQM=    golang.org/x/[email protected] h1:r5bbIROBQtRRgoutV8Q3sFY58VzHW6jMBYl48ANSyS4=    
    honnef.co/go/[email protected] h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34=
    mvdan.cc/[email protected] h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
    mvdan.cc/xurls/[email protected] h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.18.2
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
code -v
1.69.2
3b889b090b5ad5793f524b5d1d39fda662b96a2a
x64
  • Check your installed extensions to get the version of the VS Code Go extension
extension version Gov0.35.1 
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
Checking configured tools....
GOBIN: undefined
toolsGopath: 
gopath: C:\Users\user0\go
GOROOT: E:\Programs\Go
PATH: C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;E:\Programs\Python\Python27\Scripts\;E:\Programs\Python\Python27\;E:\Programs\Python\Python39\Scripts\;E:\Programs\Python\Python39\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;E:\Programs\Windows Kits\10\Windows Performance Toolkit\;E:\Programs\BinDiff\bin;E:\Programs\Git\cmd;E:\Programs\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\WireGuard\;E:\Programs\Android\SDK\platform-tools;E:\Programs\Cppcheck;C:\Program Files\dotnet\;E:\Programs\Go\bin;E:\Programs\Graphviz\bin;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;E:\Programs\Microsoft VS Code\bin;C:\Users\user0\AppData\Roaming\npm;C:\Users\user0\.dotnet\tools;C:\Users\user0\go\bin;E:\Programs\JetBrains\GoLand 2020.1\bin

    go: E:\Programs\Go\bin\go.exe: go version go1.18.2 windows/amd64

    gotests:    C:\Users\user0\go\bin\gotests.exe    (version: v1.6.0 built with go: go1.18.2)
    gomodifytags:   C:\Users\user0\go\bin\gomodifytags.exe   (version: v1.16.0 built with go: go1.18.2)
    impl:   C:\Users\user0\go\bin\impl.exe   (version: v1.1.0 built with go: go1.18.2)
    goplay: C:\Users\user0\go\bin\goplay.exe (version: v1.0.0 built with go: go1.18.2)
    dlv:    C:\Users\user0\go\bin\dlv.exe    (version: v1.9.0 built with go: go1.18.2)
    staticcheck:    C:\Users\user0\go\bin\staticcheck.exe    (version: v0.3.2 built with go: go1.18.2)
    gopls:  C:\Users\user0\go\bin\gopls.exe  (version: v0.9.1 built with go: go1.18.2)

go env
Workspace Folder (service-account): d:\projects\Golang\myapp
    set GO111MODULE=on
    set GOARCH=amd64
    set GOBIN=
    set GOCACHE=C:\Users\user0\AppData\Local\go-build
    set GOENV=C:\Users\user0\AppData\Roaming\go\env
    set GOEXE=.exe
    set GOEXPERIMENT=
    set GOFLAGS=
    set GOHOSTARCH=amd64
    set GOHOSTOS=windows
    set GOINSECURE=
    set GOMODCACHE=C:\Users\user0\go\pkg\mod
    set GONOPROXY=
    set GONOSUMDB=
    set GOOS=windows
    set GOPATH=C:\Users\user0\go
    set GOPRIVATE=
    set GOPROXY=https://proxy.golang.org,direct
    set GOROOT=E:\Programs\Go
    set GOSUMDB=sum.golang.org
    set GOTMPDIR=
    set GOTOOLDIR=E:\Programs\Go\pkg\tool\windows_amd64
    set GOVCS=
    set GOVERSION=go1.18.2
    set GCCGO=gccgo
    set GOAMD64=v1
    set AR=ar
    set CC=gcc
    set CXX=g++
    set CGO_ENABLED=1
    set GOMOD=d:\projects\Golang\myapp\go.mod
    set GOWORK=
    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\user0\AppData\Local\Temp\go-build2502215662=/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. My settings.json is empty.

Describe the bug

VS Code erase my code symbols when i press "CTRL + S"

Steps to reproduce the behavior:

  1. Create project
  2. "CTRL + P" >go install/update tools. Install all tools.
  3. Write long string.
  4. Write some symbols in start of long string.
  5. Press "CTRL + S"

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem. go install tools go ext

Note:

I disabled the linter but it didn't solve the problem. Everything works correctly without this extension.

JeySamir avatar Jul 26 '22 15:07 JeySamir

I checked some more. The problem seems to be with the [email protected] tool.

JeySamir avatar Jul 26 '22 16:07 JeySamir

Thanks for the report. If it's reproducible, can you please capture the log and share it for triaging? https://github.com/golang/vscode-go/wiki/troubleshooting#collect-extension-logs

hyangah avatar Jul 26 '22 17:07 hyangah

I also encountered this problem and it can be reproduced.
Even I disabled other extension except this one.

go version

go version go1.18.4 windows/amd64

gopls -v version

Build info


golang.org/x/tools/gopls v0.9.1 golang.org/x/tools/[email protected] h1:SigsTL4Hpv3a6b/a7oPCLRv5QUeSM6PZNdta1oKY4B0= github.com/BurntSushi/[email protected] h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU= github.com/google/[email protected] h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= golang.org/x/exp/[email protected] h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM= golang.org/x/[email protected] h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/[email protected] h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/[email protected] h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= golang.org/x/[email protected] h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/[email protected] h1:Ljlba2fVWOA1049JjsKii44g8nZN2GjpxMlzVc8AnQM= golang.org/x/[email protected] h1:r5bbIROBQtRRgoutV8Q3sFY58VzHW6jMBYl48ANSyS4= honnef.co/go/[email protected] h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34= mvdan.cc/[email protected] h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4= mvdan.cc/xurls/[email protected] h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc= go: go1.18.4

code -v

1.69.2 3b889b090b5ad5793f524b5d1d39fda662b96a2a x64

go extention

extension version Gov0.35.1

Change a .go file and then CTRL + S to save .go file or SHIFT + CTRL + F to format .go file, this problem will appear.

haxung avatar Jul 28 '22 03:07 haxung

Without repro cases or the trace, it is hard for us to do investigation. Please follow the instruction https://github.com/golang/vscode-go/wiki/troubleshooting#collect-extension-logs and share the log.

Thanks.

hyangah avatar Jul 28 '22 12:07 hyangah

I'm confused that this problem has disappeared. I've been trying to trigger it again for more than a week, but it doesn't appear.

haxung avatar Aug 09 '22 07:08 haxung

@JeySamir just following up: could you please try to capture logs reproducing the problem?

From the repro you describe, it looks approximately like a line ending edit from an old file version is being applied to a new file version. (i.e. imagine if line endings are "\r\n", and an edit removing the "\r" from the original file version -- without the A B C -- were applied to the later version). That's what it looks like, but I'm not aware of how that could be possible, and if it were happening it seems like it would likely be widespread among windows users.

LSP logs would tell us the full picture.

findleyr avatar Aug 10 '22 01:08 findleyr

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

gopherbot avatar Aug 26 '22 18:08 gopherbot