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

x/tools/gopls: refactor.extract.variable inserts new statement before the scope of its free symbols #70563

Open
adonovan opened this issue Nov 25, 2024 · 4 comments · May be fixed by golang/tools#539
Labels
gopls Issues related to the Go language server, gopls. help wanted Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

Before:

	if x := 1; true {

	} else if y := x; true {  // apply refactor.extract.variable to x

	}

After:

	x1 := x // error: undefined x
	if x := 1; true {

	} else if y := x1; true {

	}
@adonovan adonovan added gopls Issues related to the Go language server, gopls. Refactoring Issues related to refactoring tools labels Nov 25, 2024
@gabyhelp
Copy link

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Nov 25, 2024
@gopherbot gopherbot added this to the Unreleased milestone Nov 25, 2024
@xzbdmw
Copy link

xzbdmw commented Nov 25, 2024

Should StmtToInsertVarBefore be factored to indicate errors (or observe this earlier with freeVars)?

@adonovan
Copy link
Member Author

Should StmtToInsertVarBefore be factored to indicate errors (or observe this earlier with freeVars)?

Probably. And it should be moved into the golang package.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/624035 mentions this issue: gopls/internal/codeaction: replace all occurrences of expression (refactor.extract.variable.all)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. help wanted Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
5 participants