Skip to content
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

Extract Function Refactoring Does Not Work When Comments are Present #2437

Closed
FloatingSunfish opened this issue Sep 4, 2022 · 2 comments
Closed
Assignees
Labels
FrozenDueToAge gopls gopls related issues upstream-tools Issues that are caused by problems in the tools that the extension depends on.
Milestone

Comments

@FloatingSunfish
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.
    • go version go1.19 windows/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.9.4
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.71.0
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.35.2
  • 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\Admin\go
GOROOT: C:\Program Files\Go
PATH: C:\Program Files\Eclipse Adoptium\jdk-17.0.2.8-hotspot\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\swigwin;C:\gallery-dl;C:\ffmpeg\bin;C:\platform-tools;C:\Program Files\Go\bin;C:\TDM-GCC-64\bin;C:\Program Files\Git\cmd;C:\Users\Admin\AppData\Local\Programs\Python\Python310\Scripts\;C:\Users\Admin\AppData\Local\Programs\Python\Python310\;C:\Users\Admin\AppData\Local\Microsoft\WindowsApps;;C:\Users\Admin\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\JetBrains\PyCharm Community Edition 2022.2.1\bin;;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.1.3\bin;;C:\Users\Admin\go\bin;C:\Users\Admin\.dotnet\tools

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

	gotests:	C:\Users\Admin\go\bin\gotests.exe	(version: v1.6.0 built with go: go1.19)
	gomodifytags:	C:\Users\Admin\go\bin\gomodifytags.exe	(version: v1.16.0 built with go: go1.19)
	impl:	C:\Users\Admin\go\bin\impl.exe	(version: v1.1.0 built with go: go1.19)
	goplay:	C:\Users\Admin\go\bin\goplay.exe	(version: v1.0.0 built with go: go1.19)
	dlv:	C:\Users\Admin\go\bin\dlv.exe	(version: v1.9.0 built with go: go1.19)
	golangci-lint:	C:\Users\Admin\go\bin\golangci-lint.exe	(version: v1.48.0 built with go: go1.19)
	gopls:	C:\Users\Admin\go\bin\gopls.exe	(version: v0.9.4 built with go: go1.19)

go env
Workspace Folder (playground): e:\_To_Backup\_02_To_Copy_Periodic\ProjectCodes\GoCodes\playground
	set GO111MODULE=
	set GOARCH=amd64
	set GOBIN=
	set GOCACHE=C:\Users\Admin\AppData\Local\go-build
	set GOENV=C:\Users\Admin\AppData\Roaming\go\env
	set GOEXE=.exe
	set GOEXPERIMENT=
	set GOFLAGS=
	set GOHOSTARCH=amd64
	set GOHOSTOS=windows
	set GOINSECURE=
	set GOMODCACHE=C:\Users\Admin\go\pkg\mod
	set GONOPROXY=
	set GONOSUMDB=
	set GOOS=windows
	set GOPATH=C:\Users\Admin\go
	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.19
	set GCCGO=gccgo
	set GOAMD64=v1
	set AR=ar
	set CC=gcc
	set CXX=g++
	set CGO_ENABLED=1
	set GOMOD=e:\_To_Backup\_02_To_Copy_Periodic\ProjectCodes\GoCodes\playground\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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\Admin\AppData\Local\Temp\go-build1366559408=/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",
"go.lintFlags": [
    "--fast"
],
"go.lintOnSave": "workspace",
"go.lintTool": "golangci-lint",
"go.vetOnSave": "workspace",

Describe the bug

Extract Function works as expected when Comments are not present in the code.
However, Extract Function does not work when Comments are present in the code. You simply get the "No refactorings available" message.

Steps to reproduce the behavior:

The below code is inside a larger function. They cannot be extracted to another function (via the Extract Function refactoring) because of the Comments.

Make sure to include the comments when you highlight all the code in each snippet:

Snippet 1:

	// A comment.
	fmt.Println("Hello, World!")

Snippet 2:

	// Another comment.
	fmt.Println("I'm doing something!")
	fmt.Println("Now I'm doing something else!")

Snippet 3:

	// Yet another comment.
	fmt.Println("Hello, World!")
	fmt.Println("Hello, World!")
	fmt.Println("Hello, World!")

	fmt.Println("Hello, World!")
	fmt.Println("Hello, World!")
	fmt.Println("Hello, World!")

Screenshots or recordings

The above code can be pasted inside any function (e.g. the main function).
You will not be able to extract them to another function because of the comments.

@gopherbot gopherbot added this to the Untriaged milestone Sep 4, 2022
@FloatingSunfish FloatingSunfish changed the title Extract Function Does Not Work When Comments are Present Extract Function Refactoring Does Not Work When Comments are Present Sep 4, 2022
@suzmue suzmue modified the milestones: Untriaged, v0.36.0 Sep 8, 2022
@suzmue suzmue added upstream-tools Issues that are caused by problems in the tools that the extension depends on. gopls gopls related issues labels Sep 8, 2022
@suzmue
Copy link
Contributor

suzmue commented Sep 8, 2022

This issue is being tracked upstream in golang/go#54816

Will leave this open for discovery purposes until it is fixed

@hyangah hyangah modified the milestones: v0.36.0, vscode-go/later Sep 14, 2022
@hyangah hyangah modified the milestones: vscode-go/later, v0.36.0 Sep 29, 2022
@hyangah
Copy link
Contributor

hyangah commented Oct 17, 2022

This is included in the gopls v0.10.0-pre.1. Closing since it will be released soon.

@hyangah hyangah closed this as completed Oct 17, 2022
@golang golang locked and limited conversation to collaborators Oct 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls gopls related issues upstream-tools Issues that are caused by problems in the tools that the extension depends on.
Projects
None yet
Development

No branches or pull requests

4 participants