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

Go to references on TS function erroneously includes the definition #114673

Closed
robeady opened this issue Jan 21, 2021 · 6 comments
Closed

Go to references on TS function erroneously includes the definition #114673

robeady opened this issue Jan 21, 2021 · 6 comments
Assignees
Labels
javascript JavaScript support issues
Milestone

Comments

@robeady
Copy link

robeady commented Jan 21, 2021

Issue Type: Bug

If a typescript function is used more than once, then the Go To References function erroneously shows the definition of the function itself as an additional reference. So a function used 2 times appears to have 3 references.

This interacts badly with the setting to "goto" rather than "peek" references because the definition seems to be the first reference, therefore you go nowhere. It is still annoying when peeking, because the first reference shown is the definition (which is where you already are), and it takes some clicking to get to the actual usages.

The problem also occurs for arrow functions assigned to variables.

The problem does not occur when using codelens, and codelens peek correctly shows only the actual references.

vscode references bug

VS Code version: Code 1.52.1 (ea3859d, 2020-12-16T16:34:46.910Z)
OS version: Windows_NT x64 10.0.19042

@mjbvz mjbvz added this to the February 2021 milestone Jan 27, 2021
@mjbvz mjbvz modified the milestones: February 2021, Backlog Feb 20, 2021
@mjbvz
Copy link
Collaborator

mjbvz commented Feb 20, 2021

Related to microsoft/TypeScript#42889

@mjbvz mjbvz added javascript JavaScript support issues upstream-issue-linked This is an upstream issue that has been reported upstream labels Feb 20, 2021
@robeady
Copy link
Author

robeady commented Mar 1, 2021

I read the linked issue. Forgive the silly question, but is it possible to perform the filtering on the vscode side, at least for common cases? Or is it not so easy to identify whether references returned by the language server are actually at the current location?

@AssisrMatheus
Copy link

+1, also having this issue. Is there a way of fixing it temporarily?

@mjbvz
Copy link
Collaborator

mjbvz commented Oct 4, 2021

Reading over this issue again, I think this is actually the expected behavior but agree it is a bit confusing if you think about it too much

When you press F12 on a symbol you usually want a list of every place that symbol is used anywhere in the codebase (this is the only way to get this information). This matches what Visual Studio does in my testing:

Screen Shot 2021-10-04 at 3 59 19 PM

The references code lens however excludes definitions because, in this context, you really only care about references to the symbol itself and not the location(s) where it is defined. It would be confusing if definitions increased the references code lens count

I think ideally we'd allow filtering down the find all references with a toggle so that it excludes definitions. That falls under #74237

Closing this in favor of that issue since I think the current behavior is working as expected

@mjbvz mjbvz closed this as completed Oct 4, 2021
@mjbvz mjbvz removed the upstream-issue-linked This is an upstream issue that has been reported upstream label Oct 4, 2021
@robeady
Copy link
Author

robeady commented Oct 6, 2021

Closing this in favor of that issue since I think the current behavior is working as expected

I opened the issue and I do not believe that it is working as expected. When I click on a function definition and ask for the references to that function, I do not expect to find the definition of the function I clicked on. That's not a reference to the function, that's the function itself!

The issue you linked does not capture this context and to be honest I don't understand it or its relevance. It being open gives me no confidence that the issue I found might be addressed.

To reiterate my earlier question, could some filtering of the results occur on the vscode side when clicking the 'go to references' menu item on a definition? Does this already happen with the code lens thing?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
javascript JavaScript support issues
Projects
None yet
Development

No branches or pull requests

3 participants