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

Add a new "Find All Modified References" feature #3294

Open
jchunkins opened this issue Mar 29, 2024 · 1 comment
Open

Add a new "Find All Modified References" feature #3294

jchunkins opened this issue Mar 29, 2024 · 1 comment
Labels
FeatureRequest gopls gopls related issues

Comments

@jchunkins
Copy link

Is your feature request related to a problem? Please describe.

I frequently use the "Find All References" feature on a given local variable or struct field to see where it is used, and find that to be a very helpful feature. What it lacks is the ability to find only those references where the local variable or struct field has been "changed" (i.e. initialized or modified). Quite often the local variable or struct field is "changed" far less than the number of places where it is used (i.e. consumed). In this situation the "Find All References" feature forces you to wade through the results to find those lines where a "change" to the variable occurred.

Describe the solution you'd like
What I would like to have is a "Find All Modified References" command that only shows the references that have been "changed". I'll use this example to explain what I want from this feature:

1   type Foo struct {
2       S string
3       M map[string]string
4       A []string
5   }
6
7   func abc() {
8       fooExample := Foo{S: "hi there", M: map[string]string{"key": "value"}, A: []string{"first"}} // Initializations
9
10      // Example of "using" the variables
11      fmt.Println(fooExample.S)
12      fmt.Println(fooExample.M)
13      fmt.Println(fooExample.A)
14      // pretend there's a bunch more lines that "use" references of Foo.S, Foo.M and Foo.A in this function...
15
16      // modifications to values
17      fooExample.S = "goodbye"
18      fooExample.A = append(fooExample.A, "second")
19      fooExample.M["key"] = "new value"
20   }
  1. I right click on S and select "Find All Modified References" and it results in lines 8 and 17
  2. I right click on M and select "Find All Modified References" and it results in lines 8 and 19
  3. I right click on A and select "Find All Modified References" and it results in lines 8 and 18

This same sort of logic could apply just as well to a locally defined variable too.

1   func xyz() {
2       S := "hi there"
3       M := map[string]string{"key": "value"}
4       A := []string{"first"}
5
6       fmt.Println(S)
7       fmt.Println(M)
8       fmt.Println(A)
9       // pretend there's a bunch more lines that "use" references of S, M and A in this function...
10
11      // modifications to values
12      S = "goodbye"
13      A = append(A, "second")
14      M["key"] = "new value"
15  }
  1. I right click on S and select "Find All Modified References" and it results in lines 2 and 12
  2. I right click on M and select "Find All Modified References" and it results in lines 3 and 14
  3. I right click on A and select "Find All Modified References" and it results in lines 4 and 13

Describe alternatives you've considered
If the feature does not exist as I have described I would have to use "Find All References" and manually find the items that modify a variable.

Additional context
None

@gopherbot gopherbot added this to the Untriaged milestone Mar 29, 2024
@hyangah hyangah added FeatureRequest gopls gopls related issues labels Apr 2, 2024
@adonovan
Copy link
Member

adonovan commented Apr 4, 2024

See also microsoft/language-server-protocol#1911

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls gopls related issues
Projects
None yet
Development

No branches or pull requests

5 participants