-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 Definition on destruction with the same name "does nothing" #59943
Comments
While I agree that it would be useful to navigate to the implied getter that matches the variable name ( For example, consider class Class {
int myField = 0;
}
void foo() {
var instance = Class();
if (instance case Class(myField : var x)) {
print(x);
print(x);
}
} I wouldn't want to be able to navigate from the declaration of Interestingly, we made the decision to navigate to between the The support in this area is a bit inconsistent, but I don't know that we want to make the inconsistency worse. |
If you test the CL, the code you suggested works as you'd expect. When you go to declaration of But if the declaration has the same name (as my example), if you ask for the definition inside the I'd say it is worse to need the full 20250121_164513.mp4 |
To me, these don't feel equivalent. In the case of Whether we should support Go-to-Def like this though, I'm less sure - on one hand, it's the only way (unless it's also in surrounding code) to get to the getter to see what you're using (and the same goes for the hover - I'd love that to show both the getter dartdocs and some indication it's a pattern/declaration). On the other hand, if you are someone that uses the Go-to-Definition shortcut (F12) to Find References when you know something is a declaration (because it's easier to press than Shift+F12), you might invoke it here expecting references to it, and this would break that. I don't know how many users use I wonder if a simple compromise would be that hovering over |
I agree. I'm just trying to convince myself that this is either (a) consistent with the semantics of the language (which I think it isn't), (b) unlikely to create confusion in the user's mind about what the semantics are, or (c) the only reasonable choice to make given the semantics of the language and the limitations of the IDE support.
The specification for patterns says:
Maybe I'm reading that wrong, but that seems to me to imply that the name of the getter being referenced is semantically distinct from the name of the variable. Nevertheless, I see where you're both coming from. Similar to the case of a default constructor, there's something in the semantics of the code that isn't explicit in the syntax of the code. I think we need to look at all such cases and see whether we can at least be consistent in the way we handle them.
I think that extending the hover text to make it more clear what the code is doing would be great, independent of the question of whether there's a way to link to the getter. |
If you have a code like the following:
Using "Go to Definition" or CTRL + Click on
myField
at line 7 (insideif
), it doesn't go to the definition in the class. Since it is also a variable definition itself, it doesn't think there is anything more to it.By default, VS Code has a fallback at a definition (if you call that command again at that location) to show references, so it would show a list containing lines 8 and 9.
I'd like a way of getting back to the class definition for
myField
. In this case, this means that "Go to Definition" would take us to the definition and not "do nothing" to fall back to VS Code default.CC @DanTup @bwilkerson @scheglov
The text was updated successfully, but these errors were encountered: