-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Make isDefinition aware of declaring symbol #45920
Conversation
Initial code, haven't fixed any tests yet.
This commit includes a regression for commonjs aliases: ```js // @filename: a.js function f() { } module.exports.f = f // @filename: b.js const { f } = require('./a') f/**/ ``` Now says that `f` in b.js has 1 reference -- the alias `module.exports.f = f`. This is not correct (or not exactly correct), but correctly fixing will involve re-creating the ad-hoc commonjs alias resolution code from the checker. I don't think it's worth it for an edge case like this.
@mjbvz You're probably interested in this too. @amcasey I tagged you on the review because this changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Here are the two places in the VS Code codebase where we use this property:
I think the new behavior makes sense in both instances
1. Fix `default` support. 2. Add a secondary declaration location for commonjs assignment declarations.
Looking over the baselines, I can see that the changes are pretty much universally improvements. |
I've noticed regressions in my tests that tests references returned from the typescript API. For documents:
export function doStuff(): boolean {
return true;
}
import { doStuff } from './foo';
doStuff(); getting references for
where Is that an intended change? It seems to be problematic for the feature that I have that allows findings all callers of given symbol. With that change the import statement is included as a caller which doesn't seem right. |
No comments about whether this is intended changed or not? |
ping @sandersn |
Yes, that change is intended. An import is not one of the declarations of |
OK, thanks for clarifying. |
After this PR,
isDefinition
is only true when the declaring symbol is found, and the declaration for the reference's node is one of the symbol's declarations.This improves the References Codelens, fixing the cases in #42889.
Edit: Previously, I changed isDefinition for commonjs assignment declarations. The current PR now has a simple workaround for this case. I put the old discussion at the bottom.
Remaining work
I still need to update a lot of baselines. However, the change itself is ready to review.
Fixes #42889
Old
One change is with CommonJS aliases:
Previously
module.exports.f = f
hasisDefinition: true
and didn't contribute tof
's reference count. Now it hasisDefinition: false
, and it does.This is arguable, since it's not a particularly interesting reference, even though it's technically correct. But fixing will involve re-creating the ad-hoc commonjs alias resolution code from the checker. I don't think it's worth it for an edge case like this.