Skip to content

Unable to create a new line #3733

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
AkashR348 opened this issue Mar 25, 2025 · 3 comments
Closed

Unable to create a new line #3733

AkashR348 opened this issue Mar 25, 2025 · 3 comments
Milestone

Comments

@AkashR348
Copy link

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.
    • 1.24.1
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • v0.18.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.98.2
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.46.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

    Tools Configuration

Environment

GOBIN: undefined
toolsGopath:
gopath: C:\Users\akash\go
GOROOT: C:\Program Files\Go
PATH: C:\Program Files\Go\bin;C:\Program Files\Eclipse Adoptium\jdk-21.0.4.7-hotspot\bin;C:\Program Files (x86)\Common Files\Oracle\Java\java8path;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Python312\Scripts;C:\Python312;C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\node.js;C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Node.js\Node.js.lnk;C:\TDM-GCC-64\bin;C:\Program Files\dotnet;C:\Program Files (x86)\Nodist\bin;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\akash.cargo\bin;C:\Users\akash\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\akash\flutter\bin;C:\Users\akash\AppData\Local\Android\Sdk\emulator;C:\node.js;C:\Users\akash\AppData\Local\GitHubDesktop\bin;C:\Users\akash\AppData\Local\Microsoft\WindowsApps;C:\Users\akash\AppData\Local\Programs\Swift\Runtimes\6.0.3\usr\bin;C:\Users\akash\AppData\Local\Programs\Swift\Toolchains\6.0.3+Asserts\usr\bin;C:\Users\akash\AppData\Local\Programs\Swift\Tools\6.0.3;C:\Users\akash\go\bin
PATH (vscode launched with): C:\Program Files\Eclipse Adoptium\jdk-21.0.4.7-hotspot\bin;C:\Program Files (x86)\Common Files\Oracle\Java\java8path;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Python312\Scripts;C:\Python312;C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\node.js;C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Node.js\Node.js.lnk;C:\TDM-GCC-64\bin;C:\Program Files\dotnet;C:\Program Files (x86)\Nodist\bin;C:\ProgramData\chocolatey\bin;C:\Program Files\Git\cmd;C:\Program Files\Go\bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\akash.cargo\bin;C:\Users\akash\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\akash\flutter\bin;C:\Users\akash\AppData\Local\Android\Sdk\emulator;C:\node.js;C:\Users\akash\AppData\Local\GitHubDesktop\bin;C:\Users\akash\AppData\Local\Microsoft\WindowsApps;C:\Users\akash\AppData\Local\Programs\Swift\Runtimes\6.0.3\usr\bin;C:\Users\akash\AppData\Local\Programs\Swift\Toolchains\6.0.3+Asserts\usr\bin;C:\Users\akash\AppData\Local\Programs\Swift\Tools\6.0.3;C:\Users\akash\go\bin

Tools

go:	C:\Program Files\Go\bin\go.exe: go version go1.24.1 windows/amd64

gopls:	C:\Users\akash\go\bin\gopls.exe	(version: v0.18.1 built with go: go1.24.1)
gotests:	C:\Users\akash\go\bin\gotests.exe	(version: v1.6.0 built with go: go1.24.1)
gomodifytags:	not installed
impl:	not installed
goplay:	not installed
dlv:	not installed
staticcheck:	C:\Users\akash\go\bin\staticcheck.exe	(version: v0.6.1 built with go: go1.24.1)

Go env

Workspace Folder (Learn Go): c:\Learn Go

set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=1
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\akash\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\akash\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\akash\AppData\Local\Temp\go-build4191878669=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=NUL
set GOMODCACHE=C:\Users\akash\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\akash\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\akash\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.1
set GOWORK=
set PKG_CONFIG=pkg-config

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.toolsManagement.autoUpdate": true,

Describe the bug

Every time I press enter to create a new line, I cannot create a new line without first declaring something on the current line. if I don't declare something and press Enter to go to the new line, I will be pushed back to the line I was already on. It only happens after I declare 'package main', if I don't include that then everything works as usual. This only happens when I have the GO extension installed, once I uninstall it everything works fine, I have also already tested uninstalling my other extensions while having the GO extension installed, and the same problems keep occurring. Only when I uninstall/disable the GO extension is the problem fixed.

Steps to reproduce the behavior:

1.create Go file, with GO extension installed
2.Declare package main
3. press 'Enter" to go to a new line

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

20250325-0052-02.4816308.mp4
@gopherbot gopherbot added this to the Untriaged milestone Mar 25, 2025
@h9jiang
Copy link
Member

h9jiang commented Mar 25, 2025

Hi

Thanks for reporting this issue, this is unexpected. But there might be a good explanation for this. I'm just guessing.

Could you try using the configuration mentioned here. The go extension triggers a format on every save. Empty line is considered as mal-formatted code and will be cleaned up.

From my editor the code below will be auto formatted once I hit command + s save.

Image

to

Image

Did you configure "files.autoSave" in your vscode configuration?

@h9jiang h9jiang added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 25, 2025
@AkashR348
Copy link
Author

Thanks a lot for your response.

I set the formatOnSave to false, and that seemed to fix everything. I suspect the problem is that I have the VS code to autosave if there are no errors in my code; I don't manually save. So the formatOnSave was constantly formatting the code because my VScode autosaves whenever something in the file changes.

Thanks a lot for your quick response!

@h9jiang
Copy link
Member

h9jiang commented Mar 25, 2025

Of course. Glad it works.

The same issue also reported recently by another user #3730. I will discuss within the Go team to see if this default behavior is too invasive and too hidden. See if we can make this more obvious by any means. I will mark this as closed.

@h9jiang h9jiang closed this as completed Mar 25, 2025
@h9jiang h9jiang removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants