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: Find All References on named parameters should show the return values #60075

Open
jsgoupil opened this issue Apr 26, 2023 · 4 comments
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@jsgoupil
Copy link

Is your feature request related to a problem? Please describe.
When using Find All References, I expect to find all references where a variable is used or assigned.
If I am using a named return parameters, then the final return is not included in the references.

x := func() (other string) {
	defer func() {
		fmt.Println("I got: " + other)
	}()

	other = "abc"
	return "def"
}

xx := x()
fmt.Println(xx)

Searching the variable other in the code above will not give me the final def usage.
image

Describe the solution you'd like
Show me the return line in the References.

@hyangah hyangah added gopls Issues related to the Go language server, gopls. FeatureRequest labels Apr 28, 2023
@findleyr
Copy link
Member

findleyr commented May 9, 2023

Hmm, this is an interesting idea. Since this is a gopls feature request, I'll transfer to the Go issue tracker.

Something @adonovan and I have discussed is the extension to 'Find References' to find all assignments of a variable (something I often want). This could be part of that analysis.

@findleyr findleyr changed the title Find All References on named parameters should show the return values x/tools/gopls: Find All References on named parameters should show the return values May 9, 2023
@findleyr findleyr transferred this issue from golang/vscode-go May 9, 2023
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label May 9, 2023
@gopherbot gopherbot added this to the Unreleased milestone May 9, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/unplan, gopls/unplanned May 9, 2023
@adonovan
Copy link
Member

adonovan commented May 9, 2023

The current Hover functionality does almost exactly that: if you position the cursor within an element of a function's return type, it highlights all the corresponding return operands within the function body. And, conversely, if you position the cursor in one of the return operands, it highlights all the others and the corresponding element of the function's return type. It works whether the return variables are named or not.

@adonovan
Copy link
Member

There are other places in the grammar that make an implicit reference without an identifier, the most obvious one being that S{x} is an implicit reference to a field of struct S. But things get fuzzy: if return 1 is an assignment to a named result variable, is f(1) not then an assignment to the parameter variable? (And what about aliasing? Given ptr := &x, is *ptr = 1 an assignment to x?)

Making FindAllReferences return implicit references could be quite confusing, and I'm not convinced it's worth doing given that the hover feature I mentioned above provides a simple solution to the immediate problem.

@adonovan
Copy link
Member

adonovan commented Jun 4, 2024

This seems like an implicit request for microsoft/language-server-protocol#1911, which is to say, the ability to request a variety of "references-like" things that are all presented using the same UI.

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

No branches or pull requests

5 participants